1ae2b091fSJames Wright // SPDX-FileCopyrightText: Copyright (c) 2017-2024, HONEE contributors.
2ae2b091fSJames Wright // SPDX-License-Identifier: Apache-2.0 OR BSD-2-Clause
33e17a7a1SJames Wright #include <ceed/types.h>
482fc53c5SJames Wright
582fc53c5SJames Wright #include "newtonian_state.h"
682fc53c5SJames Wright #include "newtonian_types.h"
782fc53c5SJames Wright #include "utils.h"
882fc53c5SJames Wright
VelocityGradientProjectionRHS(void * ctx,CeedInt Q,const CeedScalar * const * in,CeedScalar * const * out,StateVariable state_var)982fc53c5SJames Wright CEED_QFUNCTION_HELPER int VelocityGradientProjectionRHS(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out,
108fff8293SJames Wright StateVariable state_var) {
1182fc53c5SJames Wright const CeedScalar(*q)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0];
1282fc53c5SJames Wright const CeedScalar(*Grad_q)[5][CEED_Q_VLA] = (const CeedScalar(*)[5][CEED_Q_VLA])in[1];
13ade49511SJames Wright const CeedScalar(*q_data) = in[2];
1482fc53c5SJames Wright CeedScalar(*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];
1582fc53c5SJames Wright
16*cde3d787SJames Wright NewtonianIGProperties gas = ((NewtonianIdealGasContext)ctx)->gas;
1782fc53c5SJames Wright
1882fc53c5SJames Wright CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
1982fc53c5SJames Wright const CeedScalar qi[5] = {q[0][i], q[1][i], q[2][i], q[3][i], q[4][i]};
20ade49511SJames Wright CeedScalar wdetJ, dXdx[3][3];
21ade49511SJames Wright QdataUnpack_3D(Q, i, q_data, &wdetJ, dXdx);
2282fc53c5SJames Wright
23*cde3d787SJames Wright const State s = StateFromQ(gas, qi, state_var);
2482fc53c5SJames Wright State grad_s[3];
25*cde3d787SJames Wright StatePhysicalGradientFromReference(Q, i, gas, s, state_var, (CeedScalar *)Grad_q, dXdx, grad_s);
2682fc53c5SJames Wright
2782fc53c5SJames Wright CeedScalar grad_velocity[3][3];
2882fc53c5SJames Wright VelocityGradient(grad_s, grad_velocity);
2982fc53c5SJames Wright
3082fc53c5SJames Wright for (CeedInt j = 0; j < 3; j++) {
3182fc53c5SJames Wright for (CeedInt k = 0; k < 3; k++) {
3282fc53c5SJames Wright v[j * 3 + k][i] = wdetJ * grad_velocity[j][k];
3382fc53c5SJames Wright }
3482fc53c5SJames Wright }
3582fc53c5SJames Wright }
3682fc53c5SJames Wright return 0;
3782fc53c5SJames Wright }
3882fc53c5SJames Wright
VelocityGradientProjectionRHS_Conserv(void * ctx,CeedInt Q,const CeedScalar * const * in,CeedScalar * const * out)3982fc53c5SJames Wright CEED_QFUNCTION(VelocityGradientProjectionRHS_Conserv)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
408fff8293SJames Wright return VelocityGradientProjectionRHS(ctx, Q, in, out, STATEVAR_CONSERVATIVE);
4182fc53c5SJames Wright }
4282fc53c5SJames Wright
VelocityGradientProjectionRHS_Prim(void * ctx,CeedInt Q,const CeedScalar * const * in,CeedScalar * const * out)4382fc53c5SJames Wright CEED_QFUNCTION(VelocityGradientProjectionRHS_Prim)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
448fff8293SJames Wright return VelocityGradientProjectionRHS(ctx, Q, in, out, STATEVAR_PRIMITIVE);
4582fc53c5SJames Wright }
469b103f75SJames Wright
VelocityGradientProjectionRHS_Entropy(void * ctx,CeedInt Q,const CeedScalar * const * in,CeedScalar * const * out)479b103f75SJames Wright CEED_QFUNCTION(VelocityGradientProjectionRHS_Entropy)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
489b103f75SJames Wright return VelocityGradientProjectionRHS(ctx, Q, in, out, STATEVAR_ENTROPY);
499b103f75SJames Wright }
50