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 CEED_QFUNCTION(SetupDiffGeo)(void *ctx, CeedInt Q, 22 const CeedScalar *const *in, 23 CeedScalar *const *out) { 24 const CeedScalar *J = in[0], *w = in[1]; 25 CeedScalar *qd = out[0]; 26 27 // Quadrature Point Loop 28 CeedPragmaSIMD 29 for (CeedInt i=0; i<Q; i++) { 30 const CeedScalar J11 = J[i+Q*0]; 31 const CeedScalar J21 = J[i+Q*1]; 32 const CeedScalar J31 = J[i+Q*2]; 33 const CeedScalar J12 = J[i+Q*3]; 34 const CeedScalar J22 = J[i+Q*4]; 35 const CeedScalar J32 = J[i+Q*5]; 36 const CeedScalar J13 = J[i+Q*6]; 37 const CeedScalar J23 = J[i+Q*7]; 38 const CeedScalar J33 = J[i+Q*8]; 39 const CeedScalar A11 = J22*J33 - J23*J32; 40 const CeedScalar A12 = J13*J32 - J12*J33; 41 const CeedScalar A13 = J12*J23 - J13*J22; 42 const CeedScalar A21 = J23*J31 - J21*J33; 43 const CeedScalar A22 = J11*J33 - J13*J31; 44 const CeedScalar A23 = J13*J21 - J11*J23; 45 const CeedScalar A31 = J21*J32 - J22*J31; 46 const CeedScalar A32 = J12*J31 - J11*J32; 47 const CeedScalar A33 = J11*J22 - J12*J21; 48 const CeedScalar qw = w[i] / (J11*A11 + J21*A12 + J31*A13); 49 qd[i+Q*0] = qw * (A11*A11 + A12*A12 + A13*A13); 50 qd[i+Q*1] = qw * (A11*A21 + A12*A22 + A13*A23); 51 qd[i+Q*2] = qw * (A11*A31 + A12*A32 + A13*A33); 52 qd[i+Q*3] = qw * (A21*A21 + A22*A22 + A23*A23); 53 qd[i+Q*4] = qw * (A21*A31 + A22*A32 + A23*A33); 54 qd[i+Q*5] = qw * (A31*A31 + A32*A32 + A33*A33); 55 } // End of Quadrature Point Loop 56 57 return 0; 58 } 59 60 // ----------------------------------------------------------------------------- 61 CEED_QFUNCTION(SetupDiffRhs)(void *ctx, CeedInt Q, 62 const CeedScalar *const *in, 63 CeedScalar *const *out) { 64 #ifndef M_PI 65 # define M_PI 3.14159265358979323846 66 #endif 67 const CeedScalar *x = in[0], *J = in[1], *w = in[2]; 68 CeedScalar *true_soln = out[0], *rhs = out[1]; 69 70 // Quadrature Point Loop 71 CeedPragmaSIMD 72 for (CeedInt i=0; i<Q; i++) { 73 const CeedScalar J11 = J[i+Q*0]; 74 const CeedScalar J21 = J[i+Q*1]; 75 const CeedScalar J31 = J[i+Q*2]; 76 const CeedScalar J12 = J[i+Q*3]; 77 const CeedScalar J22 = J[i+Q*4]; 78 const CeedScalar J32 = J[i+Q*5]; 79 const CeedScalar J13 = J[i+Q*6]; 80 const CeedScalar J23 = J[i+Q*7]; 81 const CeedScalar J33 = J[i+Q*8]; 82 const CeedScalar A11 = J22*J33 - J23*J32; 83 const CeedScalar A12 = J13*J32 - J12*J33; 84 const CeedScalar A13 = J12*J23 - J13*J22; 85 86 const CeedScalar c[3] = { 0, 1., 2. }; 87 const CeedScalar k[3] = { 1., 2., 3. }; 88 89 true_soln[i] = sin(M_PI*(c[0] + k[0]*x[i+Q*0])) * 90 sin(M_PI*(c[1] + k[1]*x[i+Q*1])) * 91 sin(M_PI*(c[2] + k[2]*x[i+Q*2])); 92 93 const CeedScalar rho = w[i] * (J11*A11 + J21*A12 + J31*A13); 94 rhs[i] = rho * M_PI*M_PI * (k[0]*k[0] + k[1]*k[1] + k[2]*k[2]) * 95 true_soln[i]; 96 } // End of Quadrature Point Loop 97 98 return 0; 99 } 100 101 // ----------------------------------------------------------------------------- 102 CEED_QFUNCTION(Diff)(void *ctx, CeedInt Q, 103 const CeedScalar *const *in, CeedScalar *const *out) { 104 const CeedScalar *ug = in[0], *qd = in[1]; 105 CeedScalar *vg = out[0]; 106 107 // Quadrature Point Loop 108 CeedPragmaSIMD 109 for (CeedInt i=0; i<Q; i++) { 110 // Read spatial derivatives of u 111 const CeedScalar du[3] = {ug[i+Q*0], 112 ug[i+Q*1], 113 ug[i+Q*2] 114 }; 115 // Read qdata (dXdxdXdxT symmetric matrix) 116 const CeedScalar dXdxdXdxT[3][3] = {{qd[i+0*Q], 117 qd[i+1*Q], 118 qd[i+2*Q]}, 119 {qd[i+1*Q], 120 qd[i+3*Q], 121 qd[i+4*Q]}, 122 {qd[i+2*Q], 123 qd[i+4*Q], 124 qd[i+5*Q]} 125 }; 126 127 for (int j=0; j<3; j++) // j = direction of vg 128 vg[i+j*Q] = (du[0] * dXdxdXdxT[0][j] + 129 du[1] * dXdxdXdxT[1][j] + 130 du[2] * dXdxdXdxT[2][j]); 131 132 } // End of Quadrature Point Loop 133 return 0; 134 } 135 // ----------------------------------------------------------------------------- 136