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> 16*bf415d3fSJames Wright #include "setupgeo_helpers.h" 17*bf415d3fSJames 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 42*bf415d3fSJames 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]; 52*bf415d3fSJames Wright CeedScalar(*q_data) = out[0]; 5346603fc5SJames Wright 54*bf415d3fSJames Wright CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 55*bf415d3fSJames Wright CeedScalar dXdx[2][2], detJ; 56*bf415d3fSJames Wright InvertMappingJacobian_2D(Q, i, J, dXdx, &detJ); 57*bf415d3fSJames Wright const CeedScalar wdetJ = w[i] * detJ; 5877841947SLeila Ghaffari 59*bf415d3fSJames Wright StoredValuesPack(Q, i, 0, 1, &wdetJ, q_data); 60*bf415d3fSJames Wright StoredValuesPack(Q, i, 1, 4, (const CeedScalar *)dXdx, q_data); 61*bf415d3fSJames 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) { 9177841947SLeila Ghaffari // Inputs 9246603fc5SJames Wright const CeedScalar(*J)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0]; 9346603fc5SJames Wright const CeedScalar(*w) = in[1]; 9446603fc5SJames Wright 9577841947SLeila Ghaffari // Outputs 9677841947SLeila Ghaffari CeedScalar(*q_data_sur)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0]; 9777841947SLeila Ghaffari 9877841947SLeila Ghaffari CeedPragmaSIMD 9977841947SLeila Ghaffari // Quadrature Point Loop 10077841947SLeila Ghaffari for (CeedInt i = 0; i < Q; i++) { 10177841947SLeila Ghaffari // Setup 10277841947SLeila Ghaffari const CeedScalar J1 = J[0][i]; 10377841947SLeila Ghaffari const CeedScalar J2 = J[1][i]; 10477841947SLeila Ghaffari 10577841947SLeila Ghaffari const CeedScalar detJb = sqrt(J1 * J1 + J2 * J2); 10677841947SLeila Ghaffari 10777841947SLeila Ghaffari q_data_sur[0][i] = w[i] * detJb; 10877841947SLeila Ghaffari q_data_sur[1][i] = J2 / detJb; 10977841947SLeila Ghaffari q_data_sur[2][i] = -J1 / detJb; 11077841947SLeila Ghaffari } // End of Quadrature Point Loop 11177841947SLeila Ghaffari 11277841947SLeila Ghaffari // Return 11377841947SLeila Ghaffari return 0; 11477841947SLeila Ghaffari } 11577841947SLeila Ghaffari 11677841947SLeila Ghaffari // ***************************************************************************** 11777841947SLeila Ghaffari 11877841947SLeila Ghaffari #endif // setup_geo_2d_h 119