1*5aed82e4SJeremy 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 1077841947SLeila Ghaffari 1177841947SLeila Ghaffari #ifndef setup_geo_h 1277841947SLeila Ghaffari #define setup_geo_h 1377841947SLeila Ghaffari 1488b783a1SJames Wright #include <ceed.h> 15c9c2c079SJeremy L Thompson #include <math.h> 1677841947SLeila Ghaffari 178756a6ccSJames Wright #include "setupgeo_helpers.h" 18f3e15844SJames Wright #include "utils.h" 198756a6ccSJames Wright 2077841947SLeila Ghaffari // ***************************************************************************** 21ea61e9acSJeremy L Thompson // This QFunction sets up the geometric factors required for integration and coordinate transformations 2277841947SLeila Ghaffari // 2377841947SLeila Ghaffari // Reference (parent) coordinates: X 2477841947SLeila Ghaffari // Physical (current) coordinates: x 2577841947SLeila Ghaffari // Change of coordinate matrix: dxdX_{i,j} = x_{i,j} (indicial notation) 2677841947SLeila Ghaffari // Inverse of change of coordinate matrix: dXdx_{i,j} = (detJ^-1) * X_{i,j} 2777841947SLeila Ghaffari // 2877841947SLeila Ghaffari // All quadrature data is stored in 10 field vector of quadrature data. 2977841947SLeila Ghaffari // 30ea61e9acSJeremy L Thompson // We require the determinant of the Jacobian to properly compute integrals of the form: int( v u ) 3177841947SLeila Ghaffari // 3277841947SLeila Ghaffari // Determinant of Jacobian: 3377841947SLeila Ghaffari // detJ = J11*A11 + J21*A12 + J31*A13 3477841947SLeila Ghaffari // Jij = Jacobian entry ij 358756a6ccSJames Wright // Aij = Adjugate ij 3677841947SLeila Ghaffari // 3777841947SLeila Ghaffari // Stored: w detJ 3877841947SLeila Ghaffari // in q_data[0] 3977841947SLeila Ghaffari // 40ea61e9acSJeremy L Thompson // We require the transpose of the inverse of the Jacobian to properly compute integrals of the form: int( gradv u ) 4177841947SLeila Ghaffari // 4277841947SLeila Ghaffari // Inverse of Jacobian: 4377841947SLeila Ghaffari // dXdx_i,j = Aij / detJ 4477841947SLeila Ghaffari // 4577841947SLeila Ghaffari // Stored: Aij / detJ 4677841947SLeila Ghaffari // in q_data[1:9] as 4777841947SLeila Ghaffari // (detJ^-1) * [A11 A12 A13] 4877841947SLeila Ghaffari // [A21 A22 A23] 4977841947SLeila Ghaffari // [A31 A32 A33] 5077841947SLeila Ghaffari // ***************************************************************************** 512b730f8bSJeremy L Thompson CEED_QFUNCTION(Setup)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 5246603fc5SJames Wright const CeedScalar(*J)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[0]; 5346603fc5SJames Wright const CeedScalar(*w) = in[1]; 54f3e15844SJames Wright CeedScalar(*q_data) = out[0]; 5577841947SLeila Ghaffari 568756a6ccSJames Wright CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 578756a6ccSJames Wright CeedScalar detJ, dXdx[3][3]; 588756a6ccSJames Wright InvertMappingJacobian_3D(Q, i, J, dXdx, &detJ); 59f3e15844SJames Wright const CeedScalar wdetJ = w[i] * detJ; 60f3e15844SJames Wright 61f3e15844SJames Wright StoredValuesPack(Q, i, 0, 1, &wdetJ, q_data); 62f3e15844SJames Wright StoredValuesPack(Q, i, 1, 9, (const CeedScalar *)dXdx, q_data); 638756a6ccSJames Wright } 6477841947SLeila Ghaffari return 0; 6577841947SLeila Ghaffari } 6677841947SLeila Ghaffari 6777841947SLeila Ghaffari // ***************************************************************************** 68ea61e9acSJeremy 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 6977841947SLeila Ghaffari // 7077841947SLeila Ghaffari // Reference (parent) 2D coordinates: X 7177841947SLeila Ghaffari // Physical (current) 3D coordinates: x 7277841947SLeila Ghaffari // Change of coordinate matrix: 7377841947SLeila Ghaffari // dxdX_{i,j} = dx_i/dX_j (indicial notation) [3 * 2] 74ba6664aeSJames Wright // Inverse change of coordinate matrix: 75ba6664aeSJames Wright // dXdx_{i,j} = dX_i/dx_j (indicial notation) [2 * 3] 7677841947SLeila Ghaffari // 7777841947SLeila Ghaffari // (J1,J2,J3) is given by the cross product of the columns of dxdX_{i,j} 7877841947SLeila Ghaffari // 7977841947SLeila Ghaffari // detJb is the magnitude of (J1,J2,J3) 8077841947SLeila Ghaffari // 81ba6664aeSJames Wright // dXdx is calculated via Moore–Penrose inverse: 82ba6664aeSJames Wright // 83ba6664aeSJames Wright // dX_i/dx_j = (dxdX^T dxdX)^(-1) dxdX 84ba6664aeSJames Wright // = (dx_l/dX_i * dx_l/dX_k)^(-1) dx_j/dX_k 85ba6664aeSJames Wright // 86ba6664aeSJames Wright // All quadrature data is stored in 10 field vector of quadrature data. 8777841947SLeila Ghaffari // 8877841947SLeila Ghaffari // We require the determinant of the Jacobian to properly compute integrals of 8977841947SLeila Ghaffari // the form: int( u v ) 9077841947SLeila Ghaffari // 9177841947SLeila Ghaffari // Stored: w detJb 9277841947SLeila Ghaffari // in q_data_sur[0] 9377841947SLeila Ghaffari // 9477841947SLeila Ghaffari // Normal vector = (J1,J2,J3) / detJb 9577841947SLeila Ghaffari // 96ba6664aeSJames Wright // - TODO Could possibly remove normal vector, as it could be calculated in the Qfunction from dXdx 978756a6ccSJames Wright // See https://github.com/CEED/libCEED/pull/868#discussion_r871979484 9877841947SLeila Ghaffari // Stored: (J1,J2,J3) / detJb 9977841947SLeila Ghaffari // in q_data_sur[1:3] as 10077841947SLeila Ghaffari // (detJb^-1) * [ J1 ] 10177841947SLeila Ghaffari // [ J2 ] 10277841947SLeila Ghaffari // [ J3 ] 10377841947SLeila Ghaffari // 104ba6664aeSJames Wright // Stored: dXdx_{i,j} 105ba6664aeSJames Wright // in q_data_sur[4:9] as 106ba6664aeSJames Wright // [dXdx_11 dXdx_12 dXdx_13] 107ba6664aeSJames Wright // [dXdx_21 dXdx_22 dXdx_23] 10877841947SLeila Ghaffari // ***************************************************************************** 1092b730f8bSJeremy L Thompson CEED_QFUNCTION(SetupBoundary)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 11046603fc5SJames Wright const CeedScalar(*J)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[0]; 11146603fc5SJames Wright const CeedScalar(*w) = in[1]; 112f3e15844SJames Wright CeedScalar(*q_data_sur) = out[0]; 11377841947SLeila Ghaffari 1148756a6ccSJames Wright CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 1158756a6ccSJames Wright CeedScalar detJb, normal[3], dXdx[2][3]; 11677841947SLeila Ghaffari 1178756a6ccSJames Wright NormalVectorFromdxdX_3D(Q, i, J, normal, &detJb); 1188756a6ccSJames Wright InvertBoundaryMappingJacobian_3D(Q, i, J, dXdx); 119f3e15844SJames Wright const CeedScalar wdetJ = w[i] * detJb; 120f3e15844SJames Wright 121f3e15844SJames Wright StoredValuesPack(Q, i, 0, 1, &wdetJ, q_data_sur); 122f3e15844SJames Wright StoredValuesPack(Q, i, 1, 3, normal, q_data_sur); 123f3e15844SJames Wright StoredValuesPack(Q, i, 4, 6, (const CeedScalar *)dXdx, q_data_sur); 1248756a6ccSJames Wright } 12577841947SLeila Ghaffari return 0; 12677841947SLeila Ghaffari } 12777841947SLeila Ghaffari 12877841947SLeila Ghaffari // ***************************************************************************** 12977841947SLeila Ghaffari 13077841947SLeila Ghaffari #endif // setup_geo_h 131