xref: /libCEED/examples/fluids/qfunctions/velocity_gradient_projection.h (revision 5aed82e4fa97acf4ba24a7f10a35f5303a6798e0)
1*5aed82e4SJeremy L Thompson // Copyright (c) 2017-2024, Lawrence Livermore National Security, LLC and other CEED contributors.
2df1a6dc8SJames Wright // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
3df1a6dc8SJames Wright //
4df1a6dc8SJames Wright // SPDX-License-Identifier: BSD-2-Clause
5df1a6dc8SJames Wright //
6df1a6dc8SJames Wright // This file is part of CEED:  http://github.com/ceed
7df1a6dc8SJames Wright 
8df1a6dc8SJames Wright #ifndef velocity_gradient_projection_h
9df1a6dc8SJames Wright #define velocity_gradient_projection_h
10df1a6dc8SJames Wright 
11df1a6dc8SJames Wright #include <ceed.h>
12df1a6dc8SJames Wright 
13df1a6dc8SJames Wright #include "newtonian_state.h"
14df1a6dc8SJames Wright #include "newtonian_types.h"
15df1a6dc8SJames Wright #include "utils.h"
16df1a6dc8SJames Wright 
17df1a6dc8SJames Wright CEED_QFUNCTION_HELPER int VelocityGradientProjectionRHS(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out,
18be91e165SJames Wright                                                         StateVariable state_var) {
19df1a6dc8SJames Wright   const CeedScalar(*q)[CEED_Q_VLA]         = (const CeedScalar(*)[CEED_Q_VLA])in[0];
20df1a6dc8SJames Wright   const CeedScalar(*Grad_q)[5][CEED_Q_VLA] = (const CeedScalar(*)[5][CEED_Q_VLA])in[1];
21f3e15844SJames Wright   const CeedScalar(*q_data)                = in[2];
22df1a6dc8SJames Wright   CeedScalar(*v)[CEED_Q_VLA]               = (CeedScalar(*)[CEED_Q_VLA])out[0];
23df1a6dc8SJames Wright 
24df1a6dc8SJames Wright   NewtonianIdealGasContext context = (NewtonianIdealGasContext)ctx;
25df1a6dc8SJames Wright 
26df1a6dc8SJames Wright   CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
27df1a6dc8SJames Wright     const CeedScalar qi[5] = {q[0][i], q[1][i], q[2][i], q[3][i], q[4][i]};
28f3e15844SJames Wright     CeedScalar       wdetJ, dXdx[3][3];
29f3e15844SJames Wright     QdataUnpack_3D(Q, i, q_data, &wdetJ, dXdx);
30df1a6dc8SJames Wright 
313bd61617SKenneth E. Jansen     const State s = StateFromQ(context, qi, state_var);
32df1a6dc8SJames Wright     State       grad_s[3];
334c493a33SJames Wright     StatePhysicalGradientFromReference(Q, i, context, s, state_var, (CeedScalar *)Grad_q, dXdx, grad_s);
34df1a6dc8SJames Wright 
35df1a6dc8SJames Wright     CeedScalar grad_velocity[3][3];
36df1a6dc8SJames Wright     VelocityGradient(grad_s, grad_velocity);
37df1a6dc8SJames Wright 
38df1a6dc8SJames Wright     for (CeedInt j = 0; j < 3; j++) {
39df1a6dc8SJames Wright       for (CeedInt k = 0; k < 3; k++) {
40df1a6dc8SJames Wright         v[j * 3 + k][i] = wdetJ * grad_velocity[j][k];
41df1a6dc8SJames Wright       }
42df1a6dc8SJames Wright     }
43df1a6dc8SJames Wright   }
44df1a6dc8SJames Wright   return 0;
45df1a6dc8SJames Wright }
46df1a6dc8SJames Wright 
47df1a6dc8SJames Wright CEED_QFUNCTION(VelocityGradientProjectionRHS_Conserv)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
48be91e165SJames Wright   return VelocityGradientProjectionRHS(ctx, Q, in, out, STATEVAR_CONSERVATIVE);
49df1a6dc8SJames Wright }
50df1a6dc8SJames Wright 
51df1a6dc8SJames Wright CEED_QFUNCTION(VelocityGradientProjectionRHS_Prim)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
52be91e165SJames Wright   return VelocityGradientProjectionRHS(ctx, Q, in, out, STATEVAR_PRIMITIVE);
53df1a6dc8SJames Wright }
54df1a6dc8SJames Wright #endif  // velocity_gradient_projection_h
55