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. 332d2ee49SValeria Barra // 43d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause 532d2ee49SValeria Barra // 63d8e8822SJeremy L Thompson // This file is part of CEED: http://github.com/ceed 732d2ee49SValeria Barra 832d2ee49SValeria Barra /// @file 932d2ee49SValeria Barra /// libCEED QFunctions for mass operator example for a scalar field on the sphere using PETSc 1032d2ee49SValeria Barra 11f6b55d2cSvaleriabarra #ifndef areasphere_h 12f6b55d2cSvaleriabarra #define areasphere_h 13f6b55d2cSvaleriabarra 14c9c2c079SJeremy L Thompson #include <ceed.h> 1532d2ee49SValeria Barra #include <math.h> 1632d2ee49SValeria Barra 17e83e87a5Sjeremylt // ----------------------------------------------------------------------------- 18*ea61e9acSJeremy L Thompson // This QFunction sets up the geometric factor required for integration when reference coordinates have a different dimension than the one of physical 19*ea61e9acSJeremy L Thompson // coordinates 2032d2ee49SValeria Barra // 2132d2ee49SValeria Barra // Reference (parent) 2D coordinates: X \in [-1, 1]^2 2232d2ee49SValeria Barra // 23*ea61e9acSJeremy L Thompson // Global 3D physical coordinates given by the mesh: xx \in [-R, R]^3 with R radius of the sphere 2432d2ee49SValeria Barra // 25*ea61e9acSJeremy L Thompson // Local 3D physical coordinates on the 2D manifold: x \in [-l, l]^3 with l half edge of the cube inscribed in the sphere 2632d2ee49SValeria Barra // 2732d2ee49SValeria Barra // Change of coordinates matrix computed by the library: 28ed264d09SValeria Barra // (physical 3D coords relative to reference 2D coords) 2932d2ee49SValeria Barra // dxx_j/dX_i (indicial notation) [3 * 2] 3032d2ee49SValeria Barra // 3132d2ee49SValeria Barra // Change of coordinates x (on the 2D manifold) relative to xx (phyisical 3D): 3232d2ee49SValeria Barra // dx_i/dxx_j (indicial notation) [3 * 3] 3332d2ee49SValeria Barra // 3432d2ee49SValeria Barra // Change of coordinates x (on the 2D manifold) relative to X (reference 2D): 3532d2ee49SValeria Barra // (by chain rule) 3632d2ee49SValeria Barra // dx_i/dX_j = dx_i/dxx_k * dxx_k/dX_j [3 * 2] 3732d2ee49SValeria Barra // 389b072555Sjeremylt // mod_J is given by the magnitude of the cross product of the columns of dx_i/dX_j 3932d2ee49SValeria Barra // 409b072555Sjeremylt // The quadrature data is stored in the array q_data. 4132d2ee49SValeria Barra // 42*ea61e9acSJeremy L Thompson // We require the determinant of the Jacobian to properly compute integrals of the form: int( u v ) 4332d2ee49SValeria Barra // 449b072555Sjeremylt // Qdata: mod_J * w 4532d2ee49SValeria Barra // ----------------------------------------------------------------------------- 462b730f8bSJeremy L Thompson CEED_QFUNCTION(SetupMassGeoSphere)(void *ctx, const CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 4732d2ee49SValeria Barra // Inputs 4832d2ee49SValeria Barra const CeedScalar *X = in[0], *J = in[1], *w = in[2]; 4932d2ee49SValeria Barra // Outputs 509b072555Sjeremylt CeedScalar *q_data = out[0]; 5132d2ee49SValeria Barra 5232d2ee49SValeria Barra // Quadrature Point Loop 532b730f8bSJeremy L Thompson CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 5432d2ee49SValeria Barra // Read global Cartesian coordinates 552b730f8bSJeremy L Thompson const CeedScalar xx[3][1] = {{X[i + 0 * Q]}, {X[i + 1 * Q]}, {X[i + 2 * Q]}}; 5632d2ee49SValeria Barra 5732d2ee49SValeria Barra // Read dxxdX Jacobian entries, stored as 5832d2ee49SValeria Barra // 0 3 5932d2ee49SValeria Barra // 1 4 6032d2ee49SValeria Barra // 2 5 612b730f8bSJeremy L Thompson const CeedScalar dxxdX[3][2] = { 622b730f8bSJeremy L Thompson {J[i + Q * 0], J[i + Q * 3]}, 632b730f8bSJeremy L Thompson {J[i + Q * 1], J[i + Q * 4]}, 642b730f8bSJeremy L Thompson {J[i + Q * 2], J[i + Q * 5]} 6532d2ee49SValeria Barra }; 6632d2ee49SValeria Barra 6732d2ee49SValeria Barra // Setup 689b072555Sjeremylt const CeedScalar mod_xx_sq = xx[0][0] * xx[0][0] + xx[1][0] * xx[1][0] + xx[2][0] * xx[2][0]; 699b072555Sjeremylt CeedScalar xx_sq[3][3]; 702b730f8bSJeremy L Thompson for (int j = 0; j < 3; j++) { 7132d2ee49SValeria Barra for (int k = 0; k < 3; k++) { 729b072555Sjeremylt xx_sq[j][k] = 0; 732b730f8bSJeremy L Thompson for (int l = 0; l < 1; l++) xx_sq[j][k] += xx[j][l] * xx[k][l] / (sqrt(mod_xx_sq) * mod_xx_sq); 742b730f8bSJeremy L Thompson } 7532d2ee49SValeria Barra } 7632d2ee49SValeria Barra 772b730f8bSJeremy L Thompson const CeedScalar dxdxx[3][3] = { 782b730f8bSJeremy L Thompson {1. / sqrt(mod_xx_sq) - xx_sq[0][0], -xx_sq[0][1], -xx_sq[0][2] }, 792b730f8bSJeremy L Thompson {-xx_sq[1][0], 1. / sqrt(mod_xx_sq) - xx_sq[1][1], -xx_sq[1][2] }, 802b730f8bSJeremy L Thompson {-xx_sq[2][0], -xx_sq[2][1], 1. / sqrt(mod_xx_sq) - xx_sq[2][2]} 8132d2ee49SValeria Barra }; 8232d2ee49SValeria Barra 8332d2ee49SValeria Barra CeedScalar dxdX[3][2]; 842b730f8bSJeremy L Thompson for (int j = 0; j < 3; j++) { 8532d2ee49SValeria Barra for (int k = 0; k < 2; k++) { 8632d2ee49SValeria Barra dxdX[j][k] = 0; 872b730f8bSJeremy L Thompson for (int l = 0; l < 3; l++) dxdX[j][k] += dxdxx[j][l] * dxxdX[l][k]; 882b730f8bSJeremy L Thompson } 8932d2ee49SValeria Barra } 9032d2ee49SValeria Barra 9132d2ee49SValeria Barra // J is given by the cross product of the columns of dxdX 9232d2ee49SValeria Barra const CeedScalar J[3][1] = {{dxdX[1][0] * dxdX[2][1] - dxdX[2][0] * dxdX[1][1]}, 9332d2ee49SValeria Barra {dxdX[2][0] * dxdX[0][1] - dxdX[0][0] * dxdX[2][1]}, 942b730f8bSJeremy L Thompson {dxdX[0][0] * dxdX[1][1] - dxdX[1][0] * dxdX[0][1]}}; 9532d2ee49SValeria Barra // Use the magnitude of J as our detJ (volume scaling factor) 969b072555Sjeremylt const CeedScalar mod_J = sqrt(J[0][0] * J[0][0] + J[1][0] * J[1][0] + J[2][0] * J[2][0]); 979b072555Sjeremylt q_data[i + Q * 0] = mod_J * w[i]; 9832d2ee49SValeria Barra } // End of Quadrature Point Loop 9932d2ee49SValeria Barra return 0; 10032d2ee49SValeria Barra } 10132d2ee49SValeria Barra // ----------------------------------------------------------------------------- 102f6b55d2cSvaleriabarra 103f6b55d2cSvaleriabarra #endif // areasphere_h 104