xref: /honee/qfunctions/setupgeo2d.h (revision 8a8cb6e06ce4728cc6d80ca92f8de31da49852e5)
1 // SPDX-FileCopyrightText: Copyright (c) 2017-2024, HONEE contributors.
2 // SPDX-License-Identifier: Apache-2.0 OR BSD-2-Clause
3 
4 /// @file
5 /// Geometric factors (2D) for Navier-Stokes example using PETSc
6 #include <ceed.h>
7 #include "setupgeo_helpers.h"
8 #include "utils.h"
9 
10 // *****************************************************************************
11 // This QFunction sets up the geometric factors required for integration and coordinate transformations
12 //
13 // Reference (parent) coordinates: X
14 // Physical (current) coordinates: x
15 // Change of coordinate matrix: dxdX_{i,j} = x_{i,j} (indicial notation)
16 // Inverse of change of coordinate matrix: dXdx_{i,j} = (detJ^-1) * X_{i,j}
17 //
18 // All quadrature data is stored in 10 field vector of quadrature data.
19 //
20 // We require the determinant of the Jacobian to properly compute integrals of the form: int( v u )
21 //
22 // Determinant of Jacobian:
23 //   detJ = J11*J22 - J21*J12
24 //     Jij = Jacobian entry ij
25 //
26 // Stored: w detJ
27 //   in q_data[0]
28 //
29 // We require the transpose of the inverse of the Jacobian to properly compute integrals of the form: int( gradv u )
30 //
31 // Inverse of Jacobian:
32 //   dXdx_i,j = Aij / detJ
33 //   Aij = Adjugate ij
34 //
35 // Stored: Aij / detJ
36 //   in q_data[1:4] as
37 //   (detJ^-1) * [A11 A12]
38 //               [A21 A22]
39 // *****************************************************************************
40 CEED_QFUNCTION(Setup2d)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
41   const CeedScalar(*J)[2][CEED_Q_VLA] = (const CeedScalar(*)[2][CEED_Q_VLA])in[0];
42   const CeedScalar(*w)                = in[1];
43   CeedScalar(*q_data)                 = out[0];
44 
45   CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
46     CeedScalar dXdx[2][2], detJ;
47     InvertMappingJacobian_2D(Q, i, J, dXdx, &detJ);
48     const CeedScalar wdetJ = w[i] * detJ;
49 
50     StoredValuesPack(Q, i, 0, 1, &wdetJ, q_data);
51     StoredValuesPack(Q, i, 1, 4, (const CeedScalar *)dXdx, q_data);
52   }
53   return 0;
54 }
55 
56 // *****************************************************************************
57 // This QFunction sets up the geometric factor required for integration when reference coordinates are in 1D and the physical coordinates are in 2D
58 //
59 // Reference (parent) 1D coordinates: X
60 // Physical (current) 2D coordinates: x
61 // Change of coordinate vector:
62 //           J1 = dx_1/dX
63 //           J2 = dx_2/dX
64 //
65 // detJb is the magnitude of (J1,J2)
66 //
67 // All quadrature data is stored in 3 field vector of quadrature data.
68 //
69 // We require the determinant of the Jacobian to properly compute integrals of the form: int( u v )
70 //
71 // Stored: w detJb
72 //   in q_data_sur[0]
73 //
74 // Normal vector is given by the cross product of (J1,J2)/detJ and ẑ
75 //
76 // Stored: (J1,J2,0) x (0,0,1) / detJb
77 //   in q_data_sur[1:2] as
78 //   (detJb^-1) * [ J2 ]
79 //                [-J1 ]
80 // *****************************************************************************
81 CEED_QFUNCTION(SetupBoundary2d)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
82   const CeedScalar(*J)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0];
83   const CeedScalar(*w)             = in[1];
84   CeedScalar(*q_data_sur)          = out[0];
85 
86   CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
87     CeedScalar normal[2], detJb;
88     NormalVectorFromdxdX_2D(Q, i, J, normal, &detJb);
89     const CeedScalar wdetJ = w[i] * detJb;
90 
91     StoredValuesPack(Q, i, 0, 1, &wdetJ, q_data_sur);
92     StoredValuesPack(Q, i, 1, 2, normal, q_data_sur);
93   }
94   return 0;
95 }
96 
97 // *****************************************************************************
98 // This QFunction sets up the geometric factor required for integration when reference coordinates are in 2D and the physical coordinates are in 3D
99 //
100 // Reference (parent) 2D coordinates: X
101 // Physical (current) 3D coordinates: x
102 // Change of coordinate matrix:
103 //   dxdX_{i,j} = dx_i/dX_j (indicial notation) [3 * 2]
104 // Inverse change of coordinate matrix:
105 //   dXdx_{i,j} = dX_i/dx_j (indicial notation) [2 * 3]
106 //
107 // (J1,J2,J3) is given by the cross product of the columns of dxdX_{i,j}
108 //
109 // detJb is the magnitude of (J1,J2,J3)
110 //
111 // dXdx is calculated via Moore–Penrose inverse:
112 //
113 //   dX_i/dx_j = (dxdX^T dxdX)^(-1) dxdX
114 //             = (dx_l/dX_i * dx_l/dX_k)^(-1) dx_j/dX_k
115 //
116 // All quadrature data is stored in 10 field vector of quadrature data.
117 //
118 // We require the determinant of the Jacobian to properly compute integrals of
119 //   the form: int( u v )
120 //
121 // Stored: w detJb
122 //   in q_data_sur[0]
123 //
124 // Normal vector = (J1,J2,J3) / detJb
125 //
126 // Stored: (J1,J2,J3) / detJb
127 //
128 // Stored: dXdx_{i,j}
129 //   in q_data_sur[1:6] as
130 //    [dXdx_11 dXdx_12 dXdx_13]
131 //    [dXdx_21 dXdx_22 dXdx_23]
132 // *****************************************************************************
133 CEED_QFUNCTION(Setup2D_3Dcoords)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
134   const CeedScalar(*J)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[0];
135   const CeedScalar(*w)                = in[1];
136   CeedScalar(*q_data_sur)             = out[0];
137 
138   CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
139     CeedScalar detJb, normal[3], dXdx[2][3];
140 
141     NormalVectorFromdxdX_3D(Q, i, J, normal, &detJb);
142     InvertBoundaryMappingJacobian_3D(Q, i, J, dXdx);
143     const CeedScalar wdetJ = w[i] * detJb;
144 
145     StoredValuesPack(Q, i, 0, 1, &wdetJ, q_data_sur);
146     StoredValuesPack(Q, i, 1, 6, (const CeedScalar *)dXdx, q_data_sur);
147   }
148   return 0;
149 }
150