xref: /libCEED/examples/nek/bps/bps.h (revision ab213215e569729a95fd10d21627f8060eaeb868)
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 
1736d2312cSvaleriabarra #ifndef bps_h
1836d2312cSvaleriabarra #define bps_h
1936d2312cSvaleriabarra 
204d537eeaSYohann #ifndef __CUDACC__
214d537eeaSYohann #  include <math.h>
224d537eeaSYohann #endif
234d537eeaSYohann 
24ccaff030SJeremy L Thompson #ifndef M_PI
25ccaff030SJeremy L Thompson #define M_PI    3.14159265358979323846
26ccaff030SJeremy L Thompson #endif
27ccaff030SJeremy L Thompson 
284d537eeaSYohann // *****************************************************************************
294d537eeaSYohann //   BP 1
304d537eeaSYohann // *****************************************************************************
31ccaff030SJeremy L Thompson CEED_QFUNCTION(masssetupf)(void *ctx, CeedInt Q, const CeedScalar *const *in,
32ccaff030SJeremy L Thompson                            CeedScalar *const *out) {
33a2fa7910SValeria Barra   CeedScalar *qdata = out[0], *rhs = out[1];
344d537eeaSYohann   const CeedScalar *x = in[0];
354d537eeaSYohann   const CeedScalar *J = in[1];
364d537eeaSYohann   const CeedScalar *w = in[2];
37ee07ded2SValeria Barra 
38ee07ded2SValeria Barra   // Quadrature Point Loop
394d537eeaSYohann   for (CeedInt i=0; i<Q; i++) {
404d537eeaSYohann     CeedScalar det = (J[i+Q*0]*(J[i+Q*4]*J[i+Q*8] - J[i+Q*5]*J[i+Q*7]) -
414d537eeaSYohann                       J[i+Q*1]*(J[i+Q*3]*J[i+Q*8] - J[i+Q*5]*J[i+Q*6]) +
424d537eeaSYohann                       J[i+Q*2]*(J[i+Q*3]*J[i+Q*7] - J[i+Q*4]*J[i+Q*6]));
43a2fa7910SValeria Barra     qdata[i] = det * w[i];
44*ab213215SJeremy L Thompson     rhs[i] = qdata[i] * sqrt(x[i]*x[i] + x[i+Q]*x[i+Q] + x[i+2*Q]*x[i+2*Q]);
45ee07ded2SValeria Barra   } // End of Quadrature Point Loop
464d537eeaSYohann   return 0;
474d537eeaSYohann }
484d537eeaSYohann 
49*ab213215SJeremy L Thompson CEED_QFUNCTION(massf)(void *ctx, CeedInt Q, const CeedScalar *const *in,
50ccaff030SJeremy L Thompson                       CeedScalar *const *out) {
514d537eeaSYohann   const CeedScalar *u = in[0];
52a2fa7910SValeria Barra   const CeedScalar *qdata = in[1];
534d537eeaSYohann   CeedScalar *v = out[0];
54ee07ded2SValeria Barra 
55ee07ded2SValeria Barra   // Quadrature Point Loop
56ee07ded2SValeria Barra   for (CeedInt i=0; i<Q; i++)
57a2fa7910SValeria Barra     v[i] = qdata[i] * u[i];
58ee07ded2SValeria Barra 
594d537eeaSYohann   return 0;
604d537eeaSYohann }
614d537eeaSYohann // *****************************************************************************
624d537eeaSYohann //   BP 3
634d537eeaSYohann // *****************************************************************************
64ccaff030SJeremy L Thompson CEED_QFUNCTION(diffsetupf)(void *ctx, CeedInt Q, const CeedScalar *const *in,
65ccaff030SJeremy L Thompson                            CeedScalar *const *out) {
664d537eeaSYohann   const CeedScalar *x = in[0];
674d537eeaSYohann   const CeedScalar *J = in[1];
684d537eeaSYohann   const CeedScalar *w = in[2];
69a2fa7910SValeria Barra   CeedScalar *qdata = out[0], *rhs = out[1];
70ee07ded2SValeria Barra 
71ee07ded2SValeria Barra   // Quadrature Point Loop
724d537eeaSYohann   for (CeedInt i=0; i<Q; i++) {
73288c0443SJeremy L Thompson     // Stored in Voigt convention
74288c0443SJeremy L Thompson     // 0 5 4
75288c0443SJeremy L Thompson     // 5 1 3
76288c0443SJeremy L Thompson     // 4 3 2
774d537eeaSYohann     const CeedScalar J11 = J[i+Q*0];
784d537eeaSYohann     const CeedScalar J21 = J[i+Q*1];
794d537eeaSYohann     const CeedScalar J31 = J[i+Q*2];
804d537eeaSYohann     const CeedScalar J12 = J[i+Q*3];
814d537eeaSYohann     const CeedScalar J22 = J[i+Q*4];
824d537eeaSYohann     const CeedScalar J32 = J[i+Q*5];
834d537eeaSYohann     const CeedScalar J13 = J[i+Q*6];
844d537eeaSYohann     const CeedScalar J23 = J[i+Q*7];
854d537eeaSYohann     const CeedScalar J33 = J[i+Q*8];
864d537eeaSYohann     const CeedScalar A11 = J22*J33 - J23*J32;
874d537eeaSYohann     const CeedScalar A12 = J13*J32 - J12*J33;
884d537eeaSYohann     const CeedScalar A13 = J12*J23 - J13*J22;
894d537eeaSYohann     const CeedScalar A21 = J23*J31 - J21*J33;
904d537eeaSYohann     const CeedScalar A22 = J11*J33 - J13*J31;
914d537eeaSYohann     const CeedScalar A23 = J13*J21 - J11*J23;
924d537eeaSYohann     const CeedScalar A31 = J21*J32 - J22*J31;
934d537eeaSYohann     const CeedScalar A32 = J12*J31 - J11*J32;
944d537eeaSYohann     const CeedScalar A33 = J11*J22 - J12*J21;
954d537eeaSYohann     const CeedScalar qw = w[i] / (J11*A11 + J21*A12 + J31*A13);
96a2fa7910SValeria Barra     qdata[i+Q*0] = qw * (A11*A11 + A12*A12 + A13*A13);
97a2fa7910SValeria Barra     qdata[i+Q*1] = qw * (A21*A21 + A22*A22 + A23*A23);
98a2fa7910SValeria Barra     qdata[i+Q*2] = qw * (A31*A31 + A32*A32 + A33*A33);
99a2fa7910SValeria Barra     qdata[i+Q*3] = qw * (A21*A31 + A22*A32 + A23*A33);
100a2fa7910SValeria Barra     qdata[i+Q*4] = qw * (A11*A31 + A12*A32 + A13*A33);
101a2fa7910SValeria Barra     qdata[i+Q*5] = qw * (A11*A21 + A12*A22 + A13*A23);
1024d537eeaSYohann     const CeedScalar c[3] = { 0, 1., 2. };
1034d537eeaSYohann     const CeedScalar k[3] = { 1., 2., 3. };
1044d537eeaSYohann     const CeedScalar rho = w[i] * (J11*A11 + J21*A12 + J31*A13);
1054d537eeaSYohann     rhs[i] = rho * M_PI*M_PI * (k[0]*k[0] + k[1]*k[1] + k[2]*k[2]) *
1064d537eeaSYohann              sin(M_PI*(c[0] + k[0]*x[i+Q*0])) *
1074d537eeaSYohann              sin(M_PI*(c[1] + k[1]*x[i+Q*1])) *
1084d537eeaSYohann              sin(M_PI*(c[2] + k[2]*x[i+Q*2]));
109ee07ded2SValeria Barra   } // End of Quadrature Point Loop
1104d537eeaSYohann   return 0;
1114d537eeaSYohann }
1124d537eeaSYohann 
113*ab213215SJeremy L Thompson CEED_QFUNCTION(diffusionf)(void *ctx, CeedInt Q, const CeedScalar *const *in,
114ccaff030SJeremy L Thompson                            CeedScalar *const *out) {
1154d537eeaSYohann   const CeedScalar *ug = in[0];
116a2fa7910SValeria Barra   const CeedScalar *qdata = in[1];
1174d537eeaSYohann   CeedScalar *vg = out[0];
118ee07ded2SValeria Barra 
119ee07ded2SValeria Barra   // Quadrature Point Loop
1204d537eeaSYohann   for (CeedInt i=0; i<Q; i++) {
1214d537eeaSYohann     const CeedScalar ug0 = ug[i+Q*0];
1224d537eeaSYohann     const CeedScalar ug1 = ug[i+Q*1];
1234d537eeaSYohann     const CeedScalar ug2 = ug[i+Q*2];
124a2fa7910SValeria Barra     vg[i+Q*0] = qdata[i+Q*0]*ug0 + qdata[i+Q*5]*ug1 + qdata[i+Q*4]*ug2;
125a2fa7910SValeria Barra     vg[i+Q*1] = qdata[i+Q*5]*ug0 + qdata[i+Q*1]*ug1 + qdata[i+Q*3]*ug2;
126a2fa7910SValeria Barra     vg[i+Q*2] = qdata[i+Q*4]*ug0 + qdata[i+Q*3]*ug1 + qdata[i+Q*2]*ug2;
127ee07ded2SValeria Barra   } // End of Quadrature Point Loop
1284d537eeaSYohann   return 0;
1294d537eeaSYohann }
13036d2312cSvaleriabarra 
13136d2312cSvaleriabarra #endif // bps_h
132