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 using PETSc 19 20 #ifndef bp2_h 21 #define bp2_h 22 #include <ceed.h> 23 24 #ifndef __CUDACC__ 25 # include <math.h> 26 #endif 27 28 // ***************************************************************************** 29 // This QFunction sets up the rhs and true solution for the problem 30 // ***************************************************************************** 31 32 // ----------------------------------------------------------------------------- 33 CEED_QFUNCTION(SetupMassRhs3)(void *ctx, const CeedInt Q, 34 const CeedScalar *const *in, 35 CeedScalar *const *out) { 36 const CeedScalar *x = in[0], *J = in[1], *w = in[2]; 37 CeedScalar *true_soln = out[0], *rhs = out[1]; 38 39 // Quadrature Point Loop 40 CeedPragmaSIMD 41 for (CeedInt i=0; i<Q; i++) { 42 const CeedScalar detJ = (J[i+Q*0]*(J[i+Q*4]*J[i+Q*8] - J[i+Q*5]*J[i+Q*7]) - 43 J[i+Q*1]*(J[i+Q*3]*J[i+Q*8] - J[i+Q*5]*J[i+Q*6]) + 44 J[i+Q*2]*(J[i+Q*3]*J[i+Q*7] - J[i+Q*4]*J[i+Q*6])); 45 46 // Component 1 47 true_soln[i+0*Q] = sqrt(x[i]*x[i] + x[i+Q]*x[i+Q] + x[i+2*Q]*x[i+2*Q]); 48 // Component 2 49 true_soln[i+1*Q] = 2 * true_soln[i+0*Q]; 50 // Component 3 51 true_soln[i+2*Q] = 3 * true_soln[i+0*Q]; 52 53 // Component 1 54 rhs[i+0*Q] = detJ * w[i] * true_soln[i+0*Q]; 55 // Component 2 56 rhs[i+1*Q] = 2 * rhs[i+0*Q]; 57 // Component 3 58 rhs[i+2*Q] = 3 * rhs[i+0*Q]; 59 } // End of Quadrature Point Loop 60 return 0; 61 } 62 63 // ***************************************************************************** 64 // This QFunction applies the mass operator for a vector field of 3 components. 65 // 66 // Inputs: 67 // u - Input vector at quadrature points 68 // qdata - Geometric factors 69 // 70 // Output: 71 // v - Output vector (test functions) at quadrature points 72 // 73 // ***************************************************************************** 74 75 // ----------------------------------------------------------------------------- 76 CEED_QFUNCTION(Mass3)(void *ctx, const CeedInt Q, 77 const CeedScalar *const *in, CeedScalar *const *out) { 78 const CeedScalar *u = in[0], *qdata = in[1]; 79 CeedScalar *v = out[0]; 80 81 // Quadrature Point Loop 82 CeedPragmaSIMD 83 for (CeedInt i=0; i<Q; i++) { 84 const CeedScalar r = qdata[i]; 85 // Component 1 86 v[i+0*Q] = r * u[i+0*Q]; 87 // Component 2 88 v[i+1*Q] = r * u[i+1*Q]; 89 // Component 3 90 v[i+2*Q] = r * u[i+2*Q]; 91 } // End of Quadrature Point Loop 92 return 0; 93 } 94 // ----------------------------------------------------------------------------- 95 96 #endif // bp2_h 97