xref: /libCEED/examples/fluids/qfunctions/turb_spanstats.h (revision d4cc18453651bd0f94c1a2e078b2646a92dafdcc)
1*9ba83ac0SJeremy L Thompson // Copyright (c) 2017-2026, Lawrence Livermore National Security, LLC and other CEED contributors.
2729f4e9bSJames Wright // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
3729f4e9bSJames Wright //
4729f4e9bSJames Wright // SPDX-License-Identifier: BSD-2-Clause
5729f4e9bSJames Wright //
6729f4e9bSJames Wright // This file is part of CEED:  http://github.com/ceed
7c0b5abf0SJeremy L Thompson #include <ceed/types.h>
8729f4e9bSJames Wright 
9729f4e9bSJames Wright #include "newtonian_state.h"
103a4208e6SJames Wright #include "turb_stats_types.h"
11729f4e9bSJames Wright #include "utils.h"
12729f4e9bSJames Wright 
ChildStatsCollection(void * ctx,CeedInt Q,const CeedScalar * const * in,CeedScalar * const * out,StateVariable state_var)13be91e165SJames Wright CEED_QFUNCTION_HELPER int ChildStatsCollection(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out, StateVariable state_var) {
14729f4e9bSJames Wright   const CeedScalar(*q)[CEED_Q_VLA]      = (const CeedScalar(*)[CEED_Q_VLA])in[0];
15729f4e9bSJames Wright   const CeedScalar(*q_data)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[1];
16729f4e9bSJames Wright   CeedScalar(*v)[CEED_Q_VLA]            = (CeedScalar(*)[CEED_Q_VLA])out[0];
17729f4e9bSJames Wright 
18495b9769SJames Wright   Turbulence_SpanStatsContext context = (Turbulence_SpanStatsContext)ctx;
19495b9769SJames Wright   NewtonianIdealGasContext    gas     = &context->gas;
20495b9769SJames Wright   CeedScalar                  delta_t = context->solution_time - context->previous_time;
21729f4e9bSJames Wright 
22729f4e9bSJames Wright   CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
23495b9769SJames Wright     const CeedScalar wdetJ = q_data[0][i] * delta_t;
24729f4e9bSJames Wright 
25729f4e9bSJames Wright     const CeedScalar qi[5] = {q[0][i], q[1][i], q[2][i], q[3][i], q[4][i]};
263bd61617SKenneth E. Jansen     const State      s     = StateFromQ(gas, qi, state_var);
27729f4e9bSJames Wright 
283a4208e6SJames Wright     v[TURB_MEAN_DENSITY][i]                    = wdetJ * s.U.density;
293a4208e6SJames Wright     v[TURB_MEAN_PRESSURE][i]                   = wdetJ * s.Y.pressure;
303a4208e6SJames Wright     v[TURB_MEAN_PRESSURE_SQUARED][i]           = wdetJ * Square(s.Y.pressure);
313a4208e6SJames Wright     v[TURB_MEAN_PRESSURE_VELOCITY_X][i]        = wdetJ * s.Y.pressure * s.Y.velocity[0];
323a4208e6SJames Wright     v[TURB_MEAN_PRESSURE_VELOCITY_Y][i]        = wdetJ * s.Y.pressure * s.Y.velocity[1];
333a4208e6SJames Wright     v[TURB_MEAN_PRESSURE_VELOCITY_Z][i]        = wdetJ * s.Y.pressure * s.Y.velocity[2];
343a4208e6SJames Wright     v[TURB_MEAN_DENSITY_TEMPERATURE][i]        = wdetJ * s.U.density * s.Y.temperature;
353a4208e6SJames Wright     v[TURB_MEAN_DENSITY_TEMPERATURE_FLUX_X][i] = wdetJ * s.U.density * s.Y.temperature * s.Y.velocity[0];
363a4208e6SJames Wright     v[TURB_MEAN_DENSITY_TEMPERATURE_FLUX_Y][i] = wdetJ * s.U.density * s.Y.temperature * s.Y.velocity[1];
373a4208e6SJames Wright     v[TURB_MEAN_DENSITY_TEMPERATURE_FLUX_Z][i] = wdetJ * s.U.density * s.Y.temperature * s.Y.velocity[2];
383a4208e6SJames Wright     v[TURB_MEAN_MOMENTUM_X][i]                 = wdetJ * s.U.momentum[0];
393a4208e6SJames Wright     v[TURB_MEAN_MOMENTUM_Y][i]                 = wdetJ * s.U.momentum[1];
403a4208e6SJames Wright     v[TURB_MEAN_MOMENTUM_Z][i]                 = wdetJ * s.U.momentum[2];
413a4208e6SJames Wright     v[TURB_MEAN_MOMENTUMFLUX_XX][i]            = wdetJ * s.U.momentum[0] * s.Y.velocity[0];
423a4208e6SJames Wright     v[TURB_MEAN_MOMENTUMFLUX_YY][i]            = wdetJ * s.U.momentum[1] * s.Y.velocity[1];
433a4208e6SJames Wright     v[TURB_MEAN_MOMENTUMFLUX_ZZ][i]            = wdetJ * s.U.momentum[2] * s.Y.velocity[2];
443a4208e6SJames Wright     v[TURB_MEAN_MOMENTUMFLUX_YZ][i]            = wdetJ * s.U.momentum[1] * s.Y.velocity[2];
453a4208e6SJames Wright     v[TURB_MEAN_MOMENTUMFLUX_XZ][i]            = wdetJ * s.U.momentum[0] * s.Y.velocity[2];
463a4208e6SJames Wright     v[TURB_MEAN_MOMENTUMFLUX_XY][i]            = wdetJ * s.U.momentum[0] * s.Y.velocity[1];
473a4208e6SJames Wright     v[TURB_MEAN_VELOCITY_X][i]                 = wdetJ * s.Y.velocity[0];
483a4208e6SJames Wright     v[TURB_MEAN_VELOCITY_Y][i]                 = wdetJ * s.Y.velocity[1];
493a4208e6SJames Wright     v[TURB_MEAN_VELOCITY_Z][i]                 = wdetJ * s.Y.velocity[2];
50729f4e9bSJames Wright   }
51729f4e9bSJames Wright   return 0;
52729f4e9bSJames Wright }
53729f4e9bSJames Wright 
ChildStatsCollection_Conserv(void * ctx,CeedInt Q,const CeedScalar * const * in,CeedScalar * const * out)54729f4e9bSJames Wright CEED_QFUNCTION(ChildStatsCollection_Conserv)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
55be91e165SJames Wright   return ChildStatsCollection(ctx, Q, in, out, STATEVAR_CONSERVATIVE);
56729f4e9bSJames Wright }
57729f4e9bSJames Wright 
ChildStatsCollection_Prim(void * ctx,CeedInt Q,const CeedScalar * const * in,CeedScalar * const * out)58729f4e9bSJames Wright CEED_QFUNCTION(ChildStatsCollection_Prim)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
59be91e165SJames Wright   return ChildStatsCollection(ctx, Q, in, out, STATEVAR_PRIMITIVE);
60729f4e9bSJames Wright }
61729f4e9bSJames Wright 
ChildStatsCollection_Entropy(void * ctx,CeedInt Q,const CeedScalar * const * in,CeedScalar * const * out)62a2d72b6fSJames Wright CEED_QFUNCTION(ChildStatsCollection_Entropy)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
63a2d72b6fSJames Wright   return ChildStatsCollection(ctx, Q, in, out, STATEVAR_ENTROPY);
64a2d72b6fSJames Wright }
65a2d72b6fSJames Wright 
66823a1283SJames Wright // QFunctions for testing
ChildStatsCollectionTest_Exact(const CeedScalar x_i[3])67823a1283SJames Wright CEED_QFUNCTION_HELPER CeedScalar ChildStatsCollectionTest_Exact(const CeedScalar x_i[3]) { return x_i[0] + Square(x_i[1]); }
68823a1283SJames Wright 
ChildStatsCollectionMMSTest(void * ctx,CeedInt Q,const CeedScalar * const * in,CeedScalar * const * out)69b7d66439SJames Wright CEED_QFUNCTION(ChildStatsCollectionMMSTest)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
70729f4e9bSJames Wright   const CeedScalar(*q_data)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[1];
71729f4e9bSJames Wright   const CeedScalar(*x)[CEED_Q_VLA]      = (const CeedScalar(*)[CEED_Q_VLA])in[2];
72729f4e9bSJames Wright   CeedScalar(*v)[CEED_Q_VLA]            = (CeedScalar(*)[CEED_Q_VLA])out[0];
73729f4e9bSJames Wright 
74729f4e9bSJames Wright   NewtonianIdealGasContext context = (NewtonianIdealGasContext)ctx;
75729f4e9bSJames Wright   const CeedScalar         t       = context->time;
76729f4e9bSJames Wright 
77729f4e9bSJames Wright   CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
78729f4e9bSJames Wright     const CeedScalar wdetJ  = q_data[0][i];
79729f4e9bSJames Wright     const CeedScalar x_i[3] = {x[0][i], x[1][i], x[2][i]};
80729f4e9bSJames Wright 
81823a1283SJames Wright     // set spanwise domain to [0,1] and integrate from t \in [0,1] to recover exact solution
82823a1283SJames Wright     v[0][i] = wdetJ * (ChildStatsCollectionTest_Exact(x_i) + t - 0.5) * 4 * Cube(x_i[2]);
83823a1283SJames Wright     for (int j = 1; j < 22; j++) v[j][i] = 0;
84823a1283SJames Wright   }
85823a1283SJames Wright   return 0;
86823a1283SJames Wright }
87823a1283SJames Wright 
ChildStatsCollectionMMSTest_Error(void * ctx,CeedInt Q,const CeedScalar * const * in,CeedScalar * const * out)88b7d66439SJames Wright CEED_QFUNCTION(ChildStatsCollectionMMSTest_Error)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
89823a1283SJames Wright   const CeedScalar(*q)[CEED_Q_VLA]      = (const CeedScalar(*)[CEED_Q_VLA])in[0];
90823a1283SJames Wright   const CeedScalar(*q_data)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[1];
91823a1283SJames Wright   const CeedScalar(*x)[CEED_Q_VLA]      = (const CeedScalar(*)[CEED_Q_VLA])in[2];
92823a1283SJames Wright   CeedScalar(*v)[CEED_Q_VLA]            = (CeedScalar(*)[CEED_Q_VLA])out[0];
93823a1283SJames Wright 
94823a1283SJames Wright   CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
95823a1283SJames Wright     const CeedScalar wdetJ  = q_data[0][i];
96823a1283SJames Wright     const CeedScalar x_i[3] = {x[0][i], x[1][i], x[2][i]};
97823a1283SJames Wright 
98823a1283SJames Wright     v[0][i] = wdetJ * Square(ChildStatsCollectionTest_Exact(x_i) - q[0][i]);
99729f4e9bSJames Wright   }
100729f4e9bSJames Wright   return 0;
101729f4e9bSJames Wright }
102