xref: /libCEED/examples/fluids/qfunctions/setupgeo2d.h (revision 46603fc57e28d79cde01b07e9ca450b5fd78aed4)
13d8e8822SJeremy L Thompson // Copyright (c) 2017-2022, 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>
1677841947SLeila Ghaffari 
1777841947SLeila Ghaffari // *****************************************************************************
1877841947SLeila Ghaffari // This QFunction sets up the geometric factors required for integration and
1977841947SLeila Ghaffari //   coordinate transformations
2077841947SLeila Ghaffari //
2177841947SLeila Ghaffari // Reference (parent) coordinates: X
2277841947SLeila Ghaffari // Physical (current) coordinates: x
2377841947SLeila Ghaffari // Change of coordinate matrix: dxdX_{i,j} = x_{i,j} (indicial notation)
2477841947SLeila Ghaffari // Inverse of change of coordinate matrix: dXdx_{i,j} = (detJ^-1) * X_{i,j}
2577841947SLeila Ghaffari //
2677841947SLeila Ghaffari // All quadrature data is stored in 10 field vector of quadrature data.
2777841947SLeila Ghaffari //
2877841947SLeila Ghaffari // We require the determinant of the Jacobian to properly compute integrals of
2977841947SLeila Ghaffari //   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 //
3877841947SLeila Ghaffari // We require the transpose of the inverse of the Jacobian to properly compute
3977841947SLeila Ghaffari //   integrals of the form: int( gradv u )
4077841947SLeila Ghaffari //
4177841947SLeila Ghaffari // Inverse of Jacobian:
4277841947SLeila Ghaffari //   dXdx_i,j = Aij / detJ
4377841947SLeila Ghaffari //   Aij = Adjoint ij
4477841947SLeila Ghaffari //
4577841947SLeila Ghaffari // Stored: Aij / detJ
4677841947SLeila Ghaffari //   in q_data[1:4] as
4777841947SLeila Ghaffari //   (detJ^-1) * [A11 A12]
4877841947SLeila Ghaffari //               [A21 A22]
4977841947SLeila Ghaffari //
5077841947SLeila Ghaffari // *****************************************************************************
512b730f8bSJeremy L Thompson CEED_QFUNCTION(Setup2d)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
5277841947SLeila Ghaffari   // Inputs
53*46603fc5SJames Wright   const CeedScalar(*J)[2][CEED_Q_VLA] = (const CeedScalar(*)[2][CEED_Q_VLA])in[0];
54*46603fc5SJames Wright   const CeedScalar(*w)                = in[1];
55*46603fc5SJames Wright 
5677841947SLeila Ghaffari   // Outputs
5777841947SLeila Ghaffari   CeedScalar(*q_data)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];
5877841947SLeila Ghaffari 
5977841947SLeila Ghaffari   CeedPragmaSIMD
6077841947SLeila Ghaffari       // Quadrature Point Loop
6177841947SLeila Ghaffari       for (CeedInt i = 0; i < Q; i++) {
6277841947SLeila Ghaffari     // Setup
6377841947SLeila Ghaffari     const CeedScalar J11  = J[0][0][i];
6477841947SLeila Ghaffari     const CeedScalar J21  = J[0][1][i];
6577841947SLeila Ghaffari     const CeedScalar J12  = J[1][0][i];
6677841947SLeila Ghaffari     const CeedScalar J22  = J[1][1][i];
6777841947SLeila Ghaffari     const CeedScalar detJ = J11 * J22 - J21 * J12;
6877841947SLeila Ghaffari 
6977841947SLeila Ghaffari     // Qdata
7077841947SLeila Ghaffari     // -- Interp-to-Interp q_data
7177841947SLeila Ghaffari     q_data[0][i] = w[i] * detJ;
7277841947SLeila Ghaffari     // -- Interp-to-Grad q_data
7377841947SLeila Ghaffari     // Inverse of change of coordinate matrix: X_i,j
7477841947SLeila Ghaffari     q_data[1][i] = J22 / detJ;
7543e9189fSRezgar Shakeri     q_data[2][i] = -J12 / detJ;
7643e9189fSRezgar Shakeri     q_data[3][i] = -J21 / detJ;
7777841947SLeila Ghaffari     q_data[4][i] = J11 / detJ;
7877841947SLeila Ghaffari   }  // End of Quadrature Point Loop
7977841947SLeila Ghaffari 
8077841947SLeila Ghaffari   // Return
8177841947SLeila Ghaffari   return 0;
8277841947SLeila Ghaffari }
8377841947SLeila Ghaffari 
8477841947SLeila Ghaffari // *****************************************************************************
8577841947SLeila Ghaffari // This QFunction sets up the geometric factor required for integration when
8677841947SLeila Ghaffari //   reference coordinates are in 1D and the physical coordinates are in 2D
8777841947SLeila Ghaffari //
8877841947SLeila Ghaffari // Reference (parent) 1D coordinates: X
8977841947SLeila Ghaffari // Physical (current) 2D coordinates: x
9077841947SLeila Ghaffari // Change of coordinate vector:
9177841947SLeila Ghaffari //           J1 = dx_1/dX
9277841947SLeila Ghaffari //           J2 = dx_2/dX
9377841947SLeila Ghaffari //
9477841947SLeila Ghaffari // detJb is the magnitude of (J1,J2)
9577841947SLeila Ghaffari //
9677841947SLeila Ghaffari // All quadrature data is stored in 3 field vector of quadrature data.
9777841947SLeila Ghaffari //
9877841947SLeila Ghaffari // We require the determinant of the Jacobian to properly compute integrals of
9977841947SLeila Ghaffari //   the form: int( u v )
10077841947SLeila Ghaffari //
10177841947SLeila Ghaffari // Stored: w detJb
10277841947SLeila Ghaffari //   in q_data_sur[0]
10377841947SLeila Ghaffari //
10477841947SLeila Ghaffari // Normal vector is given by the cross product of (J1,J2)/detJ and ẑ
10577841947SLeila Ghaffari //
10677841947SLeila Ghaffari // Stored: (J1,J2,0) x (0,0,1) / detJb
10777841947SLeila Ghaffari //   in q_data_sur[1:2] as
10877841947SLeila Ghaffari //   (detJb^-1) * [ J2 ]
10977841947SLeila Ghaffari //                [-J1 ]
11077841947SLeila Ghaffari //
11177841947SLeila Ghaffari // *****************************************************************************
1122b730f8bSJeremy L Thompson CEED_QFUNCTION(SetupBoundary2d)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
11377841947SLeila Ghaffari   // Inputs
114*46603fc5SJames Wright   const CeedScalar(*J)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0];
115*46603fc5SJames Wright   const CeedScalar(*w)             = in[1];
116*46603fc5SJames Wright 
11777841947SLeila Ghaffari   // Outputs
11877841947SLeila Ghaffari   CeedScalar(*q_data_sur)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];
11977841947SLeila Ghaffari 
12077841947SLeila Ghaffari   CeedPragmaSIMD
12177841947SLeila Ghaffari       // Quadrature Point Loop
12277841947SLeila Ghaffari       for (CeedInt i = 0; i < Q; i++) {
12377841947SLeila Ghaffari     // Setup
12477841947SLeila Ghaffari     const CeedScalar J1 = J[0][i];
12577841947SLeila Ghaffari     const CeedScalar J2 = J[1][i];
12677841947SLeila Ghaffari 
12777841947SLeila Ghaffari     const CeedScalar detJb = sqrt(J1 * J1 + J2 * J2);
12877841947SLeila Ghaffari 
12977841947SLeila Ghaffari     q_data_sur[0][i] = w[i] * detJb;
13077841947SLeila Ghaffari     q_data_sur[1][i] = J2 / detJb;
13177841947SLeila Ghaffari     q_data_sur[2][i] = -J1 / detJb;
13277841947SLeila Ghaffari   }  // End of Quadrature Point Loop
13377841947SLeila Ghaffari 
13477841947SLeila Ghaffari   // Return
13577841947SLeila Ghaffari   return 0;
13677841947SLeila Ghaffari }
13777841947SLeila Ghaffari 
13877841947SLeila Ghaffari // *****************************************************************************
13977841947SLeila Ghaffari 
14077841947SLeila Ghaffari #endif  // setup_geo_2d_h
141