1*8756a6ccSJames Wright // Copyright (c) 2017-2023, 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 17*8756a6ccSJames Wright #include "setupgeo_helpers.h" 18*8756a6ccSJames Wright 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*A11 + J21*A12 + J31*A13 3377841947SLeila Ghaffari // Jij = Jacobian entry ij 34*8756a6ccSJames Wright // Aij = Adjugate ij 3577841947SLeila Ghaffari // 3677841947SLeila Ghaffari // Stored: w detJ 3777841947SLeila Ghaffari // in q_data[0] 3877841947SLeila Ghaffari // 39ea61e9acSJeremy L Thompson // We require the transpose of the inverse of the Jacobian to properly compute integrals of the form: int( gradv u ) 4077841947SLeila Ghaffari // 4177841947SLeila Ghaffari // Inverse of Jacobian: 4277841947SLeila Ghaffari // dXdx_i,j = Aij / detJ 4377841947SLeila Ghaffari // 4477841947SLeila Ghaffari // Stored: Aij / detJ 4577841947SLeila Ghaffari // in q_data[1:9] as 4677841947SLeila Ghaffari // (detJ^-1) * [A11 A12 A13] 4777841947SLeila Ghaffari // [A21 A22 A23] 4877841947SLeila Ghaffari // [A31 A32 A33] 4977841947SLeila Ghaffari // ***************************************************************************** 502b730f8bSJeremy L Thompson CEED_QFUNCTION(Setup)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 5146603fc5SJames Wright const CeedScalar(*J)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[0]; 5246603fc5SJames Wright const CeedScalar(*w) = in[1]; 5377841947SLeila Ghaffari CeedScalar(*q_data)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0]; 5477841947SLeila Ghaffari 55*8756a6ccSJames Wright CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 56*8756a6ccSJames Wright CeedScalar detJ, dXdx[3][3]; 57*8756a6ccSJames Wright InvertMappingJacobian_3D(Q, i, J, dXdx, &detJ); 5877841947SLeila Ghaffari q_data[0][i] = w[i] * detJ; 59*8756a6ccSJames Wright q_data[1][i] = dXdx[0][0]; 60*8756a6ccSJames Wright q_data[2][i] = dXdx[0][1]; 61*8756a6ccSJames Wright q_data[3][i] = dXdx[0][2]; 62*8756a6ccSJames Wright q_data[4][i] = dXdx[1][0]; 63*8756a6ccSJames Wright q_data[5][i] = dXdx[1][1]; 64*8756a6ccSJames Wright q_data[6][i] = dXdx[1][2]; 65*8756a6ccSJames Wright q_data[7][i] = dXdx[2][0]; 66*8756a6ccSJames Wright q_data[8][i] = dXdx[2][1]; 67*8756a6ccSJames Wright q_data[9][i] = dXdx[2][2]; 68*8756a6ccSJames Wright } 6977841947SLeila Ghaffari return 0; 7077841947SLeila Ghaffari } 7177841947SLeila Ghaffari 7277841947SLeila Ghaffari // ***************************************************************************** 73ea61e9acSJeremy 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 7477841947SLeila Ghaffari // 7577841947SLeila Ghaffari // Reference (parent) 2D coordinates: X 7677841947SLeila Ghaffari // Physical (current) 3D coordinates: x 7777841947SLeila Ghaffari // Change of coordinate matrix: 7877841947SLeila Ghaffari // dxdX_{i,j} = dx_i/dX_j (indicial notation) [3 * 2] 79ba6664aeSJames Wright // Inverse change of coordinate matrix: 80ba6664aeSJames Wright // dXdx_{i,j} = dX_i/dx_j (indicial notation) [2 * 3] 8177841947SLeila Ghaffari // 8277841947SLeila Ghaffari // (J1,J2,J3) is given by the cross product of the columns of dxdX_{i,j} 8377841947SLeila Ghaffari // 8477841947SLeila Ghaffari // detJb is the magnitude of (J1,J2,J3) 8577841947SLeila Ghaffari // 86ba6664aeSJames Wright // dXdx is calculated via Moore–Penrose inverse: 87ba6664aeSJames Wright // 88ba6664aeSJames Wright // dX_i/dx_j = (dxdX^T dxdX)^(-1) dxdX 89ba6664aeSJames Wright // = (dx_l/dX_i * dx_l/dX_k)^(-1) dx_j/dX_k 90ba6664aeSJames Wright // 91ba6664aeSJames Wright // All quadrature data is stored in 10 field vector of quadrature data. 9277841947SLeila Ghaffari // 9377841947SLeila Ghaffari // We require the determinant of the Jacobian to properly compute integrals of 9477841947SLeila Ghaffari // the form: int( u v ) 9577841947SLeila Ghaffari // 9677841947SLeila Ghaffari // Stored: w detJb 9777841947SLeila Ghaffari // in q_data_sur[0] 9877841947SLeila Ghaffari // 9977841947SLeila Ghaffari // Normal vector = (J1,J2,J3) / detJb 10077841947SLeila Ghaffari // 101ba6664aeSJames Wright // - TODO Could possibly remove normal vector, as it could be calculated in the Qfunction from dXdx 102*8756a6ccSJames Wright // See https://github.com/CEED/libCEED/pull/868#discussion_r871979484 10377841947SLeila Ghaffari // Stored: (J1,J2,J3) / detJb 10477841947SLeila Ghaffari // in q_data_sur[1:3] as 10577841947SLeila Ghaffari // (detJb^-1) * [ J1 ] 10677841947SLeila Ghaffari // [ J2 ] 10777841947SLeila Ghaffari // [ J3 ] 10877841947SLeila Ghaffari // 109ba6664aeSJames Wright // Stored: dXdx_{i,j} 110ba6664aeSJames Wright // in q_data_sur[4:9] as 111ba6664aeSJames Wright // [dXdx_11 dXdx_12 dXdx_13] 112ba6664aeSJames Wright // [dXdx_21 dXdx_22 dXdx_23] 11377841947SLeila Ghaffari // ***************************************************************************** 1142b730f8bSJeremy L Thompson CEED_QFUNCTION(SetupBoundary)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 11546603fc5SJames Wright const CeedScalar(*J)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[0]; 11646603fc5SJames Wright const CeedScalar(*w) = in[1]; 11777841947SLeila Ghaffari CeedScalar(*q_data_sur)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0]; 11877841947SLeila Ghaffari 119*8756a6ccSJames Wright CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 120*8756a6ccSJames Wright CeedScalar detJb, normal[3], dXdx[2][3]; 12177841947SLeila Ghaffari 122*8756a6ccSJames Wright NormalVectorFromdxdX_3D(Q, i, J, normal, &detJb); 12377841947SLeila Ghaffari q_data_sur[0][i] = w[i] * detJb; 124*8756a6ccSJames Wright q_data_sur[1][i] = normal[0]; 125*8756a6ccSJames Wright q_data_sur[2][i] = normal[1]; 126*8756a6ccSJames Wright q_data_sur[3][i] = normal[2]; 12777841947SLeila Ghaffari 128*8756a6ccSJames Wright InvertBoundaryMappingJacobian_3D(Q, i, J, dXdx); 129ba6664aeSJames Wright q_data_sur[4][i] = dXdx[0][0]; 130ba6664aeSJames Wright q_data_sur[5][i] = dXdx[0][1]; 131ba6664aeSJames Wright q_data_sur[6][i] = dXdx[0][2]; 132ba6664aeSJames Wright q_data_sur[7][i] = dXdx[1][0]; 133ba6664aeSJames Wright q_data_sur[8][i] = dXdx[1][1]; 134ba6664aeSJames Wright q_data_sur[9][i] = dXdx[1][2]; 135*8756a6ccSJames Wright } 13677841947SLeila Ghaffari return 0; 13777841947SLeila Ghaffari } 13877841947SLeila Ghaffari 13977841947SLeila Ghaffari // ***************************************************************************** 14077841947SLeila Ghaffari 14177841947SLeila Ghaffari #endif // setup_geo_h 142