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