xref: /honee/qfunctions/velocity_gradient_projection.h (revision 8fff8293bda7e99146a6c5277de307a65038caa0)
182fc53c5SJames Wright // Copyright (c) 2017-2023, Lawrence Livermore National Security, LLC and other CEED contributors.
282fc53c5SJames Wright // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
382fc53c5SJames Wright //
482fc53c5SJames Wright // SPDX-License-Identifier: BSD-2-Clause
582fc53c5SJames Wright //
682fc53c5SJames Wright // This file is part of CEED:  http://github.com/ceed
782fc53c5SJames Wright 
882fc53c5SJames Wright #ifndef velocity_gradient_projection_h
982fc53c5SJames Wright #define velocity_gradient_projection_h
1082fc53c5SJames Wright 
1182fc53c5SJames Wright #include <ceed.h>
1282fc53c5SJames Wright 
1382fc53c5SJames Wright #include "newtonian_state.h"
1482fc53c5SJames Wright #include "newtonian_types.h"
1582fc53c5SJames Wright #include "utils.h"
1682fc53c5SJames Wright 
1782fc53c5SJames Wright CEED_QFUNCTION_HELPER int VelocityGradientProjectionRHS(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out,
18*8fff8293SJames Wright                                                         StateVariable state_var) {
1982fc53c5SJames Wright   const CeedScalar(*q)[CEED_Q_VLA]         = (const CeedScalar(*)[CEED_Q_VLA])in[0];
2082fc53c5SJames Wright   const CeedScalar(*Grad_q)[5][CEED_Q_VLA] = (const CeedScalar(*)[5][CEED_Q_VLA])in[1];
2182fc53c5SJames Wright   const CeedScalar(*q_data)[CEED_Q_VLA]    = (const CeedScalar(*)[CEED_Q_VLA])in[2];
2282fc53c5SJames Wright   const CeedScalar(*x)[CEED_Q_VLA]         = (const CeedScalar(*)[CEED_Q_VLA])in[3];
2382fc53c5SJames Wright   CeedScalar(*v)[CEED_Q_VLA]               = (CeedScalar(*)[CEED_Q_VLA])out[0];
2482fc53c5SJames Wright 
2582fc53c5SJames Wright   NewtonianIdealGasContext context = (NewtonianIdealGasContext)ctx;
2682fc53c5SJames Wright 
2782fc53c5SJames Wright   CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
2882fc53c5SJames Wright     const CeedScalar qi[5]      = {q[0][i], q[1][i], q[2][i], q[3][i], q[4][i]};
2982fc53c5SJames Wright     const CeedScalar x_i[3]     = {x[0][i], x[1][i], x[2][i]};
3082fc53c5SJames Wright     const CeedScalar wdetJ      = q_data[0][i];
3182fc53c5SJames Wright     const CeedScalar dXdx[3][3] = {
3282fc53c5SJames Wright         {q_data[1][i], q_data[2][i], q_data[3][i]},
3382fc53c5SJames Wright         {q_data[4][i], q_data[5][i], q_data[6][i]},
3482fc53c5SJames Wright         {q_data[7][i], q_data[8][i], q_data[9][i]}
3582fc53c5SJames Wright     };
3682fc53c5SJames Wright 
37*8fff8293SJames Wright     const State s = StateFromQ(context, qi, x_i, state_var);
3882fc53c5SJames Wright     State       grad_s[3];
3982fc53c5SJames Wright     for (CeedInt j = 0; j < 3; j++) {
4082fc53c5SJames Wright       CeedScalar dx_i[3] = {0}, dqi[5];
4182fc53c5SJames Wright       for (CeedInt k = 0; k < 5; k++) {
4282fc53c5SJames 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];
4382fc53c5SJames Wright       }
4482fc53c5SJames Wright       dx_i[j]   = 1.;
45*8fff8293SJames Wright       grad_s[j] = StateFromQ_fwd(context, s, dqi, x_i, dx_i, state_var);
4682fc53c5SJames Wright     }
4782fc53c5SJames Wright 
4882fc53c5SJames Wright     CeedScalar grad_velocity[3][3];
4982fc53c5SJames Wright     VelocityGradient(grad_s, grad_velocity);
5082fc53c5SJames Wright 
5182fc53c5SJames Wright     for (CeedInt j = 0; j < 3; j++) {
5282fc53c5SJames Wright       for (CeedInt k = 0; k < 3; k++) {
5382fc53c5SJames Wright         v[j * 3 + k][i] = wdetJ * grad_velocity[j][k];
5482fc53c5SJames Wright       }
5582fc53c5SJames Wright     }
5682fc53c5SJames Wright   }
5782fc53c5SJames Wright   return 0;
5882fc53c5SJames Wright }
5982fc53c5SJames Wright 
6082fc53c5SJames Wright CEED_QFUNCTION(VelocityGradientProjectionRHS_Conserv)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
61*8fff8293SJames Wright   return VelocityGradientProjectionRHS(ctx, Q, in, out, STATEVAR_CONSERVATIVE);
6282fc53c5SJames Wright }
6382fc53c5SJames Wright 
6482fc53c5SJames Wright CEED_QFUNCTION(VelocityGradientProjectionRHS_Prim)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
65*8fff8293SJames Wright   return VelocityGradientProjectionRHS(ctx, Q, in, out, STATEVAR_PRIMITIVE);
6682fc53c5SJames Wright }
6782fc53c5SJames Wright #endif  // velocity_gradient_projection_h
68