15aed82e4SJeremy L Thompson // Copyright (c) 2017-2024, Lawrence Livermore National Security, LLC and other CEED contributors. 23d8e8822SJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 377841947SLeila Ghaffari // 43d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause 577841947SLeila Ghaffari // 63d8e8822SJeremy L Thompson // This file is part of CEED: http://github.com/ceed 777841947SLeila Ghaffari 877841947SLeila Ghaffari /// @file 977841947SLeila Ghaffari /// Geometric factors (2D) for Navier-Stokes example using PETSc 10ba6664aeSJames Wright #include <ceed.h> 11bf415d3fSJames Wright #include "setupgeo_helpers.h" 12bf415d3fSJames Wright #include "utils.h" 1377841947SLeila Ghaffari 1477841947SLeila Ghaffari // ***************************************************************************** 15ea61e9acSJeremy L Thompson // This QFunction sets up the geometric factors required for integration and coordinate transformations 1677841947SLeila Ghaffari // 1777841947SLeila Ghaffari // Reference (parent) coordinates: X 1877841947SLeila Ghaffari // Physical (current) coordinates: x 1977841947SLeila Ghaffari // Change of coordinate matrix: dxdX_{i,j} = x_{i,j} (indicial notation) 2077841947SLeila Ghaffari // Inverse of change of coordinate matrix: dXdx_{i,j} = (detJ^-1) * X_{i,j} 2177841947SLeila Ghaffari // 2277841947SLeila Ghaffari // All quadrature data is stored in 10 field vector of quadrature data. 2377841947SLeila Ghaffari // 24ea61e9acSJeremy L Thompson // We require the determinant of the Jacobian to properly compute integrals of the form: int( v u ) 2577841947SLeila Ghaffari // 2677841947SLeila Ghaffari // Determinant of Jacobian: 2777841947SLeila Ghaffari // detJ = J11*J22 - J21*J12 2877841947SLeila Ghaffari // Jij = Jacobian entry ij 2977841947SLeila Ghaffari // 3077841947SLeila Ghaffari // Stored: w detJ 3177841947SLeila Ghaffari // in q_data[0] 3277841947SLeila Ghaffari // 33ea61e9acSJeremy L Thompson // We require the transpose of the inverse of the Jacobian to properly compute integrals of the form: int( gradv u ) 3477841947SLeila Ghaffari // 3577841947SLeila Ghaffari // Inverse of Jacobian: 3677841947SLeila Ghaffari // dXdx_i,j = Aij / detJ 37bf415d3fSJames Wright // Aij = Adjugate ij 3877841947SLeila Ghaffari // 3977841947SLeila Ghaffari // Stored: Aij / detJ 4077841947SLeila Ghaffari // in q_data[1:4] as 4177841947SLeila Ghaffari // (detJ^-1) * [A11 A12] 4277841947SLeila Ghaffari // [A21 A22] 4377841947SLeila Ghaffari // ***************************************************************************** 442b730f8bSJeremy L Thompson CEED_QFUNCTION(Setup2d)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 4546603fc5SJames Wright const CeedScalar(*J)[2][CEED_Q_VLA] = (const CeedScalar(*)[2][CEED_Q_VLA])in[0]; 4646603fc5SJames Wright const CeedScalar(*w) = in[1]; 47bf415d3fSJames Wright CeedScalar(*q_data) = out[0]; 4846603fc5SJames Wright 49bf415d3fSJames Wright CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 50bf415d3fSJames Wright CeedScalar dXdx[2][2], detJ; 51bf415d3fSJames Wright InvertMappingJacobian_2D(Q, i, J, dXdx, &detJ); 52bf415d3fSJames Wright const CeedScalar wdetJ = w[i] * detJ; 5377841947SLeila Ghaffari 54bf415d3fSJames Wright StoredValuesPack(Q, i, 0, 1, &wdetJ, q_data); 55bf415d3fSJames Wright StoredValuesPack(Q, i, 1, 4, (const CeedScalar *)dXdx, q_data); 56bf415d3fSJames Wright } 5777841947SLeila Ghaffari return 0; 5877841947SLeila Ghaffari } 5977841947SLeila Ghaffari 6077841947SLeila Ghaffari // ***************************************************************************** 61ea61e9acSJeremy L Thompson // This QFunction sets up the geometric factor required for integration when reference coordinates are in 1D and the physical coordinates are in 2D 6277841947SLeila Ghaffari // 6377841947SLeila Ghaffari // Reference (parent) 1D coordinates: X 6477841947SLeila Ghaffari // Physical (current) 2D coordinates: x 6577841947SLeila Ghaffari // Change of coordinate vector: 6677841947SLeila Ghaffari // J1 = dx_1/dX 6777841947SLeila Ghaffari // J2 = dx_2/dX 6877841947SLeila Ghaffari // 6977841947SLeila Ghaffari // detJb is the magnitude of (J1,J2) 7077841947SLeila Ghaffari // 7177841947SLeila Ghaffari // All quadrature data is stored in 3 field vector of quadrature data. 7277841947SLeila Ghaffari // 73ea61e9acSJeremy L Thompson // We require the determinant of the Jacobian to properly compute integrals of the form: int( u v ) 7477841947SLeila Ghaffari // 7577841947SLeila Ghaffari // Stored: w detJb 7677841947SLeila Ghaffari // in q_data_sur[0] 7777841947SLeila Ghaffari // 7877841947SLeila Ghaffari // Normal vector is given by the cross product of (J1,J2)/detJ and ẑ 7977841947SLeila Ghaffari // 8077841947SLeila Ghaffari // Stored: (J1,J2,0) x (0,0,1) / detJb 8177841947SLeila Ghaffari // in q_data_sur[1:2] as 8277841947SLeila Ghaffari // (detJb^-1) * [ J2 ] 8377841947SLeila Ghaffari // [-J1 ] 8477841947SLeila Ghaffari // ***************************************************************************** 852b730f8bSJeremy L Thompson CEED_QFUNCTION(SetupBoundary2d)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 8646603fc5SJames Wright const CeedScalar(*J)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0]; 8746603fc5SJames Wright const CeedScalar(*w) = in[1]; 881394d07eSJames Wright CeedScalar(*q_data_sur) = out[0]; 8946603fc5SJames Wright 901394d07eSJames Wright CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 911394d07eSJames Wright CeedScalar normal[2], detJb; 921394d07eSJames Wright NormalVectorFromdxdX_2D(Q, i, J, normal, &detJb); 931394d07eSJames Wright const CeedScalar wdetJ = w[i] * detJb; 9477841947SLeila Ghaffari 951394d07eSJames Wright StoredValuesPack(Q, i, 0, 1, &wdetJ, q_data_sur); 961394d07eSJames Wright StoredValuesPack(Q, i, 1, 2, normal, q_data_sur); 971394d07eSJames Wright } 9877841947SLeila Ghaffari return 0; 9977841947SLeila Ghaffari } 100*cfb075a4SJames Wright 101*cfb075a4SJames Wright // ***************************************************************************** 102*cfb075a4SJames Wright // This QFunction sets up the geometric factor required for integration when reference coordinates are in 2D and the physical coordinates are in 3D 103*cfb075a4SJames Wright // 104*cfb075a4SJames Wright // Reference (parent) 2D coordinates: X 105*cfb075a4SJames Wright // Physical (current) 3D coordinates: x 106*cfb075a4SJames Wright // Change of coordinate matrix: 107*cfb075a4SJames Wright // dxdX_{i,j} = dx_i/dX_j (indicial notation) [3 * 2] 108*cfb075a4SJames Wright // Inverse change of coordinate matrix: 109*cfb075a4SJames Wright // dXdx_{i,j} = dX_i/dx_j (indicial notation) [2 * 3] 110*cfb075a4SJames Wright // 111*cfb075a4SJames Wright // (J1,J2,J3) is given by the cross product of the columns of dxdX_{i,j} 112*cfb075a4SJames Wright // 113*cfb075a4SJames Wright // detJb is the magnitude of (J1,J2,J3) 114*cfb075a4SJames Wright // 115*cfb075a4SJames Wright // dXdx is calculated via Moore–Penrose inverse: 116*cfb075a4SJames Wright // 117*cfb075a4SJames Wright // dX_i/dx_j = (dxdX^T dxdX)^(-1) dxdX 118*cfb075a4SJames Wright // = (dx_l/dX_i * dx_l/dX_k)^(-1) dx_j/dX_k 119*cfb075a4SJames Wright // 120*cfb075a4SJames Wright // All quadrature data is stored in 10 field vector of quadrature data. 121*cfb075a4SJames Wright // 122*cfb075a4SJames Wright // We require the determinant of the Jacobian to properly compute integrals of 123*cfb075a4SJames Wright // the form: int( u v ) 124*cfb075a4SJames Wright // 125*cfb075a4SJames Wright // Stored: w detJb 126*cfb075a4SJames Wright // in q_data_sur[0] 127*cfb075a4SJames Wright // 128*cfb075a4SJames Wright // Normal vector = (J1,J2,J3) / detJb 129*cfb075a4SJames Wright // 130*cfb075a4SJames Wright // Stored: (J1,J2,J3) / detJb 131*cfb075a4SJames Wright // 132*cfb075a4SJames Wright // Stored: dXdx_{i,j} 133*cfb075a4SJames Wright // in q_data_sur[1:6] as 134*cfb075a4SJames Wright // [dXdx_11 dXdx_12 dXdx_13] 135*cfb075a4SJames Wright // [dXdx_21 dXdx_22 dXdx_23] 136*cfb075a4SJames Wright // ***************************************************************************** 137*cfb075a4SJames Wright CEED_QFUNCTION(Setup2D_3Dcoords)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 138*cfb075a4SJames Wright const CeedScalar(*J)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[0]; 139*cfb075a4SJames Wright const CeedScalar(*w) = in[1]; 140*cfb075a4SJames Wright CeedScalar(*q_data_sur) = out[0]; 141*cfb075a4SJames Wright 142*cfb075a4SJames Wright CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 143*cfb075a4SJames Wright CeedScalar detJb, normal[3], dXdx[2][3]; 144*cfb075a4SJames Wright 145*cfb075a4SJames Wright NormalVectorFromdxdX_3D(Q, i, J, normal, &detJb); 146*cfb075a4SJames Wright InvertBoundaryMappingJacobian_3D(Q, i, J, dXdx); 147*cfb075a4SJames Wright const CeedScalar wdetJ = w[i] * detJb; 148*cfb075a4SJames Wright 149*cfb075a4SJames Wright StoredValuesPack(Q, i, 0, 1, &wdetJ, q_data_sur); 150*cfb075a4SJames Wright StoredValuesPack(Q, i, 1, 6, (const CeedScalar *)dXdx, q_data_sur); 151*cfb075a4SJames Wright } 152*cfb075a4SJames Wright return 0; 153*cfb075a4SJames Wright } 154