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 (3D) for Navier-Stokes example using PETSc 10*c0b5abf0SJeremy L Thompson #include <ceed/types.h> 11*c0b5abf0SJeremy L Thompson #ifndef CEED_RUNNING_JIT_PASS 12c9c2c079SJeremy L Thompson #include <math.h> 13*c0b5abf0SJeremy L Thompson #endif 1477841947SLeila Ghaffari 158756a6ccSJames Wright #include "setupgeo_helpers.h" 16f3e15844SJames Wright #include "utils.h" 178756a6ccSJames Wright 1877841947SLeila Ghaffari // ***************************************************************************** 19ea61e9acSJeremy L Thompson // This QFunction sets up the geometric factors required for integration and 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 // 28ea61e9acSJeremy L Thompson // We require the determinant of the Jacobian to properly compute integrals of the form: int( v u ) 2977841947SLeila Ghaffari // 3077841947SLeila Ghaffari // Determinant of Jacobian: 3177841947SLeila Ghaffari // detJ = J11*A11 + J21*A12 + J31*A13 3277841947SLeila Ghaffari // Jij = Jacobian entry ij 338756a6ccSJames Wright // Aij = Adjugate 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 4277841947SLeila Ghaffari // 4377841947SLeila Ghaffari // Stored: Aij / detJ 4477841947SLeila Ghaffari // in q_data[1:9] as 4577841947SLeila Ghaffari // (detJ^-1) * [A11 A12 A13] 4677841947SLeila Ghaffari // [A21 A22 A23] 4777841947SLeila Ghaffari // [A31 A32 A33] 4877841947SLeila Ghaffari // ***************************************************************************** 492b730f8bSJeremy L Thompson CEED_QFUNCTION(Setup)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 5046603fc5SJames Wright const CeedScalar(*J)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[0]; 5146603fc5SJames Wright const CeedScalar(*w) = in[1]; 52f3e15844SJames Wright CeedScalar(*q_data) = out[0]; 5377841947SLeila Ghaffari 548756a6ccSJames Wright CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 558756a6ccSJames Wright CeedScalar detJ, dXdx[3][3]; 568756a6ccSJames Wright InvertMappingJacobian_3D(Q, i, J, dXdx, &detJ); 57f3e15844SJames Wright const CeedScalar wdetJ = w[i] * detJ; 58f3e15844SJames Wright 59f3e15844SJames Wright StoredValuesPack(Q, i, 0, 1, &wdetJ, q_data); 60f3e15844SJames Wright StoredValuesPack(Q, i, 1, 9, (const CeedScalar *)dXdx, q_data); 618756a6ccSJames 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 2D and the physical coordinates are in 3D 6777841947SLeila Ghaffari // 6877841947SLeila Ghaffari // Reference (parent) 2D coordinates: X 6977841947SLeila Ghaffari // Physical (current) 3D coordinates: x 7077841947SLeila Ghaffari // Change of coordinate matrix: 7177841947SLeila Ghaffari // dxdX_{i,j} = dx_i/dX_j (indicial notation) [3 * 2] 72ba6664aeSJames Wright // Inverse change of coordinate matrix: 73ba6664aeSJames Wright // dXdx_{i,j} = dX_i/dx_j (indicial notation) [2 * 3] 7477841947SLeila Ghaffari // 7577841947SLeila Ghaffari // (J1,J2,J3) is given by the cross product of the columns of dxdX_{i,j} 7677841947SLeila Ghaffari // 7777841947SLeila Ghaffari // detJb is the magnitude of (J1,J2,J3) 7877841947SLeila Ghaffari // 79ba6664aeSJames Wright // dXdx is calculated via Moore–Penrose inverse: 80ba6664aeSJames Wright // 81ba6664aeSJames Wright // dX_i/dx_j = (dxdX^T dxdX)^(-1) dxdX 82ba6664aeSJames Wright // = (dx_l/dX_i * dx_l/dX_k)^(-1) dx_j/dX_k 83ba6664aeSJames Wright // 84ba6664aeSJames Wright // All quadrature data is stored in 10 field vector of quadrature data. 8577841947SLeila Ghaffari // 8677841947SLeila Ghaffari // We require the determinant of the Jacobian to properly compute integrals of 8777841947SLeila Ghaffari // the form: int( u v ) 8877841947SLeila Ghaffari // 8977841947SLeila Ghaffari // Stored: w detJb 9077841947SLeila Ghaffari // in q_data_sur[0] 9177841947SLeila Ghaffari // 9277841947SLeila Ghaffari // Normal vector = (J1,J2,J3) / detJb 9377841947SLeila Ghaffari // 94ba6664aeSJames Wright // - TODO Could possibly remove normal vector, as it could be calculated in the Qfunction from dXdx 958756a6ccSJames Wright // See https://github.com/CEED/libCEED/pull/868#discussion_r871979484 9677841947SLeila Ghaffari // Stored: (J1,J2,J3) / detJb 9777841947SLeila Ghaffari // in q_data_sur[1:3] as 9877841947SLeila Ghaffari // (detJb^-1) * [ J1 ] 9977841947SLeila Ghaffari // [ J2 ] 10077841947SLeila Ghaffari // [ J3 ] 10177841947SLeila Ghaffari // 102ba6664aeSJames Wright // Stored: dXdx_{i,j} 103ba6664aeSJames Wright // in q_data_sur[4:9] as 104ba6664aeSJames Wright // [dXdx_11 dXdx_12 dXdx_13] 105ba6664aeSJames Wright // [dXdx_21 dXdx_22 dXdx_23] 10677841947SLeila Ghaffari // ***************************************************************************** 1072b730f8bSJeremy L Thompson CEED_QFUNCTION(SetupBoundary)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 10846603fc5SJames Wright const CeedScalar(*J)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[0]; 10946603fc5SJames Wright const CeedScalar(*w) = in[1]; 110f3e15844SJames Wright CeedScalar(*q_data_sur) = out[0]; 11177841947SLeila Ghaffari 1128756a6ccSJames Wright CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 1138756a6ccSJames Wright CeedScalar detJb, normal[3], dXdx[2][3]; 11477841947SLeila Ghaffari 1158756a6ccSJames Wright NormalVectorFromdxdX_3D(Q, i, J, normal, &detJb); 1168756a6ccSJames Wright InvertBoundaryMappingJacobian_3D(Q, i, J, dXdx); 117f3e15844SJames Wright const CeedScalar wdetJ = w[i] * detJb; 118f3e15844SJames Wright 119f3e15844SJames Wright StoredValuesPack(Q, i, 0, 1, &wdetJ, q_data_sur); 120f3e15844SJames Wright StoredValuesPack(Q, i, 1, 3, normal, q_data_sur); 121f3e15844SJames Wright StoredValuesPack(Q, i, 4, 6, (const CeedScalar *)dXdx, q_data_sur); 1228756a6ccSJames Wright } 12377841947SLeila Ghaffari return 0; 12477841947SLeila Ghaffari } 125