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 areasphere_h 21 #define areasphere_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 3D physical coordinates given by the mesh: xx \in [-R, R]^3 35 // with R radius of the sphere 36 // 37 // Local 3D physical coordinates on the 2D manifold: x \in [-l, l]^3 38 // with l half edge of the cube inscribed in the sphere 39 // 40 // Change of coordinates matrix computed by the library: 41 // (physical 3D coords relative to reference 2D coords) 42 // dxx_j/dX_i (indicial notation) [3 * 2] 43 // 44 // Change of coordinates x (on the 2D manifold) relative to xx (phyisical 3D): 45 // dx_i/dxx_j (indicial notation) [3 * 3] 46 // 47 // Change of coordinates x (on the 2D manifold) relative to X (reference 2D): 48 // (by chain rule) 49 // dx_i/dX_j = dx_i/dxx_k * dxx_k/dX_j [3 * 2] 50 // 51 // modJ is given by the magnitude of the cross product of the columns of dx_i/dX_j 52 // 53 // The quadrature data is stored in the array qdata. 54 // 55 // We require the determinant of the Jacobian to properly compute integrals of 56 // the form: int( u v ) 57 // 58 // Qdata: modJ * w 59 // 60 // ***************************************************************************** 61 62 // ----------------------------------------------------------------------------- 63 CEED_QFUNCTION(SetupMassGeoSphere)(void *ctx, const CeedInt Q, 64 const CeedScalar *const *in, 65 CeedScalar *const *out) { 66 // Inputs 67 const CeedScalar *X = in[0], *J = in[1], *w = in[2]; 68 // Outputs 69 CeedScalar *qdata = out[0]; 70 71 // Quadrature Point Loop 72 CeedPragmaSIMD 73 for (CeedInt i=0; i<Q; i++) { 74 // Read global Cartesian coordinates 75 const CeedScalar xx[3][1] = {{X[i+0*Q]}, 76 {X[i+1*Q]}, 77 {X[i+2*Q]} 78 }; 79 80 // Read dxxdX Jacobian entries, stored as 81 // 0 3 82 // 1 4 83 // 2 5 84 const CeedScalar dxxdX[3][2] = {{J[i+Q*0], 85 J[i+Q*3]}, 86 {J[i+Q*1], 87 J[i+Q*4]}, 88 {J[i+Q*2], 89 J[i+Q*5]} 90 }; 91 92 // Setup 93 const CeedScalar modxxsq = xx[0][0]*xx[0][0]+xx[1][0]*xx[1][0]+xx[2][0]*xx[2][0]; 94 CeedScalar xxsq[3][3]; 95 for (int j=0; j<3; j++) 96 for (int k=0; k<3; k++) { 97 xxsq[j][k] = 0; 98 for (int l=0; l<1; l++) 99 xxsq[j][k] += xx[j][l]*xx[k][l] / (sqrt(modxxsq) * modxxsq); 100 } 101 102 const CeedScalar dxdxx[3][3] = {{1./sqrt(modxxsq) - xxsq[0][0], 103 -xxsq[0][1], 104 -xxsq[0][2]}, 105 {-xxsq[1][0], 106 1./sqrt(modxxsq) - xxsq[1][1], 107 -xxsq[1][2]}, 108 {-xxsq[2][0], 109 -xxsq[2][1], 110 1./sqrt(modxxsq) - xxsq[2][2]} 111 }; 112 113 CeedScalar dxdX[3][2]; 114 for (int j=0; j<3; j++) 115 for (int k=0; k<2; k++) { 116 dxdX[j][k] = 0; 117 for (int l=0; l<3; l++) 118 dxdX[j][k] += dxdxx[j][l]*dxxdX[l][k]; 119 } 120 121 // J is given by the cross product of the columns of dxdX 122 const CeedScalar J[3][1] = {{dxdX[1][0]*dxdX[2][1] - dxdX[2][0]*dxdX[1][1]}, 123 {dxdX[2][0]*dxdX[0][1] - dxdX[0][0]*dxdX[2][1]}, 124 {dxdX[0][0]*dxdX[1][1] - dxdX[1][0]*dxdX[0][1]} 125 }; 126 // Use the magnitude of J as our detJ (volume scaling factor) 127 const CeedScalar modJ = sqrt(J[0][0]*J[0][0]+J[1][0]*J[1][0]+J[2][0]*J[2][0]); 128 qdata[i+Q*0] = modJ * w[i]; 129 130 } // End of Quadrature Point Loop 131 return 0; 132 } 133 // ----------------------------------------------------------------------------- 134 135 #endif // areasphere_h 136