xref: /libCEED/examples/ceed/ex1-volume-f-c.h (revision 53ee81eed7fe6a54158b819b478dad66ca478dc3)
1 // Copyright (c) 2017-2026, 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 #include <ceed/types.h>
9 
10 /// libCEED Q-function for building quadrature data for a mass operator
11 CEED_QFUNCTION(build_mass)(void *ctx, const CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
12   long long int *build_data = (long long int *)ctx;
13 
14   // in[0] is Jacobians with shape [dim, dim, Q]
15   // in[1] is quadrature weights with shape [1, Q]
16   const CeedScalar *w      = in[1];
17   CeedScalar       *q_data = out[0];
18 
19   switch (build_data[0] + 10 * build_data[1]) {
20     case 11: {
21       const CeedScalar(*J)[1][CEED_Q_VLA] = (const CeedScalar(*)[1][CEED_Q_VLA])in[0];
22 
23       // Quadrature Point Loop
24       CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { q_data[i] = J[0][0][i] * w[i]; }  // End of Quadrature Point Loop
25     } break;
26     case 22: {
27       const CeedScalar(*J)[2][CEED_Q_VLA] = (const CeedScalar(*)[2][CEED_Q_VLA])in[0];
28 
29       // Quadrature Point Loop
30       CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
31         q_data[i] = (J[0][0][i] * J[1][1][i] - J[0][1][i] * J[1][0][i]) * w[i];
32       }  // End of Quadrature Point Loop
33     } break;
34     case 33: {
35       const CeedScalar(*J)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[0];
36 
37       // Quadrature Point Loop
38       CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
39         q_data[i] =
40             (J[0][0][i] * (J[1][1][i] * J[2][2][i] - J[1][2][i] * J[2][1][i]) - J[0][1][i] * (J[1][0][i] * J[2][2][i] - J[1][2][i] * J[2][0][i]) +
41              J[0][2][i] * (J[1][0][i] * J[2][1][i] - J[1][1][i] * J[2][0][i])) *
42             w[i];
43       }  // End of Quadrature Point Loop
44     } break;
45   }
46   return CEED_ERROR_SUCCESS;
47 }
48 
49 /// libCEED Q-function for applying a mass operator
50 CEED_QFUNCTION(apply_mass)(void *ctx, const CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
51   // in[0], out[0] are solution variables with shape [1, Q]
52   // in[1] is quadrature data with shape [1, Q]
53   const CeedScalar *u = in[0], *q_data = in[1];
54   CeedScalar       *v = out[0];
55 
56   // Quadrature Point Loop
57   CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { v[i] = q_data[i] * u[i]; }  // End of Quadrature Point Loop
58   return CEED_ERROR_SUCCESS;
59 }
60