xref: /libCEED/examples/fluids/qfunctions/setupgeo2d.h (revision ea61e9ac44808524e4667c1525a05976f536c19c)
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 // *****************************************************************************
18*ea61e9acSJeremy L Thompson // This QFunction sets up the geometric factors required for integration and coordinate transformations
1977841947SLeila Ghaffari //
2077841947SLeila Ghaffari // Reference (parent) coordinates: X
2177841947SLeila Ghaffari // Physical (current) coordinates: x
2277841947SLeila Ghaffari // Change of coordinate matrix: dxdX_{i,j} = x_{i,j} (indicial notation)
2377841947SLeila Ghaffari // Inverse of change of coordinate matrix: dXdx_{i,j} = (detJ^-1) * X_{i,j}
2477841947SLeila Ghaffari //
2577841947SLeila Ghaffari // All quadrature data is stored in 10 field vector of quadrature data.
2677841947SLeila Ghaffari //
27*ea61e9acSJeremy L Thompson // We require the determinant of the Jacobian to properly compute integrals of the form: int( v u )
2877841947SLeila Ghaffari //
2977841947SLeila Ghaffari // Determinant of Jacobian:
3077841947SLeila Ghaffari //   detJ = J11*J22 - J21*J12
3177841947SLeila Ghaffari //     Jij = Jacobian entry ij
3277841947SLeila Ghaffari //
3377841947SLeila Ghaffari // Stored: w detJ
3477841947SLeila Ghaffari //   in q_data[0]
3577841947SLeila Ghaffari //
36*ea61e9acSJeremy L Thompson // We require the transpose of the inverse of the Jacobian to properly compute integrals of the form: int( gradv u )
3777841947SLeila Ghaffari //
3877841947SLeila Ghaffari // Inverse of Jacobian:
3977841947SLeila Ghaffari //   dXdx_i,j = Aij / detJ
4077841947SLeila Ghaffari //   Aij = Adjoint ij
4177841947SLeila Ghaffari //
4277841947SLeila Ghaffari // Stored: Aij / detJ
4377841947SLeila Ghaffari //   in q_data[1:4] as
4477841947SLeila Ghaffari //   (detJ^-1) * [A11 A12]
4577841947SLeila Ghaffari //               [A21 A22]
4677841947SLeila Ghaffari // *****************************************************************************
472b730f8bSJeremy L Thompson CEED_QFUNCTION(Setup2d)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
4877841947SLeila Ghaffari   // Inputs
4946603fc5SJames Wright   const CeedScalar(*J)[2][CEED_Q_VLA] = (const CeedScalar(*)[2][CEED_Q_VLA])in[0];
5046603fc5SJames Wright   const CeedScalar(*w)                = in[1];
5146603fc5SJames Wright 
5277841947SLeila Ghaffari   // Outputs
5377841947SLeila Ghaffari   CeedScalar(*q_data)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];
5477841947SLeila Ghaffari 
5577841947SLeila Ghaffari   CeedPragmaSIMD
5677841947SLeila Ghaffari       // Quadrature Point Loop
5777841947SLeila Ghaffari       for (CeedInt i = 0; i < Q; i++) {
5877841947SLeila Ghaffari     // Setup
5977841947SLeila Ghaffari     const CeedScalar J11  = J[0][0][i];
6077841947SLeila Ghaffari     const CeedScalar J21  = J[0][1][i];
6177841947SLeila Ghaffari     const CeedScalar J12  = J[1][0][i];
6277841947SLeila Ghaffari     const CeedScalar J22  = J[1][1][i];
6377841947SLeila Ghaffari     const CeedScalar detJ = J11 * J22 - J21 * J12;
6477841947SLeila Ghaffari 
6577841947SLeila Ghaffari     // Qdata
6677841947SLeila Ghaffari     // -- Interp-to-Interp q_data
6777841947SLeila Ghaffari     q_data[0][i] = w[i] * detJ;
6877841947SLeila Ghaffari     // -- Interp-to-Grad q_data
6977841947SLeila Ghaffari     // Inverse of change of coordinate matrix: X_i,j
7077841947SLeila Ghaffari     q_data[1][i] = J22 / detJ;
7143e9189fSRezgar Shakeri     q_data[2][i] = -J12 / detJ;
7243e9189fSRezgar Shakeri     q_data[3][i] = -J21 / detJ;
7377841947SLeila Ghaffari     q_data[4][i] = J11 / detJ;
7477841947SLeila Ghaffari   }  // End of Quadrature Point Loop
7577841947SLeila Ghaffari 
7677841947SLeila Ghaffari   // Return
7777841947SLeila Ghaffari   return 0;
7877841947SLeila Ghaffari }
7977841947SLeila Ghaffari 
8077841947SLeila Ghaffari // *****************************************************************************
81*ea61e9acSJeremy 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
8277841947SLeila Ghaffari //
8377841947SLeila Ghaffari // Reference (parent) 1D coordinates: X
8477841947SLeila Ghaffari // Physical (current) 2D coordinates: x
8577841947SLeila Ghaffari // Change of coordinate vector:
8677841947SLeila Ghaffari //           J1 = dx_1/dX
8777841947SLeila Ghaffari //           J2 = dx_2/dX
8877841947SLeila Ghaffari //
8977841947SLeila Ghaffari // detJb is the magnitude of (J1,J2)
9077841947SLeila Ghaffari //
9177841947SLeila Ghaffari // All quadrature data is stored in 3 field vector of quadrature data.
9277841947SLeila Ghaffari //
93*ea61e9acSJeremy L Thompson // We require the determinant of the Jacobian to properly compute integrals of the form: int( u v )
9477841947SLeila Ghaffari //
9577841947SLeila Ghaffari // Stored: w detJb
9677841947SLeila Ghaffari //   in q_data_sur[0]
9777841947SLeila Ghaffari //
9877841947SLeila Ghaffari // Normal vector is given by the cross product of (J1,J2)/detJ and ẑ
9977841947SLeila Ghaffari //
10077841947SLeila Ghaffari // Stored: (J1,J2,0) x (0,0,1) / detJb
10177841947SLeila Ghaffari //   in q_data_sur[1:2] as
10277841947SLeila Ghaffari //   (detJb^-1) * [ J2 ]
10377841947SLeila Ghaffari //                [-J1 ]
10477841947SLeila Ghaffari // *****************************************************************************
1052b730f8bSJeremy L Thompson CEED_QFUNCTION(SetupBoundary2d)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
10677841947SLeila Ghaffari   // Inputs
10746603fc5SJames Wright   const CeedScalar(*J)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0];
10846603fc5SJames Wright   const CeedScalar(*w)             = in[1];
10946603fc5SJames Wright 
11077841947SLeila Ghaffari   // Outputs
11177841947SLeila Ghaffari   CeedScalar(*q_data_sur)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];
11277841947SLeila Ghaffari 
11377841947SLeila Ghaffari   CeedPragmaSIMD
11477841947SLeila Ghaffari       // Quadrature Point Loop
11577841947SLeila Ghaffari       for (CeedInt i = 0; i < Q; i++) {
11677841947SLeila Ghaffari     // Setup
11777841947SLeila Ghaffari     const CeedScalar J1 = J[0][i];
11877841947SLeila Ghaffari     const CeedScalar J2 = J[1][i];
11977841947SLeila Ghaffari 
12077841947SLeila Ghaffari     const CeedScalar detJb = sqrt(J1 * J1 + J2 * J2);
12177841947SLeila Ghaffari 
12277841947SLeila Ghaffari     q_data_sur[0][i] = w[i] * detJb;
12377841947SLeila Ghaffari     q_data_sur[1][i] = J2 / detJb;
12477841947SLeila Ghaffari     q_data_sur[2][i] = -J1 / detJb;
12577841947SLeila Ghaffari   }  // End of Quadrature Point Loop
12677841947SLeila Ghaffari 
12777841947SLeila Ghaffari   // Return
12877841947SLeila Ghaffari   return 0;
12977841947SLeila Ghaffari }
13077841947SLeila Ghaffari 
13177841947SLeila Ghaffari // *****************************************************************************
13277841947SLeila Ghaffari 
13377841947SLeila Ghaffari #endif  // setup_geo_2d_h
134