1 // Copyright (c) 2017, Lawrence Livermore National Security, LLC. Produced at 2 // the Lawrence Livermore National Laboratory. LLNL-CODE-734707. All Rights 3 // reserved. See files LICENSE and NOTICE for details. 4 // 5 // This file is part of CEED, a collection of benchmarks, miniapps, software 6 // libraries and APIs for efficient high-order finite element and spectral 7 // element discretizations for exascale applications. For more information and 8 // source code availability see http://github.com/ceed. 9 // 10 // The CEED research is supported by the Exascale Computing Project 17-SC-20-SC, 11 // a collaborative effort of two U.S. Department of Energy organizations (Office 12 // of Science and the National Nuclear Security Administration) responsible for 13 // the planning and preparation of a capable exascale ecosystem, including 14 // software, applications, hardware, advanced system engineering and early 15 // testbed platforms, in support of the nation's exascale computing imperative. 16 17 /// @file 18 /// libCEED QFunctions for mass operator example for a scalar field on the sphere using PETSc 19 20 #ifndef areacube_h 21 #define areacube_h 22 23 #ifndef __CUDACC__ 24 # include <math.h> 25 #endif 26 27 // ----------------------------------------------------------------------------- 28 // This QFunction sets up the geometric factor required for integration when 29 // reference coordinates have a different dimension than the one of 30 // physical coordinates 31 // 32 // Reference (parent) 2D coordinates: X \in [-1, 1]^2 33 // 34 // Global physical coordinates given by the mesh (3D): xx \in [-l, l]^3 35 // 36 // Local physical coordinates on the manifold (2D): x \in [-l, l]^2 37 // 38 // Change of coordinates matrix computed by the library: 39 // (physical 3D coords relative to reference 2D coords) 40 // dxx_j/dX_i (indicial notation) [3 * 2] 41 // 42 // Change of coordinates x (physical 2D) relative to xx (phyisical 3D): 43 // dx_i/dxx_j (indicial notation) [2 * 3] 44 // 45 // Change of coordinates x (physical 2D) relative to X (reference 2D): 46 // (by chain rule) 47 // dx_i/dX_j = dx_i/dxx_k * dxx_k/dX_j 48 // 49 // The quadrature data is stored in the array q_data. 50 // 51 // We require the determinant of the Jacobian to properly compute integrals of 52 // the form: int( u v ) 53 // 54 // Qdata: w * det(dx_i/dX_j) 55 // 56 // ----------------------------------------------------------------------------- 57 CEED_QFUNCTION(SetupMassGeoCube)(void *ctx, const CeedInt Q, 58 const CeedScalar *const *in, 59 CeedScalar *const *out) { 60 // Inputs 61 const CeedScalar *J = in[1], *w = in[2]; 62 // Outputs 63 CeedScalar *q_data = out[0]; 64 65 // Quadrature Point Loop 66 CeedPragmaSIMD 67 for (CeedInt i=0; i<Q; i++) { 68 // Read dxxdX Jacobian entries, stored as 69 // 0 3 70 // 1 4 71 // 2 5 72 const CeedScalar dxxdX[3][2] = {{J[i+Q*0], 73 J[i+Q*3]}, 74 {J[i+Q*1], 75 J[i+Q*4]}, 76 {J[i+Q*2], 77 J[i+Q*5]} 78 }; 79 80 // Modulus of dxxdX column vectors 81 const CeedScalar mod_g_1 = sqrt(dxxdX[0][0]*dxxdX[0][0] + 82 dxxdX[1][0]*dxxdX[1][0] + 83 dxxdX[2][0]*dxxdX[2][0]); 84 const CeedScalar mod_g_2 = sqrt(dxxdX[0][1]*dxxdX[0][1] + 85 dxxdX[1][1]*dxxdX[1][1] + 86 dxxdX[2][1]*dxxdX[2][1]); 87 88 // Use normalized column vectors of dxxdX as rows of dxdxx 89 const CeedScalar dxdxx[2][3] = {{dxxdX[0][0] / mod_g_1, 90 dxxdX[1][0] / mod_g_1, 91 dxxdX[2][0] / mod_g_1}, 92 {dxxdX[0][1] / mod_g_2, 93 dxxdX[1][1] / mod_g_2, 94 dxxdX[2][1] / mod_g_2} 95 }; 96 97 CeedScalar dxdX[2][2]; 98 for (int j=0; j<2; j++) 99 for (int k=0; k<2; k++) { 100 dxdX[j][k] = 0; 101 for (int l=0; l<3; l++) 102 dxdX[j][k] += dxdxx[j][l]*dxxdX[l][k]; 103 } 104 105 q_data[i+Q*0] = (dxdX[0][0]*dxdX[1][1] - dxdX[1][0]*dxdX[0][1]) * w[i]; 106 107 } // End of Quadrature Point Loop 108 return 0; 109 } 110 111 // ----------------------------------------------------------------------------- 112 // This QFunction applies the mass operator for a scalar field. 113 // 114 // Inputs: 115 // u - Input vector at quadrature points 116 // q_data - Geometric factors 117 // 118 // Output: 119 // v - Output vector (test function) at quadrature points 120 // 121 // ----------------------------------------------------------------------------- 122 CEED_QFUNCTION(Mass)(void *ctx, const CeedInt Q, 123 const CeedScalar *const *in, CeedScalar *const *out) { 124 // Inputs 125 const CeedScalar *u = in[0], *q_data = in[1]; 126 // Outputs 127 CeedScalar *v = out[0]; 128 129 // Quadrature Point Loop 130 CeedPragmaSIMD 131 for (CeedInt i=0; i<Q; i++) 132 v[i] = q_data[i] * u[i]; 133 134 return 0; 135 } 136 // ----------------------------------------------------------------------------- 137 138 #endif // areacube_h 139