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 diffusion operator example using PETSc 19 20 #ifndef bp4_h 21 #define bp4_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 CEED_QFUNCTION(SetupDiffRhs3)(void *ctx, CeedInt Q, 31 const CeedScalar *const *in, 32 CeedScalar *const *out) { 33 #ifndef M_PI 34 # define M_PI 3.14159265358979323846 35 #endif 36 const CeedScalar *x = in[0], *w = in[1]; 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 c[3] = { 0, 1., 2. }; 43 const CeedScalar k[3] = { 1., 2., 3. }; 44 45 // Component 1 46 true_soln[i+0*Q] = sin(M_PI*(c[0] + k[0]*x[i+Q*0])) * 47 sin(M_PI*(c[1] + k[1]*x[i+Q*1])) * 48 sin(M_PI*(c[2] + k[2]*x[i+Q*2])); 49 // Component 2 50 true_soln[i+1*Q] = 2 * true_soln[i+0*Q]; 51 // Component 3 52 true_soln[i+2*Q] = 3 * true_soln[i+0*Q]; 53 54 // Component 1 55 rhs[i+0*Q] = w[i+Q*6] * M_PI*M_PI * (k[0]*k[0] + k[1]*k[1] + k[2]*k[2]) * 56 true_soln[i+0*Q]; 57 // Component 2 58 rhs[i+1*Q] = 2 * rhs[i+0*Q]; 59 // Component 3 60 rhs[i+2*Q] = 3 * rhs[i+0*Q]; 61 } // End of Quadrature Point Loop 62 63 return 0; 64 } 65 66 // ----------------------------------------------------------------------------- 67 // This QFunction applies the diffusion operator for a vector field of 3 components. 68 // 69 // Inputs: 70 // ug - Input vector Jacobian at quadrature points 71 // q_data - Geometric factors 72 // 73 // Output: 74 // vJ - Output vector (test functions) Jacobian at quadrature points 75 // 76 // ----------------------------------------------------------------------------- 77 CEED_QFUNCTION(Diff3)(void *ctx, CeedInt Q, 78 const CeedScalar *const *in, CeedScalar *const *out) { 79 const CeedScalar *ug = in[0], *qd = in[1]; 80 CeedScalar *vg = out[0]; 81 82 // Quadrature Point Loop 83 CeedPragmaSIMD 84 for (CeedInt i=0; i<Q; i++) { 85 // Read spatial derivatives of u components 86 const CeedScalar uJ[3][3] = {{ug[i+(0+0*3)*Q], 87 ug[i+(0+1*3)*Q], 88 ug[i+(0+2*3)*Q]}, 89 {ug[i+(1+0*3)*Q], 90 ug[i+(1+1*3)*Q], 91 ug[i+(1+2*3)*Q]}, 92 {ug[i+(2+0*3)*Q], 93 ug[i+(2+1*3)*Q], 94 ug[i+(2+2*3)*Q]} 95 }; 96 // Read q_data (dXdxdXdx_T symmetric matrix) 97 const CeedScalar dXdxdXdx_T[3][3] = {{qd[i+0*Q], 98 qd[i+1*Q], 99 qd[i+2*Q]}, 100 {qd[i+1*Q], 101 qd[i+3*Q], 102 qd[i+4*Q]}, 103 {qd[i+2*Q], 104 qd[i+4*Q], 105 qd[i+5*Q]} 106 }; 107 108 for (int k=0; k<3; k++) // k = component 109 for (int j=0; j<3; j++) // j = direction of vg 110 vg[i+(k+j*3)*Q] = (uJ[k][0] * dXdxdXdx_T[0][j] + 111 uJ[k][1] * dXdxdXdx_T[1][j] + 112 uJ[k][2] * dXdxdXdx_T[2][j]); 113 } // End of Quadrature Point Loop 114 115 return 0; 116 } 117 // ----------------------------------------------------------------------------- 118 119 #endif // bp4_h 120