xref: /libCEED/examples/fluids/qfunctions/velocity_gradient_projection.h (revision 32c47fae8e6a593fbb44be457fff64bf95e2e7f4)
1 // Copyright (c) 2017-2023, 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 velocity_gradient_projection_h
9 #define velocity_gradient_projection_h
10 
11 #include <ceed.h>
12 
13 #include "newtonian_state.h"
14 #include "newtonian_types.h"
15 #include "utils.h"
16 
17 CEED_QFUNCTION_HELPER int VelocityGradientProjectionRHS(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out,
18                                                         StateVariable state_var) {
19   const CeedScalar(*q)[CEED_Q_VLA]         = (const CeedScalar(*)[CEED_Q_VLA])in[0];
20   const CeedScalar(*Grad_q)[5][CEED_Q_VLA] = (const CeedScalar(*)[5][CEED_Q_VLA])in[1];
21   const CeedScalar(*q_data)                = in[2];
22   CeedScalar(*v)[CEED_Q_VLA]               = (CeedScalar(*)[CEED_Q_VLA])out[0];
23 
24   NewtonianIdealGasContext context = (NewtonianIdealGasContext)ctx;
25 
26   CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
27     const CeedScalar qi[5] = {q[0][i], q[1][i], q[2][i], q[3][i], q[4][i]};
28     CeedScalar       wdetJ, dXdx[3][3];
29     QdataUnpack_3D(Q, i, q_data, &wdetJ, dXdx);
30 
31     const State s = StateFromQ(context, qi, state_var);
32     State       grad_s[3];
33     StatePhysicalGradientFromReference(Q, i, context, s, state_var, (CeedScalar *)Grad_q, dXdx, grad_s);
34 
35     CeedScalar grad_velocity[3][3];
36     VelocityGradient(grad_s, grad_velocity);
37 
38     for (CeedInt j = 0; j < 3; j++) {
39       for (CeedInt k = 0; k < 3; k++) {
40         v[j * 3 + k][i] = wdetJ * grad_velocity[j][k];
41       }
42     }
43   }
44   return 0;
45 }
46 
47 CEED_QFUNCTION(VelocityGradientProjectionRHS_Conserv)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
48   return VelocityGradientProjectionRHS(ctx, Q, in, out, STATEVAR_CONSERVATIVE);
49 }
50 
51 CEED_QFUNCTION(VelocityGradientProjectionRHS_Prim)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
52   return VelocityGradientProjectionRHS(ctx, Q, in, out, STATEVAR_PRIMITIVE);
53 }
54 #endif  // velocity_gradient_projection_h
55