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