xref: /libCEED/examples/ceed/ex1-volume.h (revision 0d627ac128dbf360e78b18bad1cfd2089ff3d6d8)
1 // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors.
2 // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
3 //
4 // SPDX-License-Identifier: BSD-2-Clause
5 //
6 // This file is part of CEED:  http://github.com/ceed
7 
8 #ifndef ex1_volume_h
9 #define ex1_volume_h
10 
11 #include <ceed.h>
12 
13 /// A structure used to pass additional data to f_build_mass
14 struct BuildContext { CeedInt dim, space_dim; };
15 
16 /// libCEED Q-function for building quadrature data for a mass operator
17 CEED_QFUNCTION(f_build_mass)(void *ctx, const CeedInt Q,
18                              const CeedScalar *const *in, CeedScalar *const *out) {
19   // in[0] is Jacobians with shape [dim, nc=dim, Q]
20   // in[1] is quadrature weights, size (Q)
21   struct BuildContext *bc = (struct BuildContext *)ctx;
22   const CeedScalar *J = in[0], *w = in[1];
23   CeedScalar *q_data = out[0];
24 
25   switch (bc->dim + 10*bc->space_dim) {
26   case 11:
27     // Quadrature Point Loop
28     CeedPragmaSIMD
29     for (CeedInt i=0; i<Q; i++) {
30       q_data[i] = J[i] * w[i];
31     } // End of Quadrature Point Loop
32     break;
33   case 22:
34     // Quadrature Point Loop
35     CeedPragmaSIMD
36     for (CeedInt i=0; i<Q; i++) {
37       // 0 2
38       // 1 3
39       q_data[i] = (J[i+Q*0]*J[i+Q*3] - J[i+Q*1]*J[i+Q*2]) * w[i];
40     } // End of Quadrature Point Loop
41     break;
42   case 33:
43     // Quadrature Point Loop
44     CeedPragmaSIMD
45     for (CeedInt i=0; i<Q; i++) {
46       // 0 3 6
47       // 1 4 7
48       // 2 5 8
49       q_data[i] = (J[i+Q*0]*(J[i+Q*4]*J[i+Q*8] - J[i+Q*5]*J[i+Q*7]) -
50                    J[i+Q*1]*(J[i+Q*3]*J[i+Q*8] - J[i+Q*5]*J[i+Q*6]) +
51                    J[i+Q*2]*(J[i+Q*3]*J[i+Q*7] - J[i+Q*4]*J[i+Q*6])) * w[i];
52     } // End of Quadrature Point Loop
53     break;
54   }
55   return 0;
56 }
57 
58 /// libCEED Q-function for applying a mass operator
59 CEED_QFUNCTION(f_apply_mass)(void *ctx, const CeedInt Q,
60                              const CeedScalar *const *in, CeedScalar *const *out) {
61   const CeedScalar *u = in[0], *q_data = in[1];
62   CeedScalar *v = out[0];
63 
64   // Quadrature Point Loop
65   CeedPragmaSIMD
66   for (CeedInt i=0; i<Q; i++) {
67     v[i] = q_data[i] * u[i];
68   } // End of Quadrature Point Loop
69   return 0;
70 }
71 
72 #endif // ex1_volume_h
73