xref: /libCEED/examples/petsc/qfunctions/swarm/swarmmass.h (revision 5aed82e4fa97acf4ba24a7f10a35f5303a6798e0)
1 // Copyright (c) 2017-2024, 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 SWARM_MASS_H
9 #define SWARM_MASS_H
10 
11 #include <ceed.h>
12 
13 CEED_QFUNCTION(SetupMass)(void *ctx, const CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
14   const CeedScalar(*J)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[0];
15   const CeedScalar *w                 = in[1];
16   CeedScalar       *q_data            = out[0];
17 
18   // Quadrature point loop
19   CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
20     const CeedScalar B11 = J[1][1][i] * J[2][2][i] - J[1][2][i] * J[2][1][i];
21     const CeedScalar B12 = J[0][2][i] * J[2][1][i] - J[0][1][i] * J[2][2][i];
22     const CeedScalar B13 = J[0][1][i] * J[1][2][i] - J[0][2][i] * J[1][1][i];
23 
24     q_data[i] = w[i] * (J[0][0][i] * B11 + J[1][0][i] * B12 + J[2][0][i] * B13);
25   }
26   return 0;
27 }
28 
29 CEED_QFUNCTION(Mass)(void *ctx, const CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
30   const CeedScalar *rho            = (const CeedScalar *)in[0];
31   const CeedScalar(*u)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[1];
32   CeedScalar(*v)[CEED_Q_VLA]       = (CeedScalar(*)[CEED_Q_VLA])out[0];
33 
34   const CeedInt num_comp = *(CeedInt *)ctx;
35   // Quadrature point loop
36   CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
37     for (CeedInt j = 0; j < num_comp; j++) v[j][i] = rho[i] * u[j][i];
38   }
39   return 0;
40 }
41 
42 #endif  // SWARM_MASS_H
43