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