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