1dc936754SJeremy L Thompson // Copyright (c) 2017-2024, Lawrence Livermore National Security, LLC and other CEED contributors. 2727da7e7SJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 3a515125bSLeila Ghaffari // 4727da7e7SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause 5a515125bSLeila Ghaffari // 6727da7e7SJeremy L Thompson // This file is part of CEED: http://github.com/ceed 7a515125bSLeila Ghaffari 8a515125bSLeila Ghaffari /// @file 9a515125bSLeila Ghaffari /// Geometric factors (2D) for Navier-Stokes example using PETSc 10493642f1SJames Wright #include <ceed.h> 11baadde1fSJames Wright #include "setupgeo_helpers.h" 12baadde1fSJames Wright #include "utils.h" 13a515125bSLeila Ghaffari 14a515125bSLeila Ghaffari // ***************************************************************************** 1504e40bb6SJeremy L Thompson // This QFunction sets up the geometric factors required for integration and coordinate transformations 16a515125bSLeila Ghaffari // 17a515125bSLeila Ghaffari // Reference (parent) coordinates: X 18a515125bSLeila Ghaffari // Physical (current) coordinates: x 19a515125bSLeila Ghaffari // Change of coordinate matrix: dxdX_{i,j} = x_{i,j} (indicial notation) 20a515125bSLeila Ghaffari // Inverse of change of coordinate matrix: dXdx_{i,j} = (detJ^-1) * X_{i,j} 21a515125bSLeila Ghaffari // 22a515125bSLeila Ghaffari // All quadrature data is stored in 10 field vector of quadrature data. 23a515125bSLeila Ghaffari // 2404e40bb6SJeremy L Thompson // We require the determinant of the Jacobian to properly compute integrals of the form: int( v u ) 25a515125bSLeila Ghaffari // 26a515125bSLeila Ghaffari // Determinant of Jacobian: 27a515125bSLeila Ghaffari // detJ = J11*J22 - J21*J12 28a515125bSLeila Ghaffari // Jij = Jacobian entry ij 29a515125bSLeila Ghaffari // 30a515125bSLeila Ghaffari // Stored: w detJ 31a515125bSLeila Ghaffari // in q_data[0] 32a515125bSLeila Ghaffari // 3304e40bb6SJeremy L Thompson // We require the transpose of the inverse of the Jacobian to properly compute integrals of the form: int( gradv u ) 34a515125bSLeila Ghaffari // 35a515125bSLeila Ghaffari // Inverse of Jacobian: 36a515125bSLeila Ghaffari // dXdx_i,j = Aij / detJ 37baadde1fSJames Wright // Aij = Adjugate ij 38a515125bSLeila Ghaffari // 39a515125bSLeila Ghaffari // Stored: Aij / detJ 40a515125bSLeila Ghaffari // in q_data[1:4] as 41a515125bSLeila Ghaffari // (detJ^-1) * [A11 A12] 42a515125bSLeila Ghaffari // [A21 A22] 43a515125bSLeila Ghaffari // ***************************************************************************** 442b916ea7SJeremy L Thompson CEED_QFUNCTION(Setup2d)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 453d65b166SJames Wright const CeedScalar(*J)[2][CEED_Q_VLA] = (const CeedScalar(*)[2][CEED_Q_VLA])in[0]; 463d65b166SJames Wright const CeedScalar(*w) = in[1]; 47baadde1fSJames Wright CeedScalar(*q_data) = out[0]; 483d65b166SJames Wright 49baadde1fSJames Wright CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 50baadde1fSJames Wright CeedScalar dXdx[2][2], detJ; 51baadde1fSJames Wright InvertMappingJacobian_2D(Q, i, J, dXdx, &detJ); 52baadde1fSJames Wright const CeedScalar wdetJ = w[i] * detJ; 53a515125bSLeila Ghaffari 54baadde1fSJames Wright StoredValuesPack(Q, i, 0, 1, &wdetJ, q_data); 55baadde1fSJames Wright StoredValuesPack(Q, i, 1, 4, (const CeedScalar *)dXdx, q_data); 56baadde1fSJames Wright } 57a515125bSLeila Ghaffari return 0; 58a515125bSLeila Ghaffari } 59a515125bSLeila Ghaffari 60a515125bSLeila Ghaffari // ***************************************************************************** 6104e40bb6SJeremy 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 62a515125bSLeila Ghaffari // 63a515125bSLeila Ghaffari // Reference (parent) 1D coordinates: X 64a515125bSLeila Ghaffari // Physical (current) 2D coordinates: x 65a515125bSLeila Ghaffari // Change of coordinate vector: 66a515125bSLeila Ghaffari // J1 = dx_1/dX 67a515125bSLeila Ghaffari // J2 = dx_2/dX 68a515125bSLeila Ghaffari // 69a515125bSLeila Ghaffari // detJb is the magnitude of (J1,J2) 70a515125bSLeila Ghaffari // 71a515125bSLeila Ghaffari // All quadrature data is stored in 3 field vector of quadrature data. 72a515125bSLeila Ghaffari // 7304e40bb6SJeremy L Thompson // We require the determinant of the Jacobian to properly compute integrals of the form: int( u v ) 74a515125bSLeila Ghaffari // 75a515125bSLeila Ghaffari // Stored: w detJb 76a515125bSLeila Ghaffari // in q_data_sur[0] 77a515125bSLeila Ghaffari // 78a515125bSLeila Ghaffari // Normal vector is given by the cross product of (J1,J2)/detJ and ẑ 79a515125bSLeila Ghaffari // 80a515125bSLeila Ghaffari // Stored: (J1,J2,0) x (0,0,1) / detJb 81a515125bSLeila Ghaffari // in q_data_sur[1:2] as 82a515125bSLeila Ghaffari // (detJb^-1) * [ J2 ] 83a515125bSLeila Ghaffari // [-J1 ] 84a515125bSLeila Ghaffari // ***************************************************************************** 852b916ea7SJeremy L Thompson CEED_QFUNCTION(SetupBoundary2d)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 863d65b166SJames Wright const CeedScalar(*J)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0]; 873d65b166SJames Wright const CeedScalar(*w) = in[1]; 882c512a7bSJames Wright CeedScalar(*q_data_sur) = out[0]; 893d65b166SJames Wright 902c512a7bSJames Wright CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 912c512a7bSJames Wright CeedScalar normal[2], detJb; 922c512a7bSJames Wright NormalVectorFromdxdX_2D(Q, i, J, normal, &detJb); 932c512a7bSJames Wright const CeedScalar wdetJ = w[i] * detJb; 94a515125bSLeila Ghaffari 952c512a7bSJames Wright StoredValuesPack(Q, i, 0, 1, &wdetJ, q_data_sur); 962c512a7bSJames Wright StoredValuesPack(Q, i, 1, 2, normal, q_data_sur); 972c512a7bSJames Wright } 98a515125bSLeila Ghaffari return 0; 99a515125bSLeila Ghaffari } 100*c864c5abSJames Wright 101*c864c5abSJames Wright // ***************************************************************************** 102*c864c5abSJames 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*c864c5abSJames Wright // 104*c864c5abSJames Wright // Reference (parent) 2D coordinates: X 105*c864c5abSJames Wright // Physical (current) 3D coordinates: x 106*c864c5abSJames Wright // Change of coordinate matrix: 107*c864c5abSJames Wright // dxdX_{i,j} = dx_i/dX_j (indicial notation) [3 * 2] 108*c864c5abSJames Wright // Inverse change of coordinate matrix: 109*c864c5abSJames Wright // dXdx_{i,j} = dX_i/dx_j (indicial notation) [2 * 3] 110*c864c5abSJames Wright // 111*c864c5abSJames Wright // (J1,J2,J3) is given by the cross product of the columns of dxdX_{i,j} 112*c864c5abSJames Wright // 113*c864c5abSJames Wright // detJb is the magnitude of (J1,J2,J3) 114*c864c5abSJames Wright // 115*c864c5abSJames Wright // dXdx is calculated via Moore–Penrose inverse: 116*c864c5abSJames Wright // 117*c864c5abSJames Wright // dX_i/dx_j = (dxdX^T dxdX)^(-1) dxdX 118*c864c5abSJames Wright // = (dx_l/dX_i * dx_l/dX_k)^(-1) dx_j/dX_k 119*c864c5abSJames Wright // 120*c864c5abSJames Wright // All quadrature data is stored in 10 field vector of quadrature data. 121*c864c5abSJames Wright // 122*c864c5abSJames Wright // We require the determinant of the Jacobian to properly compute integrals of 123*c864c5abSJames Wright // the form: int( u v ) 124*c864c5abSJames Wright // 125*c864c5abSJames Wright // Stored: w detJb 126*c864c5abSJames Wright // in q_data_sur[0] 127*c864c5abSJames Wright // 128*c864c5abSJames Wright // Normal vector = (J1,J2,J3) / detJb 129*c864c5abSJames Wright // 130*c864c5abSJames Wright // Stored: (J1,J2,J3) / detJb 131*c864c5abSJames Wright // 132*c864c5abSJames Wright // Stored: dXdx_{i,j} 133*c864c5abSJames Wright // in q_data_sur[1:6] as 134*c864c5abSJames Wright // [dXdx_11 dXdx_12 dXdx_13] 135*c864c5abSJames Wright // [dXdx_21 dXdx_22 dXdx_23] 136*c864c5abSJames Wright // ***************************************************************************** 137*c864c5abSJames Wright CEED_QFUNCTION(Setup2D_3Dcoords)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 138*c864c5abSJames Wright const CeedScalar(*J)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[0]; 139*c864c5abSJames Wright const CeedScalar(*w) = in[1]; 140*c864c5abSJames Wright CeedScalar(*q_data_sur) = out[0]; 141*c864c5abSJames Wright 142*c864c5abSJames Wright CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 143*c864c5abSJames Wright CeedScalar detJb, normal[3], dXdx[2][3]; 144*c864c5abSJames Wright 145*c864c5abSJames Wright NormalVectorFromdxdX_3D(Q, i, J, normal, &detJb); 146*c864c5abSJames Wright InvertBoundaryMappingJacobian_3D(Q, i, J, dXdx); 147*c864c5abSJames Wright const CeedScalar wdetJ = w[i] * detJb; 148*c864c5abSJames Wright 149*c864c5abSJames Wright StoredValuesPack(Q, i, 0, 1, &wdetJ, q_data_sur); 150*c864c5abSJames Wright StoredValuesPack(Q, i, 1, 6, (const CeedScalar *)dXdx, q_data_sur); 151*c864c5abSJames Wright } 152*c864c5abSJames Wright return 0; 153*c864c5abSJames Wright } 154