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 vector field on the sphere using PETSc 19 20 #ifndef bp4sphere_h 21 #define bp4sphere_h 22 23 #ifndef __CUDACC__ 24 # include <math.h> 25 #endif 26 27 // ***************************************************************************** 28 // This QFunction sets up the rhs and true solution for the problem 29 // ***************************************************************************** 30 31 // ----------------------------------------------------------------------------- 32 CEED_QFUNCTION(SetupDiffRhs3)(void *ctx, const CeedInt Q, 33 const CeedScalar *const *in, 34 CeedScalar *const *out) { 35 // Inputs 36 const CeedScalar *X = in[0], *qdata = in[1]; 37 // Outputs 38 CeedScalar *true_soln = out[0], *rhs = out[1]; 39 40 // Context 41 const CeedScalar *context = (const CeedScalar*)ctx; 42 const CeedScalar R = context[0]; 43 44 // Quadrature Point Loop 45 CeedPragmaSIMD 46 for (CeedInt i=0; i<Q; i++) { 47 // Read global Cartesian coordinates 48 CeedScalar x = X[i+Q*0], y = X[i+Q*1], z = X[i+Q*2]; 49 // Normalize quadrature point coordinates to sphere 50 CeedScalar rad = sqrt(x*x + y*y + z*z); 51 x *= R / rad; 52 y *= R / rad; 53 z *= R / rad; 54 // Compute latitude and longitude 55 const CeedScalar theta = asin(z / R); // latitude 56 const CeedScalar lambda = atan2(y, x); // longitude 57 58 // Use absolute value of latitute for true solution 59 // Component 1 60 true_soln[i+0*Q] = sin(lambda) * cos(theta); 61 // Component 2 62 true_soln[i+1*Q] = 2 * true_soln[i+0*Q]; 63 // Component 3 64 true_soln[i+2*Q] = 3 * true_soln[i+0*Q]; 65 66 // Component 1 67 rhs[i+0*Q] = qdata[i+Q*0] * 2 * sin(lambda)*cos(theta) / (R*R); 68 // Component 2 69 rhs[i+1*Q] = 2 * rhs[i+0*Q]; 70 // Component 3 71 rhs[i+2*Q] = 3 * rhs[i+0*Q]; 72 } // End of Quadrature Point Loop 73 74 return 0; 75 } 76 77 // ***************************************************************************** 78 // This QFunction applies the diffusion operator for a vector field of 3 components. 79 // 80 // Inputs: 81 // ug - Input vector Jacobian at quadrature points 82 // qdata - Geometric factors 83 // 84 // Output: 85 // vJ - Output vector (test functions) Jacobian at quadrature points 86 // 87 // ***************************************************************************** 88 89 // ----------------------------------------------------------------------------- 90 CEED_QFUNCTION(Diff3)(void *ctx, const CeedInt Q, 91 const CeedScalar *const *in, CeedScalar *const *out) { 92 const CeedScalar *ug = in[0], *qdata = in[1]; 93 CeedScalar *vJ = out[0]; 94 95 // Quadrature Point Loop 96 CeedPragmaSIMD 97 for (CeedInt i=0; i<Q; i++) { 98 // Read spatial derivatives of u 99 const CeedScalar uJ[3][2] = {{ug[i+(0+0*3)*Q], 100 ug[i+(0+1*3)*Q]}, 101 {ug[i+(1+0*3)*Q], 102 ug[i+(1+1*3)*Q]}, 103 {ug[i+(2+0*3)*Q], 104 ug[i+(2+1*3)*Q]} 105 }; 106 // Read qdata 107 const CeedScalar wdetJ = qdata[i+Q*0]; 108 // -- Grad-to-Grad qdata 109 // ---- dXdx_j,k * dXdx_k,j 110 const CeedScalar dXdxdXdxT[2][2] = {{qdata[i+Q*1], 111 qdata[i+Q*3]}, 112 {qdata[i+Q*3], 113 qdata[i+Q*2]} 114 }; 115 116 for (int k=0; k<3; k++) // k = component 117 for (int j=0; j<2; j++) // j = direction of vg 118 vJ[i+(k+j*3)*Q] = wdetJ * (uJ[k][0] * dXdxdXdxT[0][j] + 119 uJ[k][1] * dXdxdXdxT[1][j]); 120 121 } // End of Quadrature Point Loop 122 123 return 0; 124 } 125 // ----------------------------------------------------------------------------- 126 127 #endif // bp4sphere_h 128