xref: /libCEED/examples/fluids/qfunctions/setupgeo2d.h (revision bf415d3f2caaa496a7237a74a170eda6d09dd921)
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   // Inputs
92   const CeedScalar(*J)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0];
93   const CeedScalar(*w)             = in[1];
94 
95   // Outputs
96   CeedScalar(*q_data_sur)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];
97 
98   CeedPragmaSIMD
99       // Quadrature Point Loop
100       for (CeedInt i = 0; i < Q; i++) {
101     // Setup
102     const CeedScalar J1 = J[0][i];
103     const CeedScalar J2 = J[1][i];
104 
105     const CeedScalar detJb = sqrt(J1 * J1 + J2 * J2);
106 
107     q_data_sur[0][i] = w[i] * detJb;
108     q_data_sur[1][i] = J2 / detJb;
109     q_data_sur[2][i] = -J1 / detJb;
110   }  // End of Quadrature Point Loop
111 
112   // Return
113   return 0;
114 }
115 
116 // *****************************************************************************
117 
118 #endif  // setup_geo_2d_h
119