xref: /libCEED/examples/fluids/qfunctions/setupgeo2d.h (revision 5aed82e4fa97acf4ba24a7f10a35f5303a6798e0)
1*5aed82e4SJeremy L Thompson // Copyright (c) 2017-2024, Lawrence Livermore National Security, LLC and other CEED contributors.
23d8e8822SJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
377841947SLeila Ghaffari //
43d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause
577841947SLeila Ghaffari //
63d8e8822SJeremy L Thompson // This file is part of CEED:  http://github.com/ceed
777841947SLeila Ghaffari 
877841947SLeila Ghaffari /// @file
977841947SLeila Ghaffari /// Geometric factors (2D) for Navier-Stokes example using PETSc
1077841947SLeila Ghaffari 
1177841947SLeila Ghaffari #ifndef setup_geo_2d_h
1277841947SLeila Ghaffari #define setup_geo_2d_h
1377841947SLeila Ghaffari 
14ba6664aeSJames Wright #include <ceed.h>
15c9c2c079SJeremy L Thompson #include <math.h>
16bf415d3fSJames Wright #include "setupgeo_helpers.h"
17bf415d3fSJames Wright #include "utils.h"
1877841947SLeila Ghaffari 
1977841947SLeila Ghaffari // *****************************************************************************
20ea61e9acSJeremy L Thompson // This QFunction sets up the geometric factors required for integration and coordinate transformations
2177841947SLeila Ghaffari //
2277841947SLeila Ghaffari // Reference (parent) coordinates: X
2377841947SLeila Ghaffari // Physical (current) coordinates: x
2477841947SLeila Ghaffari // Change of coordinate matrix: dxdX_{i,j} = x_{i,j} (indicial notation)
2577841947SLeila Ghaffari // Inverse of change of coordinate matrix: dXdx_{i,j} = (detJ^-1) * X_{i,j}
2677841947SLeila Ghaffari //
2777841947SLeila Ghaffari // All quadrature data is stored in 10 field vector of quadrature data.
2877841947SLeila Ghaffari //
29ea61e9acSJeremy L Thompson // We require the determinant of the Jacobian to properly compute integrals of the form: int( v u )
3077841947SLeila Ghaffari //
3177841947SLeila Ghaffari // Determinant of Jacobian:
3277841947SLeila Ghaffari //   detJ = J11*J22 - J21*J12
3377841947SLeila Ghaffari //     Jij = Jacobian entry ij
3477841947SLeila Ghaffari //
3577841947SLeila Ghaffari // Stored: w detJ
3677841947SLeila Ghaffari //   in q_data[0]
3777841947SLeila Ghaffari //
38ea61e9acSJeremy L Thompson // We require the transpose of the inverse of the Jacobian to properly compute integrals of the form: int( gradv u )
3977841947SLeila Ghaffari //
4077841947SLeila Ghaffari // Inverse of Jacobian:
4177841947SLeila Ghaffari //   dXdx_i,j = Aij / detJ
42bf415d3fSJames Wright //   Aij = Adjugate ij
4377841947SLeila Ghaffari //
4477841947SLeila Ghaffari // Stored: Aij / detJ
4577841947SLeila Ghaffari //   in q_data[1:4] as
4677841947SLeila Ghaffari //   (detJ^-1) * [A11 A12]
4777841947SLeila Ghaffari //               [A21 A22]
4877841947SLeila Ghaffari // *****************************************************************************
492b730f8bSJeremy L Thompson CEED_QFUNCTION(Setup2d)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
5046603fc5SJames Wright   const CeedScalar(*J)[2][CEED_Q_VLA] = (const CeedScalar(*)[2][CEED_Q_VLA])in[0];
5146603fc5SJames Wright   const CeedScalar(*w)                = in[1];
52bf415d3fSJames Wright   CeedScalar(*q_data)                 = out[0];
5346603fc5SJames Wright 
54bf415d3fSJames Wright   CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
55bf415d3fSJames Wright     CeedScalar dXdx[2][2], detJ;
56bf415d3fSJames Wright     InvertMappingJacobian_2D(Q, i, J, dXdx, &detJ);
57bf415d3fSJames Wright     const CeedScalar wdetJ = w[i] * detJ;
5877841947SLeila Ghaffari 
59bf415d3fSJames Wright     StoredValuesPack(Q, i, 0, 1, &wdetJ, q_data);
60bf415d3fSJames Wright     StoredValuesPack(Q, i, 1, 4, (const CeedScalar *)dXdx, q_data);
61bf415d3fSJames Wright   }
6277841947SLeila Ghaffari   return 0;
6377841947SLeila Ghaffari }
6477841947SLeila Ghaffari 
6577841947SLeila Ghaffari // *****************************************************************************
66ea61e9acSJeremy L Thompson // This QFunction sets up the geometric factor required for integration when reference coordinates are in 1D and the physical coordinates are in 2D
6777841947SLeila Ghaffari //
6877841947SLeila Ghaffari // Reference (parent) 1D coordinates: X
6977841947SLeila Ghaffari // Physical (current) 2D coordinates: x
7077841947SLeila Ghaffari // Change of coordinate vector:
7177841947SLeila Ghaffari //           J1 = dx_1/dX
7277841947SLeila Ghaffari //           J2 = dx_2/dX
7377841947SLeila Ghaffari //
7477841947SLeila Ghaffari // detJb is the magnitude of (J1,J2)
7577841947SLeila Ghaffari //
7677841947SLeila Ghaffari // All quadrature data is stored in 3 field vector of quadrature data.
7777841947SLeila Ghaffari //
78ea61e9acSJeremy L Thompson // We require the determinant of the Jacobian to properly compute integrals of the form: int( u v )
7977841947SLeila Ghaffari //
8077841947SLeila Ghaffari // Stored: w detJb
8177841947SLeila Ghaffari //   in q_data_sur[0]
8277841947SLeila Ghaffari //
8377841947SLeila Ghaffari // Normal vector is given by the cross product of (J1,J2)/detJ and ẑ
8477841947SLeila Ghaffari //
8577841947SLeila Ghaffari // Stored: (J1,J2,0) x (0,0,1) / detJb
8677841947SLeila Ghaffari //   in q_data_sur[1:2] as
8777841947SLeila Ghaffari //   (detJb^-1) * [ J2 ]
8877841947SLeila Ghaffari //                [-J1 ]
8977841947SLeila Ghaffari // *****************************************************************************
902b730f8bSJeremy L Thompson CEED_QFUNCTION(SetupBoundary2d)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
9146603fc5SJames Wright   const CeedScalar(*J)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0];
9246603fc5SJames Wright   const CeedScalar(*w)             = in[1];
931394d07eSJames Wright   CeedScalar(*q_data_sur)          = out[0];
9446603fc5SJames Wright 
951394d07eSJames Wright   CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
961394d07eSJames Wright     CeedScalar normal[2], detJb;
971394d07eSJames Wright     NormalVectorFromdxdX_2D(Q, i, J, normal, &detJb);
981394d07eSJames Wright     const CeedScalar wdetJ = w[i] * detJb;
9977841947SLeila Ghaffari 
1001394d07eSJames Wright     StoredValuesPack(Q, i, 0, 1, &wdetJ, q_data_sur);
1011394d07eSJames Wright     StoredValuesPack(Q, i, 1, 2, normal, q_data_sur);
1021394d07eSJames Wright   }
10377841947SLeila Ghaffari   return 0;
10477841947SLeila Ghaffari }
10577841947SLeila Ghaffari 
10677841947SLeila Ghaffari // *****************************************************************************
10777841947SLeila Ghaffari 
10877841947SLeila Ghaffari #endif  // setup_geo_2d_h
109