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 qdata. 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 58 // ----------------------------------------------------------------------------- 59 CEED_QFUNCTION(SetupMassGeoCube)(void *ctx, const CeedInt Q, 60 const CeedScalar *const *in, 61 CeedScalar *const *out) { 62 // Inputs 63 const CeedScalar *J = in[1], *w = in[2]; 64 // Outputs 65 CeedScalar *qdata = out[0]; 66 67 // Quadrature Point Loop 68 CeedPragmaSIMD 69 for (CeedInt i=0; i<Q; i++) { 70 // Read dxxdX Jacobian entries, stored as 71 // 0 3 72 // 1 4 73 // 2 5 74 const CeedScalar dxxdX[3][2] = {{J[i+Q*0], 75 J[i+Q*3]}, 76 {J[i+Q*1], 77 J[i+Q*4]}, 78 {J[i+Q*2], 79 J[i+Q*5]} 80 }; 81 82 // Modulus of dxxdX column vectors 83 const CeedScalar modg1 = sqrt(dxxdX[0][0]*dxxdX[0][0] + 84 dxxdX[1][0]*dxxdX[1][0] + 85 dxxdX[2][0]*dxxdX[2][0]); 86 const CeedScalar modg2 = sqrt(dxxdX[0][1]*dxxdX[0][1] + 87 dxxdX[1][1]*dxxdX[1][1] + 88 dxxdX[2][1]*dxxdX[2][1]); 89 90 // Use normalized column vectors of dxxdX as rows of dxdxx 91 const CeedScalar dxdxx[2][3] = {{dxxdX[0][0] / modg1, 92 dxxdX[1][0] / modg1, 93 dxxdX[2][0] / modg1}, 94 {dxxdX[0][1] / modg2, 95 dxxdX[1][1] / modg2, 96 dxxdX[2][1] / modg2} 97 }; 98 99 CeedScalar dxdX[2][2]; 100 for (int j=0; j<2; j++) 101 for (int k=0; k<2; k++) { 102 dxdX[j][k] = 0; 103 for (int l=0; l<3; l++) 104 dxdX[j][k] += dxdxx[j][l]*dxxdX[l][k]; 105 } 106 107 qdata[i+Q*0] = (dxdX[0][0]*dxdX[1][1] - dxdX[1][0]*dxdX[0][1]) * w[i]; 108 109 } // End of Quadrature Point Loop 110 return 0; 111 } 112 // ----------------------------------------------------------------------------- 113 114 // ***************************************************************************** 115 // This QFunction applies the mass operator for a scalar field. 116 // 117 // Inputs: 118 // u - Input vector at quadrature points 119 // qdata - Geometric factors 120 // 121 // Output: 122 // v - Output vector (test function) at quadrature points 123 // 124 // ***************************************************************************** 125 126 // ----------------------------------------------------------------------------- 127 CEED_QFUNCTION(Mass)(void *ctx, const CeedInt Q, 128 const CeedScalar *const *in, CeedScalar *const *out) { 129 // Inputs 130 const CeedScalar *u = in[0], *qdata = in[1]; 131 // Outputs 132 CeedScalar *v = out[0]; 133 134 // Quadrature Point Loop 135 CeedPragmaSIMD 136 for (CeedInt i=0; i<Q; i++) 137 v[i] = qdata[i] * u[i]; 138 139 return 0; 140 } 141 // ----------------------------------------------------------------------------- 142 143 #endif // areacube_h 144