1 // Copyright (c) 2017-2024, Lawrence Livermore National Security, LLC and other CEED contributors. 2 // All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 3 // 4 // SPDX-License-Identifier: BSD-2-Clause 5 // 6 // This file is part of CEED: http://github.com/ceed 7 8 /// @file 9 /// libCEED QFunctions for mass operator example for a scalar field on the sphere using PETSc 10 11 #include <ceed.h> 12 #include <math.h> 13 14 // ----------------------------------------------------------------------------- 15 // This QFunction sets up the geometric factor required for integration when reference coordinates have a different dimension than the one of physical 16 // coordinates 17 // 18 // Reference (parent) 2D coordinates: X \in [-1, 1]^2 19 // 20 // Global physical coordinates given by the mesh (3D): xx \in [-l, l]^3 21 // 22 // Local physical coordinates on the manifold (2D): x \in [-l, l]^2 23 // 24 // Change of coordinates matrix computed by the library: 25 // (physical 3D coords relative to reference 2D coords) 26 // dxx_j/dX_i (indicial notation) [3 * 2] 27 // 28 // Change of coordinates x (physical 2D) relative to xx (phyiscal 3D): 29 // dx_i/dxx_j (indicial notation) [2 * 3] 30 // 31 // Change of coordinates x (physical 2D) relative to X (reference 2D): 32 // (by chain rule) 33 // dx_i/dX_j = dx_i/dxx_k * dxx_k/dX_j 34 // 35 // The quadrature data is stored in the array q_data. 36 // 37 // We require the determinant of the Jacobian to properly compute integrals of the form: int( u v ) 38 // 39 // Qdata: w * det(dx_i/dX_j) 40 // ----------------------------------------------------------------------------- 41 CEED_QFUNCTION(SetupMassGeoCube)(void *ctx, const CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 42 // Inputs 43 const CeedScalar *J = in[1], *w = in[2]; 44 // Outputs 45 CeedScalar *q_data = out[0]; 46 47 // Quadrature Point Loop 48 CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 49 // Read dxxdX Jacobian entries, stored as 50 // 0 3 51 // 1 4 52 // 2 5 53 const CeedScalar dxxdX[3][2] = { 54 {J[i + Q * 0], J[i + Q * 3]}, 55 {J[i + Q * 1], J[i + Q * 4]}, 56 {J[i + Q * 2], J[i + Q * 5]} 57 }; 58 59 // Modulus of dxxdX column vectors 60 const CeedScalar mod_g_1 = sqrt(dxxdX[0][0] * dxxdX[0][0] + dxxdX[1][0] * dxxdX[1][0] + dxxdX[2][0] * dxxdX[2][0]); 61 const CeedScalar mod_g_2 = sqrt(dxxdX[0][1] * dxxdX[0][1] + dxxdX[1][1] * dxxdX[1][1] + dxxdX[2][1] * dxxdX[2][1]); 62 63 // Use normalized column vectors of dxxdX as rows of dxdxx 64 const CeedScalar dxdxx[2][3] = { 65 {dxxdX[0][0] / mod_g_1, dxxdX[1][0] / mod_g_1, dxxdX[2][0] / mod_g_1}, 66 {dxxdX[0][1] / mod_g_2, dxxdX[1][1] / mod_g_2, dxxdX[2][1] / mod_g_2} 67 }; 68 69 CeedScalar dxdX[2][2]; 70 for (int j = 0; j < 2; j++) { 71 for (int k = 0; k < 2; k++) { 72 dxdX[j][k] = 0; 73 for (int l = 0; l < 3; l++) dxdX[j][k] += dxdxx[j][l] * dxxdX[l][k]; 74 } 75 } 76 77 q_data[i + Q * 0] = (dxdX[0][0] * dxdX[1][1] - dxdX[1][0] * dxdX[0][1]) * w[i]; 78 79 } // End of Quadrature Point Loop 80 return 0; 81 } 82 83 // ----------------------------------------------------------------------------- 84 // This QFunction applies the mass operator for a scalar field. 85 // 86 // Inputs: 87 // u - Input vector at quadrature points 88 // q_data - Geometric factors 89 // 90 // Output: 91 // v - Output vector (test function) at quadrature points 92 // ----------------------------------------------------------------------------- 93 CEED_QFUNCTION(Mass)(void *ctx, const CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 94 // Inputs 95 const CeedScalar *u = in[0], *q_data = in[1]; 96 // Outputs 97 CeedScalar *v = out[0]; 98 99 // Quadrature Point Loop 100 CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) v[i] = q_data[i] * u[i]; 101 102 return 0; 103 } 104 // ----------------------------------------------------------------------------- 105