xref: /honee/qfunctions/setupgeo.h (revision 1a74fa3085319ee7f03f3896ebeee61542107f4d)
1*1a74fa30SJames Wright // Copyright (c) 2017-2023, Lawrence Livermore National Security, LLC and other CEED contributors.
2727da7e7SJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
3a515125bSLeila Ghaffari //
4727da7e7SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause
5a515125bSLeila Ghaffari //
6727da7e7SJeremy L Thompson // This file is part of CEED:  http://github.com/ceed
7a515125bSLeila Ghaffari 
8a515125bSLeila Ghaffari /// @file
9a515125bSLeila Ghaffari /// Geometric factors (3D) for Navier-Stokes example using PETSc
10a515125bSLeila Ghaffari 
11a515125bSLeila Ghaffari #ifndef setup_geo_h
12a515125bSLeila Ghaffari #define setup_geo_h
13a515125bSLeila Ghaffari 
143a8779fbSJames Wright #include <ceed.h>
15d0cce58aSJeremy L Thompson #include <math.h>
16a515125bSLeila Ghaffari 
17*1a74fa30SJames Wright #include "setupgeo_helpers.h"
18*1a74fa30SJames Wright 
19a515125bSLeila Ghaffari // *****************************************************************************
2004e40bb6SJeremy L Thompson // This QFunction sets up the geometric factors required for integration and coordinate transformations
21a515125bSLeila Ghaffari //
22a515125bSLeila Ghaffari // Reference (parent) coordinates: X
23a515125bSLeila Ghaffari // Physical (current) coordinates: x
24a515125bSLeila Ghaffari // Change of coordinate matrix: dxdX_{i,j} = x_{i,j} (indicial notation)
25a515125bSLeila Ghaffari // Inverse of change of coordinate matrix: dXdx_{i,j} = (detJ^-1) * X_{i,j}
26a515125bSLeila Ghaffari //
27a515125bSLeila Ghaffari // All quadrature data is stored in 10 field vector of quadrature data.
28a515125bSLeila Ghaffari //
2904e40bb6SJeremy L Thompson // We require the determinant of the Jacobian to properly compute integrals of the form: int( v u )
30a515125bSLeila Ghaffari //
31a515125bSLeila Ghaffari // Determinant of Jacobian:
32a515125bSLeila Ghaffari //   detJ = J11*A11 + J21*A12 + J31*A13
33a515125bSLeila Ghaffari //     Jij = Jacobian entry ij
34*1a74fa30SJames Wright //     Aij = Adjugate ij
35a515125bSLeila Ghaffari //
36a515125bSLeila Ghaffari // Stored: w detJ
37a515125bSLeila Ghaffari //   in q_data[0]
38a515125bSLeila Ghaffari //
3904e40bb6SJeremy L Thompson // We require the transpose of the inverse of the Jacobian to properly compute integrals of the form: int( gradv u )
40a515125bSLeila Ghaffari //
41a515125bSLeila Ghaffari // Inverse of Jacobian:
42a515125bSLeila Ghaffari //   dXdx_i,j = Aij / detJ
43a515125bSLeila Ghaffari //
44a515125bSLeila Ghaffari // Stored: Aij / detJ
45a515125bSLeila Ghaffari //   in q_data[1:9] as
46a515125bSLeila Ghaffari //   (detJ^-1) * [A11 A12 A13]
47a515125bSLeila Ghaffari //               [A21 A22 A23]
48a515125bSLeila Ghaffari //               [A31 A32 A33]
49a515125bSLeila Ghaffari // *****************************************************************************
502b916ea7SJeremy L Thompson CEED_QFUNCTION(Setup)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
513d65b166SJames Wright   const CeedScalar(*J)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[0];
523d65b166SJames Wright   const CeedScalar(*w)                = in[1];
53a515125bSLeila Ghaffari   CeedScalar(*q_data)[CEED_Q_VLA]     = (CeedScalar(*)[CEED_Q_VLA])out[0];
54a515125bSLeila Ghaffari 
55*1a74fa30SJames Wright   CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
56*1a74fa30SJames Wright     CeedScalar detJ, dXdx[3][3];
57*1a74fa30SJames Wright     InvertMappingJacobian_3D(Q, i, J, dXdx, &detJ);
58a515125bSLeila Ghaffari     q_data[0][i] = w[i] * detJ;
59*1a74fa30SJames Wright     q_data[1][i] = dXdx[0][0];
60*1a74fa30SJames Wright     q_data[2][i] = dXdx[0][1];
61*1a74fa30SJames Wright     q_data[3][i] = dXdx[0][2];
62*1a74fa30SJames Wright     q_data[4][i] = dXdx[1][0];
63*1a74fa30SJames Wright     q_data[5][i] = dXdx[1][1];
64*1a74fa30SJames Wright     q_data[6][i] = dXdx[1][2];
65*1a74fa30SJames Wright     q_data[7][i] = dXdx[2][0];
66*1a74fa30SJames Wright     q_data[8][i] = dXdx[2][1];
67*1a74fa30SJames Wright     q_data[9][i] = dXdx[2][2];
68*1a74fa30SJames Wright   }
69a515125bSLeila Ghaffari   return 0;
70a515125bSLeila Ghaffari }
71a515125bSLeila Ghaffari 
72a515125bSLeila Ghaffari // *****************************************************************************
7304e40bb6SJeremy 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
74a515125bSLeila Ghaffari //
75a515125bSLeila Ghaffari // Reference (parent) 2D coordinates: X
76a515125bSLeila Ghaffari // Physical (current) 3D coordinates: x
77a515125bSLeila Ghaffari // Change of coordinate matrix:
78a515125bSLeila Ghaffari //   dxdX_{i,j} = dx_i/dX_j (indicial notation) [3 * 2]
79493642f1SJames Wright // Inverse change of coordinate matrix:
80493642f1SJames Wright //   dXdx_{i,j} = dX_i/dx_j (indicial notation) [2 * 3]
81a515125bSLeila Ghaffari //
82a515125bSLeila Ghaffari // (J1,J2,J3) is given by the cross product of the columns of dxdX_{i,j}
83a515125bSLeila Ghaffari //
84a515125bSLeila Ghaffari // detJb is the magnitude of (J1,J2,J3)
85a515125bSLeila Ghaffari //
86493642f1SJames Wright // dXdx is calculated via Moore–Penrose inverse:
87493642f1SJames Wright //
88493642f1SJames Wright //   dX_i/dx_j = (dxdX^T dxdX)^(-1) dxdX
89493642f1SJames Wright //             = (dx_l/dX_i * dx_l/dX_k)^(-1) dx_j/dX_k
90493642f1SJames Wright //
91493642f1SJames Wright // All quadrature data is stored in 10 field vector of quadrature data.
92a515125bSLeila Ghaffari //
93a515125bSLeila Ghaffari // We require the determinant of the Jacobian to properly compute integrals of
94a515125bSLeila Ghaffari //   the form: int( u v )
95a515125bSLeila Ghaffari //
96a515125bSLeila Ghaffari // Stored: w detJb
97a515125bSLeila Ghaffari //   in q_data_sur[0]
98a515125bSLeila Ghaffari //
99a515125bSLeila Ghaffari // Normal vector = (J1,J2,J3) / detJb
100a515125bSLeila Ghaffari //
101493642f1SJames Wright //   - TODO Could possibly remove normal vector, as it could be calculated in the Qfunction from dXdx
102*1a74fa30SJames Wright //    See https://github.com/CEED/libCEED/pull/868#discussion_r871979484
103a515125bSLeila Ghaffari // Stored: (J1,J2,J3) / detJb
104a515125bSLeila Ghaffari //   in q_data_sur[1:3] as
105a515125bSLeila Ghaffari //   (detJb^-1) * [ J1 ]
106a515125bSLeila Ghaffari //                [ J2 ]
107a515125bSLeila Ghaffari //                [ J3 ]
108a515125bSLeila Ghaffari //
109493642f1SJames Wright // Stored: dXdx_{i,j}
110493642f1SJames Wright //   in q_data_sur[4:9] as
111493642f1SJames Wright //    [dXdx_11 dXdx_12 dXdx_13]
112493642f1SJames Wright //    [dXdx_21 dXdx_22 dXdx_23]
113a515125bSLeila Ghaffari // *****************************************************************************
1142b916ea7SJeremy L Thompson CEED_QFUNCTION(SetupBoundary)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
1153d65b166SJames Wright   const CeedScalar(*J)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[0];
1163d65b166SJames Wright   const CeedScalar(*w)                = in[1];
117a515125bSLeila Ghaffari   CeedScalar(*q_data_sur)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];
118a515125bSLeila Ghaffari 
119*1a74fa30SJames Wright   CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
120*1a74fa30SJames Wright     CeedScalar detJb, normal[3], dXdx[2][3];
121a515125bSLeila Ghaffari 
122*1a74fa30SJames Wright     NormalVectorFromdxdX_3D(Q, i, J, normal, &detJb);
123a515125bSLeila Ghaffari     q_data_sur[0][i] = w[i] * detJb;
124*1a74fa30SJames Wright     q_data_sur[1][i] = normal[0];
125*1a74fa30SJames Wright     q_data_sur[2][i] = normal[1];
126*1a74fa30SJames Wright     q_data_sur[3][i] = normal[2];
127a515125bSLeila Ghaffari 
128*1a74fa30SJames Wright     InvertBoundaryMappingJacobian_3D(Q, i, J, dXdx);
129493642f1SJames Wright     q_data_sur[4][i] = dXdx[0][0];
130493642f1SJames Wright     q_data_sur[5][i] = dXdx[0][1];
131493642f1SJames Wright     q_data_sur[6][i] = dXdx[0][2];
132493642f1SJames Wright     q_data_sur[7][i] = dXdx[1][0];
133493642f1SJames Wright     q_data_sur[8][i] = dXdx[1][1];
134493642f1SJames Wright     q_data_sur[9][i] = dXdx[1][2];
135*1a74fa30SJames Wright   }
136a515125bSLeila Ghaffari   return 0;
137a515125bSLeila Ghaffari }
138a515125bSLeila Ghaffari 
139a515125bSLeila Ghaffari // *****************************************************************************
140a515125bSLeila Ghaffari 
141a515125bSLeila Ghaffari #endif  // setup_geo_h
142