xref: /honee/qfunctions/monitor_totalkineticenergy.h (revision 475f0cac5d40259768f4556cf888e8f2448554cb)
125125139SJames Wright // SPDX-FileCopyrightText: Copyright (c) 2017-2024, HONEE contributors.
225125139SJames Wright // SPDX-License-Identifier: Apache-2.0 OR BSD-2-Clause
325125139SJames Wright 
425125139SJames Wright #include <ceed/types.h>
525125139SJames Wright #include "newtonian_state.h"
625125139SJames Wright 
MonitorTotalKineticEnergy(void * ctx,CeedInt Q,const CeedScalar * const * in,CeedScalar * const * out,StateVariable state_var)725125139SJames Wright CEED_QFUNCTION_HELPER int MonitorTotalKineticEnergy(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out,
825125139SJames Wright                                                     StateVariable state_var) {
9*cde3d787SJames Wright   const NewtonianIdealGasContext newt_ctx = (const NewtonianIdealGasContext)ctx;
1025125139SJames Wright   const CeedScalar(*q)[CEED_Q_VLA]        = (const CeedScalar(*)[CEED_Q_VLA])in[0];
1125125139SJames Wright   const CeedScalar(*Grad_q)               = in[1];
1225125139SJames Wright   const CeedScalar(*q_data)               = in[2];
1325125139SJames Wright   CeedScalar(*v)[CEED_Q_VLA]              = (CeedScalar(*)[CEED_Q_VLA])out[0];
1425125139SJames Wright 
15*cde3d787SJames Wright   const NewtonianIGProperties gas = newt_ctx->gas;
1625125139SJames Wright   CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
1725125139SJames Wright     const CeedScalar qi[5] = {q[0][i], q[1][i], q[2][i], q[3][i], q[4][i]};
1825125139SJames Wright     const State      s     = StateFromQ(gas, qi, state_var);
1925125139SJames Wright     CeedScalar       wdetJ, dXdx[3][3], vorticity[3], kmstrain_rate[6], strain_rate[3][3];
2025125139SJames Wright     State            grad_s[3];
2125125139SJames Wright 
2225125139SJames Wright     QdataUnpack_3D(Q, i, q_data, &wdetJ, dXdx);
2325125139SJames Wright     StatePhysicalGradientFromReference(Q, i, gas, s, state_var, Grad_q, dXdx, grad_s);
2425125139SJames Wright 
2525125139SJames Wright     v[0][i] = wdetJ * 0.5 * s.U.density * Dot3(s.Y.velocity, s.Y.velocity);
2625125139SJames Wright     KMStrainRate_State(grad_s, kmstrain_rate);
2725125139SJames Wright     {  // See Kundu eq. 4.60
2825125139SJames Wright       CeedScalar div_u = kmstrain_rate[0] + kmstrain_rate[1] + kmstrain_rate[2];
2925125139SJames Wright       KMUnpack(kmstrain_rate, strain_rate);
30*cde3d787SJames Wright       v[1][i] = wdetJ * -2 * gas.mu * DotN((CeedScalar *)strain_rate, (CeedScalar *)strain_rate, 9);
31*cde3d787SJames Wright       v[2][i] = wdetJ * -gas.lambda * gas.mu * Square(div_u);
3225125139SJames Wright       v[3][i] = wdetJ * s.Y.pressure * div_u;
3325125139SJames Wright     }
3425125139SJames Wright     Vorticity(grad_s, vorticity);
35*cde3d787SJames Wright     v[4][i] = wdetJ * gas.mu * Dot3(vorticity, vorticity);
3625125139SJames Wright   }
3725125139SJames Wright   return 0;
3825125139SJames Wright }
3925125139SJames Wright 
MonitorTotalKineticEnergy_Conserv(void * ctx,CeedInt Q,const CeedScalar * const * in,CeedScalar * const * out)4025125139SJames Wright CEED_QFUNCTION(MonitorTotalKineticEnergy_Conserv)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
4125125139SJames Wright   return MonitorTotalKineticEnergy(ctx, Q, in, out, STATEVAR_CONSERVATIVE);
4225125139SJames Wright }
4325125139SJames Wright 
MonitorTotalKineticEnergy_Prim(void * ctx,CeedInt Q,const CeedScalar * const * in,CeedScalar * const * out)4425125139SJames Wright CEED_QFUNCTION(MonitorTotalKineticEnergy_Prim)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
4525125139SJames Wright   return MonitorTotalKineticEnergy(ctx, Q, in, out, STATEVAR_PRIMITIVE);
4625125139SJames Wright }
4725125139SJames Wright 
MonitorTotalKineticEnergy_Entropy(void * ctx,CeedInt Q,const CeedScalar * const * in,CeedScalar * const * out)4825125139SJames Wright CEED_QFUNCTION(MonitorTotalKineticEnergy_Entropy)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
4925125139SJames Wright   return MonitorTotalKineticEnergy(ctx, Q, in, out, STATEVAR_ENTROPY);
5025125139SJames Wright }
51