xref: /libCEED/examples/fluids/qfunctions/setupgeo2d.h (revision 22070f9510d4ff69aa6119a59aa3c46d57cc1cc7)
1 // Copyright (c) 2017-2022, 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 
11 #ifndef setup_geo_2d_h
12 #define setup_geo_2d_h
13 
14 #include <ceed.h>
15 #include <math.h>
16 #include "setupgeo_helpers.h"
17 #include "utils.h"
18 
19 // *****************************************************************************
20 // This QFunction sets up the geometric factors required for integration and coordinate transformations
21 //
22 // Reference (parent) coordinates: X
23 // Physical (current) coordinates: x
24 // Change of coordinate matrix: dxdX_{i,j} = x_{i,j} (indicial notation)
25 // Inverse of change of coordinate matrix: dXdx_{i,j} = (detJ^-1) * X_{i,j}
26 //
27 // All quadrature data is stored in 10 field vector of quadrature data.
28 //
29 // We require the determinant of the Jacobian to properly compute integrals of the form: int( v u )
30 //
31 // Determinant of Jacobian:
32 //   detJ = J11*J22 - J21*J12
33 //     Jij = Jacobian entry ij
34 //
35 // Stored: w detJ
36 //   in q_data[0]
37 //
38 // We require the transpose of the inverse of the Jacobian to properly compute integrals of the form: int( gradv u )
39 //
40 // Inverse of Jacobian:
41 //   dXdx_i,j = Aij / detJ
42 //   Aij = Adjugate ij
43 //
44 // Stored: Aij / detJ
45 //   in q_data[1:4] as
46 //   (detJ^-1) * [A11 A12]
47 //               [A21 A22]
48 // *****************************************************************************
49 CEED_QFUNCTION(Setup2d)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
50   const CeedScalar(*J)[2][CEED_Q_VLA] = (const CeedScalar(*)[2][CEED_Q_VLA])in[0];
51   const CeedScalar(*w)                = in[1];
52   CeedScalar(*q_data)                 = out[0];
53 
54   CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
55     CeedScalar dXdx[2][2], detJ;
56     InvertMappingJacobian_2D(Q, i, J, dXdx, &detJ);
57     const CeedScalar wdetJ = w[i] * detJ;
58 
59     StoredValuesPack(Q, i, 0, 1, &wdetJ, q_data);
60     StoredValuesPack(Q, i, 1, 4, (const CeedScalar *)dXdx, q_data);
61   }
62   return 0;
63 }
64 
65 // *****************************************************************************
66 // This QFunction sets up the geometric factor required for integration when reference coordinates are in 1D and the physical coordinates are in 2D
67 //
68 // Reference (parent) 1D coordinates: X
69 // Physical (current) 2D coordinates: x
70 // Change of coordinate vector:
71 //           J1 = dx_1/dX
72 //           J2 = dx_2/dX
73 //
74 // detJb is the magnitude of (J1,J2)
75 //
76 // All quadrature data is stored in 3 field vector of quadrature data.
77 //
78 // We require the determinant of the Jacobian to properly compute integrals of the form: int( u v )
79 //
80 // Stored: w detJb
81 //   in q_data_sur[0]
82 //
83 // Normal vector is given by the cross product of (J1,J2)/detJ and ẑ
84 //
85 // Stored: (J1,J2,0) x (0,0,1) / detJb
86 //   in q_data_sur[1:2] as
87 //   (detJb^-1) * [ J2 ]
88 //                [-J1 ]
89 // *****************************************************************************
90 CEED_QFUNCTION(SetupBoundary2d)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
91   const CeedScalar(*J)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0];
92   const CeedScalar(*w)             = in[1];
93   CeedScalar(*q_data_sur)          = out[0];
94 
95   CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
96     CeedScalar normal[2], detJb;
97     NormalVectorFromdxdX_2D(Q, i, J, normal, &detJb);
98     const CeedScalar wdetJ = w[i] * detJb;
99 
100     StoredValuesPack(Q, i, 0, 1, &wdetJ, q_data_sur);
101     StoredValuesPack(Q, i, 1, 2, normal, q_data_sur);
102   }
103   return 0;
104 }
105 
106 // *****************************************************************************
107 
108 #endif  // setup_geo_2d_h
109