15aed82e4SJeremy 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 10*c0b5abf0SJeremy L Thompson #include <ceed/types.h> 11*c0b5abf0SJeremy L Thompson 12bf415d3fSJames Wright #include "setupgeo_helpers.h" 13bf415d3fSJames Wright #include "utils.h" 1477841947SLeila Ghaffari 1577841947SLeila Ghaffari // ***************************************************************************** 16ea61e9acSJeremy L Thompson // This QFunction sets up the geometric factors required for integration and coordinate transformations 1777841947SLeila Ghaffari // 1877841947SLeila Ghaffari // Reference (parent) coordinates: X 1977841947SLeila Ghaffari // Physical (current) coordinates: x 2077841947SLeila Ghaffari // Change of coordinate matrix: dxdX_{i,j} = x_{i,j} (indicial notation) 2177841947SLeila Ghaffari // Inverse of change of coordinate matrix: dXdx_{i,j} = (detJ^-1) * X_{i,j} 2277841947SLeila Ghaffari // 2377841947SLeila Ghaffari // All quadrature data is stored in 10 field vector of quadrature data. 2477841947SLeila Ghaffari // 25ea61e9acSJeremy L Thompson // We require the determinant of the Jacobian to properly compute integrals of the form: int( v u ) 2677841947SLeila Ghaffari // 2777841947SLeila Ghaffari // Determinant of Jacobian: 2877841947SLeila Ghaffari // detJ = J11*J22 - J21*J12 2977841947SLeila Ghaffari // Jij = Jacobian entry ij 3077841947SLeila Ghaffari // 3177841947SLeila Ghaffari // Stored: w detJ 3277841947SLeila Ghaffari // in q_data[0] 3377841947SLeila Ghaffari // 34ea61e9acSJeremy L Thompson // We require the transpose of the inverse of the Jacobian to properly compute integrals of the form: int( gradv u ) 3577841947SLeila Ghaffari // 3677841947SLeila Ghaffari // Inverse of Jacobian: 3777841947SLeila Ghaffari // dXdx_i,j = Aij / detJ 38bf415d3fSJames Wright // Aij = Adjugate ij 3977841947SLeila Ghaffari // 4077841947SLeila Ghaffari // Stored: Aij / detJ 4177841947SLeila Ghaffari // in q_data[1:4] as 4277841947SLeila Ghaffari // (detJ^-1) * [A11 A12] 4377841947SLeila Ghaffari // [A21 A22] 4477841947SLeila Ghaffari // ***************************************************************************** 452b730f8bSJeremy L Thompson CEED_QFUNCTION(Setup2d)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 4646603fc5SJames Wright const CeedScalar(*J)[2][CEED_Q_VLA] = (const CeedScalar(*)[2][CEED_Q_VLA])in[0]; 4746603fc5SJames Wright const CeedScalar(*w) = in[1]; 48bf415d3fSJames Wright CeedScalar(*q_data) = out[0]; 4946603fc5SJames Wright 50bf415d3fSJames Wright CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 51bf415d3fSJames Wright CeedScalar dXdx[2][2], detJ; 52bf415d3fSJames Wright InvertMappingJacobian_2D(Q, i, J, dXdx, &detJ); 53bf415d3fSJames Wright const CeedScalar wdetJ = w[i] * detJ; 5477841947SLeila Ghaffari 55bf415d3fSJames Wright StoredValuesPack(Q, i, 0, 1, &wdetJ, q_data); 56bf415d3fSJames Wright StoredValuesPack(Q, i, 1, 4, (const CeedScalar *)dXdx, q_data); 57bf415d3fSJames Wright } 5877841947SLeila Ghaffari return 0; 5977841947SLeila Ghaffari } 6077841947SLeila Ghaffari 6177841947SLeila Ghaffari // ***************************************************************************** 62ea61e9acSJeremy 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 6377841947SLeila Ghaffari // 6477841947SLeila Ghaffari // Reference (parent) 1D coordinates: X 6577841947SLeila Ghaffari // Physical (current) 2D coordinates: x 6677841947SLeila Ghaffari // Change of coordinate vector: 6777841947SLeila Ghaffari // J1 = dx_1/dX 6877841947SLeila Ghaffari // J2 = dx_2/dX 6977841947SLeila Ghaffari // 7077841947SLeila Ghaffari // detJb is the magnitude of (J1,J2) 7177841947SLeila Ghaffari // 7277841947SLeila Ghaffari // All quadrature data is stored in 3 field vector of quadrature data. 7377841947SLeila Ghaffari // 74ea61e9acSJeremy L Thompson // We require the determinant of the Jacobian to properly compute integrals of the form: int( u v ) 7577841947SLeila Ghaffari // 7677841947SLeila Ghaffari // Stored: w detJb 7777841947SLeila Ghaffari // in q_data_sur[0] 7877841947SLeila Ghaffari // 7977841947SLeila Ghaffari // Normal vector is given by the cross product of (J1,J2)/detJ and ẑ 8077841947SLeila Ghaffari // 8177841947SLeila Ghaffari // Stored: (J1,J2,0) x (0,0,1) / detJb 8277841947SLeila Ghaffari // in q_data_sur[1:2] as 8377841947SLeila Ghaffari // (detJb^-1) * [ J2 ] 8477841947SLeila Ghaffari // [-J1 ] 8577841947SLeila Ghaffari // ***************************************************************************** 862b730f8bSJeremy L Thompson CEED_QFUNCTION(SetupBoundary2d)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 8746603fc5SJames Wright const CeedScalar(*J)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0]; 8846603fc5SJames Wright const CeedScalar(*w) = in[1]; 891394d07eSJames Wright CeedScalar(*q_data_sur) = out[0]; 9046603fc5SJames Wright 911394d07eSJames Wright CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 921394d07eSJames Wright CeedScalar normal[2], detJb; 931394d07eSJames Wright NormalVectorFromdxdX_2D(Q, i, J, normal, &detJb); 941394d07eSJames Wright const CeedScalar wdetJ = w[i] * detJb; 9577841947SLeila Ghaffari 961394d07eSJames Wright StoredValuesPack(Q, i, 0, 1, &wdetJ, q_data_sur); 971394d07eSJames Wright StoredValuesPack(Q, i, 1, 2, normal, q_data_sur); 981394d07eSJames Wright } 9977841947SLeila Ghaffari return 0; 10077841947SLeila Ghaffari } 101cfb075a4SJames Wright 102cfb075a4SJames Wright // ***************************************************************************** 103cfb075a4SJames Wright // This QFunction sets up the geometric factor required for integration when reference coordinates are in 2D and the physical coordinates are in 3D 104cfb075a4SJames Wright // 105cfb075a4SJames Wright // Reference (parent) 2D coordinates: X 106cfb075a4SJames Wright // Physical (current) 3D coordinates: x 107cfb075a4SJames Wright // Change of coordinate matrix: 108cfb075a4SJames Wright // dxdX_{i,j} = dx_i/dX_j (indicial notation) [3 * 2] 109cfb075a4SJames Wright // Inverse change of coordinate matrix: 110cfb075a4SJames Wright // dXdx_{i,j} = dX_i/dx_j (indicial notation) [2 * 3] 111cfb075a4SJames Wright // 112cfb075a4SJames Wright // (J1,J2,J3) is given by the cross product of the columns of dxdX_{i,j} 113cfb075a4SJames Wright // 114cfb075a4SJames Wright // detJb is the magnitude of (J1,J2,J3) 115cfb075a4SJames Wright // 116cfb075a4SJames Wright // dXdx is calculated via Moore–Penrose inverse: 117cfb075a4SJames Wright // 118cfb075a4SJames Wright // dX_i/dx_j = (dxdX^T dxdX)^(-1) dxdX 119cfb075a4SJames Wright // = (dx_l/dX_i * dx_l/dX_k)^(-1) dx_j/dX_k 120cfb075a4SJames Wright // 121cfb075a4SJames Wright // All quadrature data is stored in 10 field vector of quadrature data. 122cfb075a4SJames Wright // 123cfb075a4SJames Wright // We require the determinant of the Jacobian to properly compute integrals of 124cfb075a4SJames Wright // the form: int( u v ) 125cfb075a4SJames Wright // 126cfb075a4SJames Wright // Stored: w detJb 127cfb075a4SJames Wright // in q_data_sur[0] 128cfb075a4SJames Wright // 129cfb075a4SJames Wright // Normal vector = (J1,J2,J3) / detJb 130cfb075a4SJames Wright // 131cfb075a4SJames Wright // Stored: (J1,J2,J3) / detJb 132cfb075a4SJames Wright // 133cfb075a4SJames Wright // Stored: dXdx_{i,j} 134cfb075a4SJames Wright // in q_data_sur[1:6] as 135cfb075a4SJames Wright // [dXdx_11 dXdx_12 dXdx_13] 136cfb075a4SJames Wright // [dXdx_21 dXdx_22 dXdx_23] 137cfb075a4SJames Wright // ***************************************************************************** 138cfb075a4SJames Wright CEED_QFUNCTION(Setup2D_3Dcoords)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 139cfb075a4SJames Wright const CeedScalar(*J)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[0]; 140cfb075a4SJames Wright const CeedScalar(*w) = in[1]; 141cfb075a4SJames Wright CeedScalar(*q_data_sur) = out[0]; 142cfb075a4SJames Wright 143cfb075a4SJames Wright CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 144cfb075a4SJames Wright CeedScalar detJb, normal[3], dXdx[2][3]; 145cfb075a4SJames Wright 146cfb075a4SJames Wright NormalVectorFromdxdX_3D(Q, i, J, normal, &detJb); 147cfb075a4SJames Wright InvertBoundaryMappingJacobian_3D(Q, i, J, dXdx); 148cfb075a4SJames Wright const CeedScalar wdetJ = w[i] * detJb; 149cfb075a4SJames Wright 150cfb075a4SJames Wright StoredValuesPack(Q, i, 0, 1, &wdetJ, q_data_sur); 151cfb075a4SJames Wright StoredValuesPack(Q, i, 1, 6, (const CeedScalar *)dXdx, q_data_sur); 152cfb075a4SJames Wright } 153cfb075a4SJames Wright return 0; 154cfb075a4SJames Wright } 155