1 // Copyright (c) 2017-2018, Lawrence Livermore National Security, LLC. 2 // Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707. 3 // All Rights 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 #ifndef bps_h 18 #define bps_h 19 #include <ceed.h> 20 21 #ifndef __CUDACC__ 22 # include <math.h> 23 #endif 24 25 #ifndef M_PI 26 #define M_PI 3.14159265358979323846 27 #endif 28 29 // ***************************************************************************** 30 // BP 1 31 // ***************************************************************************** 32 CEED_QFUNCTION(masssetupf)(void *ctx, CeedInt Q, const CeedScalar *const *in, 33 CeedScalar *const *out) { 34 CeedScalar *qdata = out[0], *rhs = out[1]; 35 const CeedScalar *x = in[0]; 36 const CeedScalar *J = in[1]; 37 const CeedScalar *w = in[2]; 38 39 // Quadrature Point Loop 40 for (CeedInt i=0; i<Q; i++) { 41 CeedScalar det = (J[i+Q*0]*(J[i+Q*4]*J[i+Q*8] - J[i+Q*5]*J[i+Q*7]) - 42 J[i+Q*1]*(J[i+Q*3]*J[i+Q*8] - J[i+Q*5]*J[i+Q*6]) + 43 J[i+Q*2]*(J[i+Q*3]*J[i+Q*7] - J[i+Q*4]*J[i+Q*6])); 44 qdata[i] = det * w[i]; 45 rhs[i] = qdata[i] * w[i] * 46 sqrt(x[i]*x[i] + x[i+Q]*x[i+Q] + x[i+2*Q]*x[i+2*Q]); 47 } // End of Quadrature Point Loop 48 return 0; 49 } 50 51 CEED_QFUNCTION int massf(void *ctx, CeedInt Q, const CeedScalar *const *in, 52 CeedScalar *const *out) { 53 const CeedScalar *u = in[0]; 54 const CeedScalar *qdata = in[1]; 55 CeedScalar *v = out[0]; 56 57 // Quadrature Point Loop 58 for (CeedInt i=0; i<Q; i++) 59 v[i] = qdata[i] * u[i]; 60 61 return 0; 62 } 63 // ***************************************************************************** 64 // BP 3 65 // ***************************************************************************** 66 CEED_QFUNCTION(diffsetupf)(void *ctx, CeedInt Q, const CeedScalar *const *in, 67 CeedScalar *const *out) { 68 const CeedScalar *x = in[0]; 69 const CeedScalar *J = in[1]; 70 const CeedScalar *w = in[2]; 71 CeedScalar *qdata = out[0], *rhs = out[1]; 72 73 // Quadrature Point Loop 74 for (CeedInt i=0; i<Q; i++) { 75 // Stored in Voigt convention 76 // 0 5 4 77 // 5 1 3 78 // 4 3 2 79 const CeedScalar J11 = J[i+Q*0]; 80 const CeedScalar J21 = J[i+Q*1]; 81 const CeedScalar J31 = J[i+Q*2]; 82 const CeedScalar J12 = J[i+Q*3]; 83 const CeedScalar J22 = J[i+Q*4]; 84 const CeedScalar J32 = J[i+Q*5]; 85 const CeedScalar J13 = J[i+Q*6]; 86 const CeedScalar J23 = J[i+Q*7]; 87 const CeedScalar J33 = J[i+Q*8]; 88 const CeedScalar A11 = J22*J33 - J23*J32; 89 const CeedScalar A12 = J13*J32 - J12*J33; 90 const CeedScalar A13 = J12*J23 - J13*J22; 91 const CeedScalar A21 = J23*J31 - J21*J33; 92 const CeedScalar A22 = J11*J33 - J13*J31; 93 const CeedScalar A23 = J13*J21 - J11*J23; 94 const CeedScalar A31 = J21*J32 - J22*J31; 95 const CeedScalar A32 = J12*J31 - J11*J32; 96 const CeedScalar A33 = J11*J22 - J12*J21; 97 const CeedScalar qw = w[i] / (J11*A11 + J21*A12 + J31*A13); 98 qdata[i+Q*0] = qw * (A11*A11 + A12*A12 + A13*A13); 99 qdata[i+Q*1] = qw * (A21*A21 + A22*A22 + A23*A23); 100 qdata[i+Q*2] = qw * (A31*A31 + A32*A32 + A33*A33); 101 qdata[i+Q*3] = qw * (A21*A31 + A22*A32 + A23*A33); 102 qdata[i+Q*4] = qw * (A11*A31 + A12*A32 + A13*A33); 103 qdata[i+Q*5] = qw * (A11*A21 + A12*A22 + A13*A23); 104 const CeedScalar c[3] = { 0, 1., 2. }; 105 const CeedScalar k[3] = { 1., 2., 3. }; 106 const CeedScalar rho = w[i] * (J11*A11 + J21*A12 + J31*A13); 107 rhs[i] = rho * M_PI*M_PI * (k[0]*k[0] + k[1]*k[1] + k[2]*k[2]) * 108 sin(M_PI*(c[0] + k[0]*x[i+Q*0])) * 109 sin(M_PI*(c[1] + k[1]*x[i+Q*1])) * 110 sin(M_PI*(c[2] + k[2]*x[i+Q*2])); 111 } // End of Quadrature Point Loop 112 return 0; 113 } 114 115 CEED_QFUNCTION int diffusionf(void *ctx, CeedInt Q, const CeedScalar *const *in, 116 CeedScalar *const *out) { 117 const CeedScalar *ug = in[0]; 118 const CeedScalar *qdata = in[1]; 119 CeedScalar *vg = out[0]; 120 121 // Quadrature Point Loop 122 for (CeedInt i=0; i<Q; i++) { 123 const CeedScalar ug0 = ug[i+Q*0]; 124 const CeedScalar ug1 = ug[i+Q*1]; 125 const CeedScalar ug2 = ug[i+Q*2]; 126 vg[i+Q*0] = qdata[i+Q*0]*ug0 + qdata[i+Q*5]*ug1 + qdata[i+Q*4]*ug2; 127 vg[i+Q*1] = qdata[i+Q*5]*ug0 + qdata[i+Q*1]*ug1 + qdata[i+Q*3]*ug2; 128 vg[i+Q*2] = qdata[i+Q*4]*ug0 + qdata[i+Q*3]*ug1 + qdata[i+Q*2]*ug2; 129 } // End of Quadrature Point Loop 130 return 0; 131 } 132 133 #endif // bps_h 134