1ae2b091fSJames Wright // SPDX-FileCopyrightText: Copyright (c) 2017-2024, HONEE contributors. 2ae2b091fSJames Wright // SPDX-License-Identifier: Apache-2.0 OR BSD-2-Clause 3a515125bSLeila Ghaffari 4a515125bSLeila Ghaffari /// @file 5a515125bSLeila Ghaffari /// Geometric factors (3D) for Navier-Stokes example using PETSc 63a8779fbSJames Wright #include <ceed.h> 7d0cce58aSJeremy L Thompson #include <math.h> 8a515125bSLeila Ghaffari 91a74fa30SJames Wright #include "setupgeo_helpers.h" 10ade49511SJames Wright #include "utils.h" 111a74fa30SJames Wright 12a515125bSLeila Ghaffari // ***************************************************************************** 1304e40bb6SJeremy L Thompson // This QFunction sets up the geometric factors required for integration and coordinate transformations 14a515125bSLeila Ghaffari // 15a515125bSLeila Ghaffari // Reference (parent) coordinates: X 16a515125bSLeila Ghaffari // Physical (current) coordinates: x 17a515125bSLeila Ghaffari // Change of coordinate matrix: dxdX_{i,j} = x_{i,j} (indicial notation) 18a515125bSLeila Ghaffari // Inverse of change of coordinate matrix: dXdx_{i,j} = (detJ^-1) * X_{i,j} 19a515125bSLeila Ghaffari // 20a515125bSLeila Ghaffari // All quadrature data is stored in 10 field vector of quadrature data. 21a515125bSLeila Ghaffari // 2204e40bb6SJeremy L Thompson // We require the determinant of the Jacobian to properly compute integrals of the form: int( v u ) 23a515125bSLeila Ghaffari // 24a515125bSLeila Ghaffari // Determinant of Jacobian: 25a515125bSLeila Ghaffari // detJ = J11*A11 + J21*A12 + J31*A13 26a515125bSLeila Ghaffari // Jij = Jacobian entry ij 271a74fa30SJames Wright // Aij = Adjugate ij 28a515125bSLeila Ghaffari // 29a515125bSLeila Ghaffari // Stored: w detJ 30a515125bSLeila Ghaffari // in q_data[0] 31a515125bSLeila Ghaffari // 3204e40bb6SJeremy L Thompson // We require the transpose of the inverse of the Jacobian to properly compute integrals of the form: int( gradv u ) 33a515125bSLeila Ghaffari // 34a515125bSLeila Ghaffari // Inverse of Jacobian: 35a515125bSLeila Ghaffari // dXdx_i,j = Aij / detJ 36a515125bSLeila Ghaffari // 37a515125bSLeila Ghaffari // Stored: Aij / detJ 38a515125bSLeila Ghaffari // in q_data[1:9] as 39a515125bSLeila Ghaffari // (detJ^-1) * [A11 A12 A13] 40a515125bSLeila Ghaffari // [A21 A22 A23] 41a515125bSLeila Ghaffari // [A31 A32 A33] 42a515125bSLeila Ghaffari // ***************************************************************************** 432b916ea7SJeremy L Thompson CEED_QFUNCTION(Setup)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 443d65b166SJames Wright const CeedScalar(*J)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[0]; 453d65b166SJames Wright const CeedScalar(*w) = in[1]; 46ade49511SJames Wright CeedScalar(*q_data) = out[0]; 47a515125bSLeila Ghaffari 481a74fa30SJames Wright CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 491a74fa30SJames Wright CeedScalar detJ, dXdx[3][3]; 501a74fa30SJames Wright InvertMappingJacobian_3D(Q, i, J, dXdx, &detJ); 51ade49511SJames Wright const CeedScalar wdetJ = w[i] * detJ; 52ade49511SJames Wright 53ade49511SJames Wright StoredValuesPack(Q, i, 0, 1, &wdetJ, q_data); 54ade49511SJames Wright StoredValuesPack(Q, i, 1, 9, (const CeedScalar *)dXdx, q_data); 551a74fa30SJames Wright } 56a515125bSLeila Ghaffari return 0; 57a515125bSLeila Ghaffari } 58a515125bSLeila Ghaffari 59a515125bSLeila Ghaffari // ***************************************************************************** 6004e40bb6SJeremy L Thompson // This QFunction sets up the geometric factor required for integration when reference coordinates are in 2D and the physical coordinates are in 3D 61a515125bSLeila Ghaffari // 62a515125bSLeila Ghaffari // Reference (parent) 2D coordinates: X 63a515125bSLeila Ghaffari // Physical (current) 3D coordinates: x 64a515125bSLeila Ghaffari // Change of coordinate matrix: 65a515125bSLeila Ghaffari // dxdX_{i,j} = dx_i/dX_j (indicial notation) [3 * 2] 66493642f1SJames Wright // Inverse change of coordinate matrix: 67493642f1SJames Wright // dXdx_{i,j} = dX_i/dx_j (indicial notation) [2 * 3] 68a515125bSLeila Ghaffari // 69a515125bSLeila Ghaffari // (J1,J2,J3) is given by the cross product of the columns of dxdX_{i,j} 70a515125bSLeila Ghaffari // 71a515125bSLeila Ghaffari // detJb is the magnitude of (J1,J2,J3) 72a515125bSLeila Ghaffari // 73493642f1SJames Wright // dXdx is calculated via Moore–Penrose inverse: 74493642f1SJames Wright // 75493642f1SJames Wright // dX_i/dx_j = (dxdX^T dxdX)^(-1) dxdX 76493642f1SJames Wright // = (dx_l/dX_i * dx_l/dX_k)^(-1) dx_j/dX_k 77493642f1SJames Wright // 78493642f1SJames Wright // All quadrature data is stored in 10 field vector of quadrature data. 79a515125bSLeila Ghaffari // 80a515125bSLeila Ghaffari // We require the determinant of the Jacobian to properly compute integrals of 81a515125bSLeila Ghaffari // the form: int( u v ) 82a515125bSLeila Ghaffari // 83a515125bSLeila Ghaffari // Stored: w detJb 84a515125bSLeila Ghaffari // in q_data_sur[0] 85a515125bSLeila Ghaffari // 86a515125bSLeila Ghaffari // Normal vector = (J1,J2,J3) / detJb 87a515125bSLeila Ghaffari // 88493642f1SJames Wright // - TODO Could possibly remove normal vector, as it could be calculated in the Qfunction from dXdx 891a74fa30SJames Wright // See https://github.com/CEED/libCEED/pull/868#discussion_r871979484 90a515125bSLeila Ghaffari // Stored: (J1,J2,J3) / detJb 91a515125bSLeila Ghaffari // in q_data_sur[1:3] as 92a515125bSLeila Ghaffari // (detJb^-1) * [ J1 ] 93a515125bSLeila Ghaffari // [ J2 ] 94a515125bSLeila Ghaffari // [ J3 ] 95a515125bSLeila Ghaffari // 96493642f1SJames Wright // Stored: dXdx_{i,j} 97493642f1SJames Wright // in q_data_sur[4:9] as 98493642f1SJames Wright // [dXdx_11 dXdx_12 dXdx_13] 99493642f1SJames Wright // [dXdx_21 dXdx_22 dXdx_23] 100a515125bSLeila Ghaffari // ***************************************************************************** 1012b916ea7SJeremy L Thompson CEED_QFUNCTION(SetupBoundary)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 1023d65b166SJames Wright const CeedScalar(*J)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[0]; 1033d65b166SJames Wright const CeedScalar(*w) = in[1]; 104ade49511SJames Wright CeedScalar(*q_data_sur) = out[0]; 105a515125bSLeila Ghaffari 1061a74fa30SJames Wright CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 1071a74fa30SJames Wright CeedScalar detJb, normal[3], dXdx[2][3]; 108a515125bSLeila Ghaffari 1091a74fa30SJames Wright NormalVectorFromdxdX_3D(Q, i, J, normal, &detJb); 1101a74fa30SJames Wright InvertBoundaryMappingJacobian_3D(Q, i, J, dXdx); 111ade49511SJames Wright const CeedScalar wdetJ = w[i] * detJb; 112ade49511SJames Wright 113ade49511SJames Wright StoredValuesPack(Q, i, 0, 1, &wdetJ, q_data_sur); 114ade49511SJames Wright StoredValuesPack(Q, i, 1, 3, normal, q_data_sur); 115ade49511SJames Wright StoredValuesPack(Q, i, 4, 6, (const CeedScalar *)dXdx, q_data_sur); 1161a74fa30SJames Wright } 117a515125bSLeila Ghaffari return 0; 118a515125bSLeila Ghaffari } 1198c85b835SJames Wright 1208c85b835SJames Wright /** 1218c85b835SJames Wright @brief Compute geometric factors for integration, gradient transformations, and coordinate transformations on element faces. 1228c85b835SJames Wright 1238c85b835SJames Wright Reference (parent) 2D coordinates are given by `X` and physical (current) 3D coordinates are given by `x`. 1248c85b835SJames Wright The change of coordinate matrix is given by`dxdX_{i,j} = dx_i/dX_j (indicial notation) [3 * 2]`. 1258c85b835SJames Wright 1268c85b835SJames Wright `(N_1, N_2, N_3)` is given by the cross product of the columns of `dxdX_{i,j}`. 1278c85b835SJames Wright 1288c85b835SJames Wright `detNb` is the magnitude of `(N_1, N_2, N_3)`. 1298c85b835SJames Wright 1308c85b835SJames Wright @param[in] ctx QFunction context, unused 1318c85b835SJames Wright @param[in] Q Number of quadrature points 1328c85b835SJames Wright @param[in] in Input arrays 1338c85b835SJames Wright - 0 - Jacobian of cell coordinates 1348c85b835SJames Wright - 1 - Jacobian of face coordinates 1358c85b835SJames Wright - 2 - quadrature weights 1368c85b835SJames Wright @param[out] out Output array 1378c85b835SJames Wright - 0 - qdata, `w detNb`, `dXdx`, and `N` 1388c85b835SJames Wright 1398c85b835SJames Wright @return An error code: 0 - success, otherwise - failure 1408c85b835SJames Wright **/ 1418c85b835SJames Wright CEED_QFUNCTION(SetupBoundaryGradient)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 1428c85b835SJames Wright const CeedScalar(*J_cell)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[0]; 1438c85b835SJames Wright const CeedScalar(*J_face)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[1]; 1448c85b835SJames Wright const CeedScalar(*w) = in[2]; 1458c85b835SJames Wright CeedScalar(*q_data_sur) = out[0]; 1468c85b835SJames Wright 1478c85b835SJames Wright CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 148*fda2a15dSJames Wright CeedScalar detJ_face, normal[3], dXdx[3][3]; 1498c85b835SJames Wright 150*fda2a15dSJames Wright NormalVectorFromdxdX_3D(Q, i, J_face, normal, &detJ_face); 1518c85b835SJames Wright const CeedScalar wdetJ = w[i] * detJ_face; 1528c85b835SJames Wright InvertMappingJacobian_3D(Q, i, J_cell, dXdx, NULL); 1538c85b835SJames Wright 1548c85b835SJames Wright StoredValuesPack(Q, i, 0, 1, &wdetJ, q_data_sur); 1558c85b835SJames Wright StoredValuesPack(Q, i, 1, 9, (CeedScalar *)dXdx, q_data_sur); 1568c85b835SJames Wright StoredValuesPack(Q, i, 10, 3, normal, q_data_sur); 1578c85b835SJames Wright } 1588c85b835SJames Wright return CEED_ERROR_SUCCESS; 1598c85b835SJames Wright } 160