1 // Copyright (c) 2017-2024, Lawrence Livermore National Security, LLC and other CEED contributors. 2 // All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 3 // 4 // SPDX-License-Identifier: BSD-2-Clause 5 // 6 // This file is part of CEED: http://github.com/ceed 7 8 /// @file 9 /// Geometric factors (3D) for Navier-Stokes example using PETSc 10 #include <ceed.h> 11 #include <math.h> 12 13 #include "setupgeo_helpers.h" 14 #include "utils.h" 15 16 // ***************************************************************************** 17 // This QFunction sets up the geometric factors required for integration and coordinate transformations 18 // 19 // Reference (parent) coordinates: X 20 // Physical (current) coordinates: x 21 // Change of coordinate matrix: dxdX_{i,j} = x_{i,j} (indicial notation) 22 // Inverse of change of coordinate matrix: dXdx_{i,j} = (detJ^-1) * X_{i,j} 23 // 24 // All quadrature data is stored in 10 field vector of quadrature data. 25 // 26 // We require the determinant of the Jacobian to properly compute integrals of the form: int( v u ) 27 // 28 // Determinant of Jacobian: 29 // detJ = J11*A11 + J21*A12 + J31*A13 30 // Jij = Jacobian entry ij 31 // Aij = Adjugate ij 32 // 33 // Stored: w detJ 34 // in q_data[0] 35 // 36 // We require the transpose of the inverse of the Jacobian to properly compute integrals of the form: int( gradv u ) 37 // 38 // Inverse of Jacobian: 39 // dXdx_i,j = Aij / detJ 40 // 41 // Stored: Aij / detJ 42 // in q_data[1:9] as 43 // (detJ^-1) * [A11 A12 A13] 44 // [A21 A22 A23] 45 // [A31 A32 A33] 46 // ***************************************************************************** 47 CEED_QFUNCTION(Setup)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 48 const CeedScalar(*J)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[0]; 49 const CeedScalar(*w) = in[1]; 50 CeedScalar(*q_data) = out[0]; 51 52 CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 53 CeedScalar detJ, dXdx[3][3]; 54 InvertMappingJacobian_3D(Q, i, J, dXdx, &detJ); 55 const CeedScalar wdetJ = w[i] * detJ; 56 57 StoredValuesPack(Q, i, 0, 1, &wdetJ, q_data); 58 StoredValuesPack(Q, i, 1, 9, (const CeedScalar *)dXdx, q_data); 59 } 60 return 0; 61 } 62 63 // ***************************************************************************** 64 // This QFunction sets up the geometric factor required for integration when reference coordinates are in 2D and the physical coordinates are in 3D 65 // 66 // Reference (parent) 2D coordinates: X 67 // Physical (current) 3D coordinates: x 68 // Change of coordinate matrix: 69 // dxdX_{i,j} = dx_i/dX_j (indicial notation) [3 * 2] 70 // Inverse change of coordinate matrix: 71 // dXdx_{i,j} = dX_i/dx_j (indicial notation) [2 * 3] 72 // 73 // (J1,J2,J3) is given by the cross product of the columns of dxdX_{i,j} 74 // 75 // detJb is the magnitude of (J1,J2,J3) 76 // 77 // dXdx is calculated via Moore–Penrose inverse: 78 // 79 // dX_i/dx_j = (dxdX^T dxdX)^(-1) dxdX 80 // = (dx_l/dX_i * dx_l/dX_k)^(-1) dx_j/dX_k 81 // 82 // All quadrature data is stored in 10 field vector of quadrature data. 83 // 84 // We require the determinant of the Jacobian to properly compute integrals of 85 // the form: int( u v ) 86 // 87 // Stored: w detJb 88 // in q_data_sur[0] 89 // 90 // Normal vector = (J1,J2,J3) / detJb 91 // 92 // - TODO Could possibly remove normal vector, as it could be calculated in the Qfunction from dXdx 93 // See https://github.com/CEED/libCEED/pull/868#discussion_r871979484 94 // Stored: (J1,J2,J3) / detJb 95 // in q_data_sur[1:3] as 96 // (detJb^-1) * [ J1 ] 97 // [ J2 ] 98 // [ J3 ] 99 // 100 // Stored: dXdx_{i,j} 101 // in q_data_sur[4:9] as 102 // [dXdx_11 dXdx_12 dXdx_13] 103 // [dXdx_21 dXdx_22 dXdx_23] 104 // ***************************************************************************** 105 CEED_QFUNCTION(SetupBoundary)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 106 const CeedScalar(*J)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[0]; 107 const CeedScalar(*w) = in[1]; 108 CeedScalar(*q_data_sur) = out[0]; 109 110 CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 111 CeedScalar detJb, normal[3], dXdx[2][3]; 112 113 NormalVectorFromdxdX_3D(Q, i, J, normal, &detJb); 114 InvertBoundaryMappingJacobian_3D(Q, i, J, dXdx); 115 const CeedScalar wdetJ = w[i] * detJb; 116 117 StoredValuesPack(Q, i, 0, 1, &wdetJ, q_data_sur); 118 StoredValuesPack(Q, i, 1, 3, normal, q_data_sur); 119 StoredValuesPack(Q, i, 4, 6, (const CeedScalar *)dXdx, q_data_sur); 120 } 121 return 0; 122 } 123