xref: /libCEED/examples/mfem/bp1.h (revision 4d537eea83dd2f1011134892241345b6ac537f56)
1*4d537eeaSYohann // Copyright (c) 2017-2018, Lawrence Livermore National Security, LLC.
2*4d537eeaSYohann // Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707.
3*4d537eeaSYohann // All Rights reserved. See files LICENSE and NOTICE for details.
4*4d537eeaSYohann //
5*4d537eeaSYohann // This file is part of CEED, a collection of benchmarks, miniapps, software
6*4d537eeaSYohann // libraries and APIs for efficient high-order finite element and spectral
7*4d537eeaSYohann // element discretizations for exascale applications. For more information and
8*4d537eeaSYohann // source code availability see http://github.com/ceed.
9*4d537eeaSYohann //
10*4d537eeaSYohann // The CEED research is supported by the Exascale Computing Project 17-SC-20-SC,
11*4d537eeaSYohann // a collaborative effort of two U.S. Department of Energy organizations (Office
12*4d537eeaSYohann // of Science and the National Nuclear Security Administration) responsible for
13*4d537eeaSYohann // the planning and preparation of a capable exascale ecosystem, including
14*4d537eeaSYohann // software, applications, hardware, advanced system engineering and early
15*4d537eeaSYohann // testbed platforms, in support of the nation's exascale computing imperative.
16*4d537eeaSYohann 
17*4d537eeaSYohann /// A structure used to pass additional data to f_build_mass
18*4d537eeaSYohann struct BuildContext { CeedInt dim, space_dim; };
19*4d537eeaSYohann 
20*4d537eeaSYohann /// libCEED Q-function for building quadrature data for a mass operator
21*4d537eeaSYohann CEED_QFUNCTION(f_build_mass)(void *ctx, const CeedInt Q,
22*4d537eeaSYohann                              const CeedScalar *const *in, CeedScalar *const *out) {
23*4d537eeaSYohann   // in[0] is Jacobians with shape [dim, nc=dim, Q]
24*4d537eeaSYohann   // in[1] is quadrature weights, size (Q)
25*4d537eeaSYohann   BuildContext *bc = (BuildContext *)ctx;
26*4d537eeaSYohann   const CeedScalar *J = in[0], *qw = in[1];
27*4d537eeaSYohann   CeedScalar *rho = out[0];
28*4d537eeaSYohann   switch (bc->dim + 10*bc->space_dim) {
29*4d537eeaSYohann   case 11:
30*4d537eeaSYohann     for (CeedInt i=0; i<Q; i++) {
31*4d537eeaSYohann       rho[i] = J[i] * qw[i];
32*4d537eeaSYohann     }
33*4d537eeaSYohann     break;
34*4d537eeaSYohann   case 22:
35*4d537eeaSYohann     for (CeedInt i=0; i<Q; i++) {
36*4d537eeaSYohann       // 0 2
37*4d537eeaSYohann       // 1 3
38*4d537eeaSYohann       rho[i] = (J[i+Q*0]*J[i+Q*3] - J[i+Q*1]*J[i+Q*2]) * qw[i];
39*4d537eeaSYohann     }
40*4d537eeaSYohann     break;
41*4d537eeaSYohann   case 33:
42*4d537eeaSYohann     for (CeedInt i=0; i<Q; i++) {
43*4d537eeaSYohann       // 0 3 6
44*4d537eeaSYohann       // 1 4 7
45*4d537eeaSYohann       // 2 5 8
46*4d537eeaSYohann       rho[i] = (J[i+Q*0]*(J[i+Q*4]*J[i+Q*8] - J[i+Q*5]*J[i+Q*7]) -
47*4d537eeaSYohann                 J[i+Q*1]*(J[i+Q*3]*J[i+Q*8] - J[i+Q*5]*J[i+Q*6]) +
48*4d537eeaSYohann                 J[i+Q*2]*(J[i+Q*3]*J[i+Q*7] - J[i+Q*4]*J[i+Q*6])) * qw[i];
49*4d537eeaSYohann     }
50*4d537eeaSYohann     break;
51*4d537eeaSYohann   }
52*4d537eeaSYohann   return 0;
53*4d537eeaSYohann }
54*4d537eeaSYohann 
55*4d537eeaSYohann /// libCEED Q-function for applying a mass operator
56*4d537eeaSYohann CEED_QFUNCTION(f_apply_mass)(void *ctx, const CeedInt Q,
57*4d537eeaSYohann                              const CeedScalar *const *in, CeedScalar *const *out) {
58*4d537eeaSYohann   const CeedScalar *u = in[0], *w = in[1];
59*4d537eeaSYohann   CeedScalar *v = out[0];
60*4d537eeaSYohann   for (CeedInt i=0; i<Q; i++) {
61*4d537eeaSYohann     v[i] = w[i] * u[i];
62*4d537eeaSYohann   }
63*4d537eeaSYohann   return 0;
64*4d537eeaSYohann }
65