xref: /libCEED/examples/mfem/bp1.h (revision a2fa791084b022ffd3d077ae9be76b4b170bb84e)
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 /// A structure used to pass additional data to f_build_mass
184d537eeaSYohann struct BuildContext { CeedInt dim, space_dim; };
194d537eeaSYohann 
204d537eeaSYohann /// libCEED Q-function for building quadrature data for a mass operator
214d537eeaSYohann CEED_QFUNCTION(f_build_mass)(void *ctx, const CeedInt Q,
224d537eeaSYohann                              const CeedScalar *const *in, CeedScalar *const *out) {
234d537eeaSYohann   // in[0] is Jacobians with shape [dim, nc=dim, Q]
244d537eeaSYohann   // in[1] is quadrature weights, size (Q)
254d537eeaSYohann   BuildContext *bc = (BuildContext *)ctx;
26*a2fa7910SValeria Barra   const CeedScalar *J = in[0], *w = in[1];
27*a2fa7910SValeria Barra   CeedScalar *qdata = out[0];
28ee07ded2SValeria Barra 
294d537eeaSYohann   switch (bc->dim + 10*bc->space_dim) {
304d537eeaSYohann   case 11:
31ee07ded2SValeria Barra     // Quadrature Point Loop
32ee07ded2SValeria Barra     CeedPragmaSIMD
334d537eeaSYohann     for (CeedInt i=0; i<Q; i++) {
34*a2fa7910SValeria Barra       qdata[i] = J[i] * w[i];
354d537eeaSYohann     }
364d537eeaSYohann     break;
374d537eeaSYohann   case 22:
38ee07ded2SValeria Barra     // Quadrature Point Loop
39ee07ded2SValeria Barra     CeedPragmaSIMD
404d537eeaSYohann     for (CeedInt i=0; i<Q; i++) {
414d537eeaSYohann       // 0 2
424d537eeaSYohann       // 1 3
43*a2fa7910SValeria Barra       qdata[i] = (J[i+Q*0]*J[i+Q*3] - J[i+Q*1]*J[i+Q*2]) * w[i];
444d537eeaSYohann     }
454d537eeaSYohann     break;
464d537eeaSYohann   case 33:
47ee07ded2SValeria Barra     // Quadrature Point Loop
48ee07ded2SValeria Barra     CeedPragmaSIMD
494d537eeaSYohann     for (CeedInt i=0; i<Q; i++) {
504d537eeaSYohann       // 0 3 6
514d537eeaSYohann       // 1 4 7
524d537eeaSYohann       // 2 5 8
53*a2fa7910SValeria Barra       qdata[i] = (J[i+Q*0]*(J[i+Q*4]*J[i+Q*8] - J[i+Q*5]*J[i+Q*7]) -
544d537eeaSYohann                 J[i+Q*1]*(J[i+Q*3]*J[i+Q*8] - J[i+Q*5]*J[i+Q*6]) +
55*a2fa7910SValeria Barra                 J[i+Q*2]*(J[i+Q*3]*J[i+Q*7] - J[i+Q*4]*J[i+Q*6])) * w[i];
564d537eeaSYohann     }
574d537eeaSYohann     break;
584d537eeaSYohann   }
594d537eeaSYohann   return 0;
604d537eeaSYohann }
614d537eeaSYohann 
624d537eeaSYohann /// libCEED Q-function for applying a mass operator
634d537eeaSYohann CEED_QFUNCTION(f_apply_mass)(void *ctx, const CeedInt Q,
644d537eeaSYohann                              const CeedScalar *const *in, CeedScalar *const *out) {
65*a2fa7910SValeria Barra   const CeedScalar *u = in[0], *qdata = in[1];
664d537eeaSYohann   CeedScalar *v = out[0];
67ee07ded2SValeria Barra 
68ee07ded2SValeria Barra   // Quadrature Point Loop
69ee07ded2SValeria Barra   CeedPragmaSIMD
704d537eeaSYohann   for (CeedInt i=0; i<Q; i++) {
71*a2fa7910SValeria Barra     v[i] = qdata[i] * u[i];
724d537eeaSYohann   }
734d537eeaSYohann   return 0;
744d537eeaSYohann }
75