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