xref: /honee/qfunctions/velocity_gradient_projection.h (revision 82fc53c502e7fe487bacbde9162ca5e5bed042f3)
1*82fc53c5SJames Wright // Copyright (c) 2017-2023, Lawrence Livermore National Security, LLC and other CEED contributors.
2*82fc53c5SJames Wright // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
3*82fc53c5SJames Wright //
4*82fc53c5SJames Wright // SPDX-License-Identifier: BSD-2-Clause
5*82fc53c5SJames Wright //
6*82fc53c5SJames Wright // This file is part of CEED:  http://github.com/ceed
7*82fc53c5SJames Wright 
8*82fc53c5SJames Wright #ifndef velocity_gradient_projection_h
9*82fc53c5SJames Wright #define velocity_gradient_projection_h
10*82fc53c5SJames Wright 
11*82fc53c5SJames Wright #include <ceed.h>
12*82fc53c5SJames Wright 
13*82fc53c5SJames Wright #include "newtonian_state.h"
14*82fc53c5SJames Wright #include "newtonian_types.h"
15*82fc53c5SJames Wright #include "utils.h"
16*82fc53c5SJames Wright 
17*82fc53c5SJames Wright CEED_QFUNCTION_HELPER int VelocityGradientProjectionRHS(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out,
18*82fc53c5SJames Wright                                                         StateFromQi_t StateFromQi, StateFromQi_fwd_t StateFromQi_fwd) {
19*82fc53c5SJames Wright   const CeedScalar(*q)[CEED_Q_VLA]         = (const CeedScalar(*)[CEED_Q_VLA])in[0];
20*82fc53c5SJames Wright   const CeedScalar(*Grad_q)[5][CEED_Q_VLA] = (const CeedScalar(*)[5][CEED_Q_VLA])in[1];
21*82fc53c5SJames Wright   const CeedScalar(*q_data)[CEED_Q_VLA]    = (const CeedScalar(*)[CEED_Q_VLA])in[2];
22*82fc53c5SJames Wright   const CeedScalar(*x)[CEED_Q_VLA]         = (const CeedScalar(*)[CEED_Q_VLA])in[3];
23*82fc53c5SJames Wright   CeedScalar(*v)[CEED_Q_VLA]               = (CeedScalar(*)[CEED_Q_VLA])out[0];
24*82fc53c5SJames Wright 
25*82fc53c5SJames Wright   NewtonianIdealGasContext context = (NewtonianIdealGasContext)ctx;
26*82fc53c5SJames Wright 
27*82fc53c5SJames Wright   CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
28*82fc53c5SJames Wright     const CeedScalar qi[5]      = {q[0][i], q[1][i], q[2][i], q[3][i], q[4][i]};
29*82fc53c5SJames Wright     const CeedScalar x_i[3]     = {x[0][i], x[1][i], x[2][i]};
30*82fc53c5SJames Wright     const CeedScalar wdetJ      = q_data[0][i];
31*82fc53c5SJames Wright     const CeedScalar dXdx[3][3] = {
32*82fc53c5SJames Wright         {q_data[1][i], q_data[2][i], q_data[3][i]},
33*82fc53c5SJames Wright         {q_data[4][i], q_data[5][i], q_data[6][i]},
34*82fc53c5SJames Wright         {q_data[7][i], q_data[8][i], q_data[9][i]}
35*82fc53c5SJames Wright     };
36*82fc53c5SJames Wright 
37*82fc53c5SJames Wright     const State s = StateFromQi(context, qi, x_i);
38*82fc53c5SJames Wright     State       grad_s[3];
39*82fc53c5SJames Wright     for (CeedInt j = 0; j < 3; j++) {
40*82fc53c5SJames Wright       CeedScalar dx_i[3] = {0}, dqi[5];
41*82fc53c5SJames Wright       for (CeedInt k = 0; k < 5; k++) {
42*82fc53c5SJames Wright         dqi[k] = Grad_q[0][k][i] * dXdx[0][j] + Grad_q[1][k][i] * dXdx[1][j] + Grad_q[2][k][i] * dXdx[2][j];
43*82fc53c5SJames Wright       }
44*82fc53c5SJames Wright       dx_i[j]   = 1.;
45*82fc53c5SJames Wright       grad_s[j] = StateFromQi_fwd(context, s, dqi, x_i, dx_i);
46*82fc53c5SJames Wright     }
47*82fc53c5SJames Wright 
48*82fc53c5SJames Wright     CeedScalar grad_velocity[3][3];
49*82fc53c5SJames Wright     VelocityGradient(grad_s, grad_velocity);
50*82fc53c5SJames Wright 
51*82fc53c5SJames Wright     for (CeedInt j = 0; j < 3; j++) {
52*82fc53c5SJames Wright       for (CeedInt k = 0; k < 3; k++) {
53*82fc53c5SJames Wright         v[j * 3 + k][i] = wdetJ * grad_velocity[j][k];
54*82fc53c5SJames Wright       }
55*82fc53c5SJames Wright     }
56*82fc53c5SJames Wright   }
57*82fc53c5SJames Wright   return 0;
58*82fc53c5SJames Wright }
59*82fc53c5SJames Wright 
60*82fc53c5SJames Wright CEED_QFUNCTION(VelocityGradientProjectionRHS_Conserv)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
61*82fc53c5SJames Wright   return VelocityGradientProjectionRHS(ctx, Q, in, out, StateFromU, StateFromU_fwd);
62*82fc53c5SJames Wright }
63*82fc53c5SJames Wright 
64*82fc53c5SJames Wright CEED_QFUNCTION(VelocityGradientProjectionRHS_Prim)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
65*82fc53c5SJames Wright   return VelocityGradientProjectionRHS(ctx, Q, in, out, StateFromY, StateFromY_fwd);
66*82fc53c5SJames Wright }
67*82fc53c5SJames Wright #endif  // velocity_gradient_projection_h
68