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
5*ea615d4cSJames Wright /// Geometric factors (3D) for HONEE
63e17a7a1SJames Wright #include <ceed/types.h>
7a515125bSLeila Ghaffari
81a74fa30SJames Wright #include "setupgeo_helpers.h"
9ade49511SJames Wright #include "utils.h"
101a74fa30SJames Wright
11a515125bSLeila Ghaffari // *****************************************************************************
1204e40bb6SJeremy L Thompson // This QFunction sets up the geometric factors required for integration and coordinate transformations
13a515125bSLeila Ghaffari //
14a515125bSLeila Ghaffari // Reference (parent) coordinates: X
15a515125bSLeila Ghaffari // Physical (current) coordinates: x
16a515125bSLeila Ghaffari // Change of coordinate matrix: dxdX_{i,j} = x_{i,j} (indicial notation)
17a515125bSLeila Ghaffari // Inverse of change of coordinate matrix: dXdx_{i,j} = (detJ^-1) * X_{i,j}
18a515125bSLeila Ghaffari //
19a515125bSLeila Ghaffari // All quadrature data is stored in 10 field vector of quadrature data.
20a515125bSLeila Ghaffari //
2104e40bb6SJeremy L Thompson // We require the determinant of the Jacobian to properly compute integrals of the form: int( v u )
22a515125bSLeila Ghaffari //
23a515125bSLeila Ghaffari // Determinant of Jacobian:
24a515125bSLeila Ghaffari // detJ = J11*A11 + J21*A12 + J31*A13
25a515125bSLeila Ghaffari // Jij = Jacobian entry ij
261a74fa30SJames Wright // Aij = Adjugate ij
27a515125bSLeila Ghaffari //
28a515125bSLeila Ghaffari // Stored: w detJ
29a515125bSLeila Ghaffari // in q_data[0]
30a515125bSLeila Ghaffari //
3104e40bb6SJeremy L Thompson // We require the transpose of the inverse of the Jacobian to properly compute integrals of the form: int( gradv u )
32a515125bSLeila Ghaffari //
33a515125bSLeila Ghaffari // Inverse of Jacobian:
34a515125bSLeila Ghaffari // dXdx_i,j = Aij / detJ
35a515125bSLeila Ghaffari //
36a515125bSLeila Ghaffari // Stored: Aij / detJ
37a515125bSLeila Ghaffari // in q_data[1:9] as
38a515125bSLeila Ghaffari // (detJ^-1) * [A11 A12 A13]
39a515125bSLeila Ghaffari // [A21 A22 A23]
40a515125bSLeila Ghaffari // [A31 A32 A33]
41a515125bSLeila Ghaffari // *****************************************************************************
Setup(void * ctx,CeedInt Q,const CeedScalar * const * in,CeedScalar * const * out)422b916ea7SJeremy L Thompson CEED_QFUNCTION(Setup)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
433d65b166SJames Wright const CeedScalar(*J)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[0];
443d65b166SJames Wright const CeedScalar(*w) = in[1];
45ade49511SJames Wright CeedScalar(*q_data) = out[0];
46a515125bSLeila Ghaffari
471a74fa30SJames Wright CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
481a74fa30SJames Wright CeedScalar detJ, dXdx[3][3];
491a74fa30SJames Wright InvertMappingJacobian_3D(Q, i, J, dXdx, &detJ);
50ade49511SJames Wright const CeedScalar wdetJ = w[i] * detJ;
51ade49511SJames Wright
52ade49511SJames Wright StoredValuesPack(Q, i, 0, 1, &wdetJ, q_data);
53ade49511SJames Wright StoredValuesPack(Q, i, 1, 9, (const CeedScalar *)dXdx, q_data);
541a74fa30SJames Wright }
55a515125bSLeila Ghaffari return 0;
56a515125bSLeila Ghaffari }
57a515125bSLeila Ghaffari
58a515125bSLeila Ghaffari // *****************************************************************************
5904e40bb6SJeremy 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
60a515125bSLeila Ghaffari //
61a515125bSLeila Ghaffari // Reference (parent) 2D coordinates: X
62a515125bSLeila Ghaffari // Physical (current) 3D coordinates: x
63a515125bSLeila Ghaffari // Change of coordinate matrix:
64a515125bSLeila Ghaffari // dxdX_{i,j} = dx_i/dX_j (indicial notation) [3 * 2]
65493642f1SJames Wright // Inverse change of coordinate matrix:
66493642f1SJames Wright // dXdx_{i,j} = dX_i/dx_j (indicial notation) [2 * 3]
67a515125bSLeila Ghaffari //
68a515125bSLeila Ghaffari // (J1,J2,J3) is given by the cross product of the columns of dxdX_{i,j}
69a515125bSLeila Ghaffari //
70a515125bSLeila Ghaffari // detJb is the magnitude of (J1,J2,J3)
71a515125bSLeila Ghaffari //
72493642f1SJames Wright // dXdx is calculated via Moore–Penrose inverse:
73493642f1SJames Wright //
74493642f1SJames Wright // dX_i/dx_j = (dxdX^T dxdX)^(-1) dxdX
75493642f1SJames Wright // = (dx_l/dX_i * dx_l/dX_k)^(-1) dx_j/dX_k
76493642f1SJames Wright //
77493642f1SJames Wright // All quadrature data is stored in 10 field vector of quadrature data.
78a515125bSLeila Ghaffari //
79a515125bSLeila Ghaffari // We require the determinant of the Jacobian to properly compute integrals of
80a515125bSLeila Ghaffari // the form: int( u v )
81a515125bSLeila Ghaffari //
82a515125bSLeila Ghaffari // Stored: w detJb
83a515125bSLeila Ghaffari // in q_data_sur[0]
84a515125bSLeila Ghaffari //
85a515125bSLeila Ghaffari // Normal vector = (J1,J2,J3) / detJb
86a515125bSLeila Ghaffari //
87493642f1SJames Wright // - TODO Could possibly remove normal vector, as it could be calculated in the Qfunction from dXdx
881a74fa30SJames Wright // See https://github.com/CEED/libCEED/pull/868#discussion_r871979484
89a515125bSLeila Ghaffari // Stored: (J1,J2,J3) / detJb
90a515125bSLeila Ghaffari // in q_data_sur[1:3] as
91a515125bSLeila Ghaffari // (detJb^-1) * [ J1 ]
92a515125bSLeila Ghaffari // [ J2 ]
93a515125bSLeila Ghaffari // [ J3 ]
94a515125bSLeila Ghaffari //
95493642f1SJames Wright // Stored: dXdx_{i,j}
96493642f1SJames Wright // in q_data_sur[4:9] as
97493642f1SJames Wright // [dXdx_11 dXdx_12 dXdx_13]
98493642f1SJames Wright // [dXdx_21 dXdx_22 dXdx_23]
99a515125bSLeila Ghaffari // *****************************************************************************
SetupBoundary(void * ctx,CeedInt Q,const CeedScalar * const * in,CeedScalar * const * out)1002b916ea7SJeremy L Thompson CEED_QFUNCTION(SetupBoundary)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
1013d65b166SJames Wright const CeedScalar(*J)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[0];
1023d65b166SJames Wright const CeedScalar(*w) = in[1];
103ade49511SJames Wright CeedScalar(*q_data_sur) = out[0];
104a515125bSLeila Ghaffari
1051a74fa30SJames Wright CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
1061a74fa30SJames Wright CeedScalar detJb, normal[3], dXdx[2][3];
107a515125bSLeila Ghaffari
1081a74fa30SJames Wright NormalVectorFromdxdX_3D(Q, i, J, normal, &detJb);
1091a74fa30SJames Wright InvertBoundaryMappingJacobian_3D(Q, i, J, dXdx);
110ade49511SJames Wright const CeedScalar wdetJ = w[i] * detJb;
111ade49511SJames Wright
112ade49511SJames Wright StoredValuesPack(Q, i, 0, 1, &wdetJ, q_data_sur);
113ade49511SJames Wright StoredValuesPack(Q, i, 1, 3, normal, q_data_sur);
114ade49511SJames Wright StoredValuesPack(Q, i, 4, 6, (const CeedScalar *)dXdx, q_data_sur);
1151a74fa30SJames Wright }
116a515125bSLeila Ghaffari return 0;
117a515125bSLeila Ghaffari }
1188c85b835SJames Wright
1198c85b835SJames Wright /**
1208c85b835SJames Wright @brief Compute geometric factors for integration, gradient transformations, and coordinate transformations on element faces.
1218c85b835SJames Wright
1228c85b835SJames Wright Reference (parent) 2D coordinates are given by `X` and physical (current) 3D coordinates are given by `x`.
1238c85b835SJames Wright The change of coordinate matrix is given by`dxdX_{i,j} = dx_i/dX_j (indicial notation) [3 * 2]`.
1248c85b835SJames Wright
1258c85b835SJames Wright `(N_1, N_2, N_3)` is given by the cross product of the columns of `dxdX_{i,j}`.
1268c85b835SJames Wright
1278c85b835SJames Wright `detNb` is the magnitude of `(N_1, N_2, N_3)`.
1288c85b835SJames Wright
1298c85b835SJames Wright @param[in] ctx QFunction context, unused
1308c85b835SJames Wright @param[in] Q Number of quadrature points
1318c85b835SJames Wright @param[in] in Input arrays
1328c85b835SJames Wright - 0 - Jacobian of cell coordinates
1338c85b835SJames Wright - 1 - Jacobian of face coordinates
1348c85b835SJames Wright - 2 - quadrature weights
1358c85b835SJames Wright @param[out] out Output array
1368c85b835SJames Wright - 0 - qdata, `w detNb`, `dXdx`, and `N`
1378c85b835SJames Wright
1388c85b835SJames Wright @return An error code: 0 - success, otherwise - failure
1398c85b835SJames Wright **/
SetupBoundaryGradient(void * ctx,CeedInt Q,const CeedScalar * const * in,CeedScalar * const * out)1408c85b835SJames Wright CEED_QFUNCTION(SetupBoundaryGradient)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
1418c85b835SJames Wright const CeedScalar(*J_cell)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[0];
1428c85b835SJames Wright const CeedScalar(*J_face)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[1];
1438c85b835SJames Wright const CeedScalar(*w) = in[2];
1448c85b835SJames Wright CeedScalar(*q_data_sur) = out[0];
1458c85b835SJames Wright
1468c85b835SJames Wright CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
147fda2a15dSJames Wright CeedScalar detJ_face, normal[3], dXdx[3][3];
1488c85b835SJames Wright
149fda2a15dSJames Wright NormalVectorFromdxdX_3D(Q, i, J_face, normal, &detJ_face);
1508c85b835SJames Wright const CeedScalar wdetJ = w[i] * detJ_face;
1518c85b835SJames Wright InvertMappingJacobian_3D(Q, i, J_cell, dXdx, NULL);
1528c85b835SJames Wright
1538c85b835SJames Wright StoredValuesPack(Q, i, 0, 1, &wdetJ, q_data_sur);
1548c85b835SJames Wright StoredValuesPack(Q, i, 1, 9, (CeedScalar *)dXdx, q_data_sur);
1558c85b835SJames Wright StoredValuesPack(Q, i, 10, 3, normal, q_data_sur);
1568c85b835SJames Wright }
1578c85b835SJames Wright return CEED_ERROR_SUCCESS;
1588c85b835SJames Wright }
159