xref: /libCEED/examples/ceed/ex1-volume.h (revision 82946b17cb1e5ff4e735292ffaa6377862cf1d29)
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 /// A structure used to pass additional data to f_build_mass
18 struct BuildContext { CeedInt dim, space_dim; };
19 
20 /// libCEED Q-function for building quadrature data for a mass operator
21 CEED_QFUNCTION(f_build_mass)(void *ctx, const CeedInt Q,
22                              const CeedScalar *const *in, CeedScalar *const *out) {
23   // in[0] is Jacobians with shape [dim, nc=dim, Q]
24   // in[1] is quadrature weights, size (Q)
25   struct BuildContext *bc = (struct BuildContext *)ctx;
26   const CeedScalar *J = in[0], *w = in[1];
27   CeedScalar *qdata = out[0];
28 
29   switch (bc->dim + 10*bc->space_dim) {
30   case 11:
31     // Quadrature Point Loop
32     CeedPragmaSIMD
33     for (CeedInt i=0; i<Q; i++) {
34       qdata[i] = J[i] * w[i];
35     } // End of Quadrature Point Loop
36     break;
37   case 22:
38     // Quadrature Point Loop
39     CeedPragmaSIMD
40     for (CeedInt i=0; i<Q; i++) {
41       // 0 2
42       // 1 3
43       qdata[i] = (J[i+Q*0]*J[i+Q*3] - J[i+Q*1]*J[i+Q*2]) * w[i];
44     } // End of Quadrature Point Loop
45     break;
46   case 33:
47     // Quadrature Point Loop
48     CeedPragmaSIMD
49     for (CeedInt i=0; i<Q; i++) {
50       // 0 3 6
51       // 1 4 7
52       // 2 5 8
53       qdata[i] = (J[i+Q*0]*(J[i+Q*4]*J[i+Q*8] - J[i+Q*5]*J[i+Q*7]) -
54                   J[i+Q*1]*(J[i+Q*3]*J[i+Q*8] - J[i+Q*5]*J[i+Q*6]) +
55                   J[i+Q*2]*(J[i+Q*3]*J[i+Q*7] - J[i+Q*4]*J[i+Q*6])) * w[i];
56     } // End of Quadrature Point Loop
57     break;
58   }
59   return 0;
60 }
61 
62 /// libCEED Q-function for applying a mass operator
63 CEED_QFUNCTION(f_apply_mass)(void *ctx, const CeedInt Q,
64                              const CeedScalar *const *in, CeedScalar *const *out) {
65   const CeedScalar *u = in[0], *qdata = in[1];
66   CeedScalar *v = out[0];
67 
68   // Quadrature Point Loop
69   CeedPragmaSIMD
70   for (CeedInt i=0; i<Q; i++) {
71     v[i] = qdata[i] * u[i];
72   } // End of Quadrature Point Loop
73   return 0;
74 }
75