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