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