xref: /libCEED/examples/nek/bps/bps.h (revision 288c044332e33f37503f09b6484fec9d0a55fba1)
14d537eeaSYohann // Copyright (c) 2017-2018, Lawrence Livermore National Security, LLC.
24d537eeaSYohann // Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707.
34d537eeaSYohann // All Rights reserved. See files LICENSE and NOTICE for details.
44d537eeaSYohann //
54d537eeaSYohann // This file is part of CEED, a collection of benchmarks, miniapps, software
64d537eeaSYohann // libraries and APIs for efficient high-order finite element and spectral
74d537eeaSYohann // element discretizations for exascale applications. For more information and
84d537eeaSYohann // source code availability see http://github.com/ceed.
94d537eeaSYohann //
104d537eeaSYohann // The CEED research is supported by the Exascale Computing Project 17-SC-20-SC,
114d537eeaSYohann // a collaborative effort of two U.S. Department of Energy organizations (Office
124d537eeaSYohann // of Science and the National Nuclear Security Administration) responsible for
134d537eeaSYohann // the planning and preparation of a capable exascale ecosystem, including
144d537eeaSYohann // software, applications, hardware, advanced system engineering and early
154d537eeaSYohann // testbed platforms, in support of the nation's exascale computing imperative.
164d537eeaSYohann 
174d537eeaSYohann #ifndef __CUDACC__
184d537eeaSYohann #  include <math.h>
194d537eeaSYohann #endif
204d537eeaSYohann 
214d537eeaSYohann // *****************************************************************************
224d537eeaSYohann //   BP 1
234d537eeaSYohann // *****************************************************************************
244d537eeaSYohann CEED_QFUNCTION(masssetupf)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
254d537eeaSYohann   CeedScalar *rho = out[0], *rhs = out[1];
264d537eeaSYohann   const CeedScalar *x = in[0];
274d537eeaSYohann   const CeedScalar *J = in[1];
284d537eeaSYohann   const CeedScalar *w = in[2];
29ee07ded2SValeria Barra 
30ee07ded2SValeria Barra   // Quadrature Point Loop
314d537eeaSYohann   for (CeedInt i=0; i<Q; i++) {
324d537eeaSYohann     CeedScalar det = (J[i+Q*0]*(J[i+Q*4]*J[i+Q*8] - J[i+Q*5]*J[i+Q*7]) -
334d537eeaSYohann                       J[i+Q*1]*(J[i+Q*3]*J[i+Q*8] - J[i+Q*5]*J[i+Q*6]) +
344d537eeaSYohann                       J[i+Q*2]*(J[i+Q*3]*J[i+Q*7] - J[i+Q*4]*J[i+Q*6]));
354d537eeaSYohann     rho[i] = det * w[i];
364d537eeaSYohann     rhs[i] = rho[i] * w[i] *
374d537eeaSYohann                sqrt(x[i]*x[i] + x[i+Q]*x[i+Q] + x[i+2*Q]*x[i+2*Q]);
38ee07ded2SValeria Barra   } // End of Quadrature Point Loop
394d537eeaSYohann   return 0;
404d537eeaSYohann }
414d537eeaSYohann 
424d537eeaSYohann CEED_QFUNCTION int massf(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
434d537eeaSYohann   const CeedScalar *u = in[0];
444d537eeaSYohann   const CeedScalar *rho = in[1];
454d537eeaSYohann   CeedScalar *v = out[0];
46ee07ded2SValeria Barra 
47ee07ded2SValeria Barra   // Quadrature Point Loop
48ee07ded2SValeria Barra   for (CeedInt i=0; i<Q; i++)
494d537eeaSYohann     v[i] = rho[i] * u[i];
50ee07ded2SValeria Barra 
514d537eeaSYohann   return 0;
524d537eeaSYohann }
534d537eeaSYohann // *****************************************************************************
544d537eeaSYohann //   BP 3
554d537eeaSYohann // *****************************************************************************
564d537eeaSYohann CEED_QFUNCTION(diffsetupf)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
574d537eeaSYohann   #ifndef M_PI
584d537eeaSYohann   #define M_PI    3.14159265358979323846
594d537eeaSYohann   #endif
604d537eeaSYohann   const CeedScalar *x = in[0];
614d537eeaSYohann   const CeedScalar *J = in[1];
624d537eeaSYohann   const CeedScalar *w = in[2];
634d537eeaSYohann   CeedScalar *qd = out[0], *rhs = out[1];
64ee07ded2SValeria Barra 
65ee07ded2SValeria Barra   // Quadrature Point Loop
664d537eeaSYohann   for (CeedInt i=0; i<Q; i++) {
67*288c0443SJeremy L Thompson     // Stored in Voigt convention
68*288c0443SJeremy L Thompson     // 0 5 4
69*288c0443SJeremy L Thompson     // 5 1 3
70*288c0443SJeremy L Thompson     // 4 3 2
714d537eeaSYohann     const CeedScalar J11 = J[i+Q*0];
724d537eeaSYohann     const CeedScalar J21 = J[i+Q*1];
734d537eeaSYohann     const CeedScalar J31 = J[i+Q*2];
744d537eeaSYohann     const CeedScalar J12 = J[i+Q*3];
754d537eeaSYohann     const CeedScalar J22 = J[i+Q*4];
764d537eeaSYohann     const CeedScalar J32 = J[i+Q*5];
774d537eeaSYohann     const CeedScalar J13 = J[i+Q*6];
784d537eeaSYohann     const CeedScalar J23 = J[i+Q*7];
794d537eeaSYohann     const CeedScalar J33 = J[i+Q*8];
804d537eeaSYohann     const CeedScalar A11 = J22*J33 - J23*J32;
814d537eeaSYohann     const CeedScalar A12 = J13*J32 - J12*J33;
824d537eeaSYohann     const CeedScalar A13 = J12*J23 - J13*J22;
834d537eeaSYohann     const CeedScalar A21 = J23*J31 - J21*J33;
844d537eeaSYohann     const CeedScalar A22 = J11*J33 - J13*J31;
854d537eeaSYohann     const CeedScalar A23 = J13*J21 - J11*J23;
864d537eeaSYohann     const CeedScalar A31 = J21*J32 - J22*J31;
874d537eeaSYohann     const CeedScalar A32 = J12*J31 - J11*J32;
884d537eeaSYohann     const CeedScalar A33 = J11*J22 - J12*J21;
894d537eeaSYohann     const CeedScalar qw = w[i] / (J11*A11 + J21*A12 + J31*A13);
904d537eeaSYohann     qd[i+Q*0] = qw * (A11*A11 + A12*A12 + A13*A13);
91*288c0443SJeremy L Thompson     qd[i+Q*1] = qw * (A21*A21 + A22*A22 + A23*A23);
92*288c0443SJeremy L Thompson     qd[i+Q*2] = qw * (A31*A31 + A32*A32 + A33*A33);
93*288c0443SJeremy L Thompson     qd[i+Q*3] = qw * (A21*A31 + A22*A32 + A23*A33);
94*288c0443SJeremy L Thompson     qd[i+Q*4] = qw * (A11*A31 + A12*A32 + A13*A33);
95*288c0443SJeremy L Thompson     qd[i+Q*5] = qw * (A11*A21 + A12*A22 + A13*A23);
964d537eeaSYohann     const CeedScalar c[3] = { 0, 1., 2. };
974d537eeaSYohann     const CeedScalar k[3] = { 1., 2., 3. };
984d537eeaSYohann     const CeedScalar rho = w[i] * (J11*A11 + J21*A12 + J31*A13);
994d537eeaSYohann     rhs[i] = rho * M_PI*M_PI * (k[0]*k[0] + k[1]*k[1] + k[2]*k[2]) *
1004d537eeaSYohann                sin(M_PI*(c[0] + k[0]*x[i+Q*0])) *
1014d537eeaSYohann                sin(M_PI*(c[1] + k[1]*x[i+Q*1])) *
1024d537eeaSYohann                sin(M_PI*(c[2] + k[2]*x[i+Q*2]));
103ee07ded2SValeria Barra   } // End of Quadrature Point Loop
1044d537eeaSYohann   return 0;
1054d537eeaSYohann }
1064d537eeaSYohann 
1074d537eeaSYohann CEED_QFUNCTION int diffusionf(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
1084d537eeaSYohann   const CeedScalar *ug = in[0];
1094d537eeaSYohann   const CeedScalar *qd = in[1];
1104d537eeaSYohann   CeedScalar *vg = out[0];
111ee07ded2SValeria Barra 
112ee07ded2SValeria Barra   // Quadrature Point Loop
1134d537eeaSYohann   for (CeedInt i=0; i<Q; i++) {
1144d537eeaSYohann     const CeedScalar ug0 = ug[i+Q*0];
1154d537eeaSYohann     const CeedScalar ug1 = ug[i+Q*1];
1164d537eeaSYohann     const CeedScalar ug2 = ug[i+Q*2];
117*288c0443SJeremy L Thompson     vg[i+Q*0] = qd[i+Q*0]*ug0 + qd[i+Q*5]*ug1 + qd[i+Q*4]*ug2;
118*288c0443SJeremy L Thompson     vg[i+Q*1] = qd[i+Q*5]*ug0 + qd[i+Q*1]*ug1 + qd[i+Q*3]*ug2;
119*288c0443SJeremy L Thompson     vg[i+Q*2] = qd[i+Q*4]*ug0 + qd[i+Q*3]*ug1 + qd[i+Q*2]*ug2;
120ee07ded2SValeria Barra   } // End of Quadrature Point Loop
1214d537eeaSYohann   return 0;
1224d537eeaSYohann }
123