1b30619f6SJames Wright // SPDX-FileCopyrightText: Copyright (c) 2017-2025, HONEE contributors. 2b30619f6SJames Wright // SPDX-License-Identifier: Apache-2.0 OR BSD-2-Clause 3b30619f6SJames Wright #include <ceed/types.h> 4b30619f6SJames Wright 5b30619f6SJames Wright #include "../newtonian_state.h" 6b30619f6SJames Wright #include "../numerics.h" 7b30619f6SJames Wright #include "../utils.h" 8b30619f6SJames Wright 9b30619f6SJames Wright typedef struct CflPe_SpanStatsContext_ *CflPe_SpanStatsContext; 10b30619f6SJames Wright struct CflPe_SpanStatsContext_ { 11b30619f6SJames Wright CeedScalar solution_time; 12b30619f6SJames Wright CeedScalar previous_time; 13b30619f6SJames Wright CeedScalar diffusion_coeff; 14b30619f6SJames Wright CeedScalar timestep; 15*cde3d787SJames Wright struct NewtonianIdealGasContext_ newt_ctx; 16b30619f6SJames Wright }; 17b30619f6SJames Wright 18b30619f6SJames Wright CEED_QFUNCTION_HELPER int ChildStatsCollection_CflPe(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out, 19b30619f6SJames Wright StateVariable state_var, CeedInt dim) { 20b30619f6SJames Wright const CeedScalar(*q)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0]; 21b30619f6SJames Wright const CeedScalar(*q_data) = in[1]; 22b30619f6SJames Wright CeedScalar(*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0]; 23b30619f6SJames Wright 24b30619f6SJames Wright CflPe_SpanStatsContext context = (CflPe_SpanStatsContext)ctx; 25*cde3d787SJames Wright const NewtonianIGProperties gas = context->newt_ctx.gas; 26b30619f6SJames Wright CeedScalar delta_t = context->solution_time - context->previous_time; 27b30619f6SJames Wright 28b30619f6SJames Wright CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 29b30619f6SJames Wright const CeedScalar qi[5] = {q[0][i], q[1][i], q[2][i], q[3][i], q[4][i]}; 30b30619f6SJames Wright const State s = StateFromQ(gas, qi, state_var); 31b30619f6SJames Wright CeedScalar Pe, cfl, wdetJ; 32b30619f6SJames Wright 33b30619f6SJames Wright switch (dim) { 34b30619f6SJames Wright case 2: { 35b30619f6SJames Wright CeedScalar dXdx[2][2], gijd_mat[2][2] = {{0.}}; 36b30619f6SJames Wright 37b30619f6SJames Wright QdataUnpack_2D(Q, i, q_data, &wdetJ, dXdx); 38b30619f6SJames Wright wdetJ = wdetJ * delta_t; 39b30619f6SJames Wright 40b30619f6SJames Wright MatMat2(dXdx, dXdx, CEED_TRANSPOSE, CEED_NOTRANSPOSE, gijd_mat); 41b30619f6SJames Wright // (1/2)^2 to account for reference element size; for length 1 square/cube element, gij should be identity matrix 42b30619f6SJames Wright ScaleN((CeedScalar *)gijd_mat, 0.25, Square(dim)); 43b30619f6SJames Wright 44b30619f6SJames Wright cfl = CalculateCFL_2D(s.Y.velocity, context->timestep, gijd_mat); 45b30619f6SJames Wright Pe = CalculatePe_2D(s.Y.velocity, context->diffusion_coeff, gijd_mat); 46b30619f6SJames Wright } break; 47b30619f6SJames Wright case 3: { 48b30619f6SJames Wright CeedScalar dXdx[3][3], gijd_mat[3][3] = {{0.}}; 49b30619f6SJames Wright 50b30619f6SJames Wright QdataUnpack_3D(Q, i, q_data, &wdetJ, dXdx); 51b30619f6SJames Wright wdetJ = wdetJ * delta_t; 52b30619f6SJames Wright 53b30619f6SJames Wright MatMat3(dXdx, dXdx, CEED_TRANSPOSE, CEED_NOTRANSPOSE, gijd_mat); 54b30619f6SJames Wright // (1/2)^2 to account for reference element size; for length 1 square/cube element, gij should be identity matrix 55b30619f6SJames Wright ScaleN((CeedScalar *)gijd_mat, 0.25, Square(dim)); 56b30619f6SJames Wright 57b30619f6SJames Wright cfl = CalculateCFL_3D(s.Y.velocity, context->timestep, gijd_mat); 58b30619f6SJames Wright Pe = CalculatePe_3D(s.Y.velocity, context->diffusion_coeff, gijd_mat); 59b30619f6SJames Wright } break; 60b30619f6SJames Wright } 61b30619f6SJames Wright 62b30619f6SJames Wright v[0][i] = wdetJ * cfl; 63b30619f6SJames Wright v[1][i] = wdetJ * Square(cfl); 64b30619f6SJames Wright v[2][i] = wdetJ * Cube(cfl); 65b30619f6SJames Wright v[3][i] = wdetJ * Pe; 66b30619f6SJames Wright v[4][i] = wdetJ * Square(Pe); 67b30619f6SJames Wright v[5][i] = wdetJ * Cube(Pe); 68b30619f6SJames Wright } 69b30619f6SJames Wright return 0; 70b30619f6SJames Wright } 71b30619f6SJames Wright 72b30619f6SJames Wright CEED_QFUNCTION(ChildStatsCollection_3D_Conserv)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 73b30619f6SJames Wright return ChildStatsCollection_CflPe(ctx, Q, in, out, STATEVAR_CONSERVATIVE, 3); 74b30619f6SJames Wright } 75b30619f6SJames Wright 76b30619f6SJames Wright CEED_QFUNCTION(ChildStatsCollection_3D_Prim)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 77b30619f6SJames Wright return ChildStatsCollection_CflPe(ctx, Q, in, out, STATEVAR_PRIMITIVE, 3); 78b30619f6SJames Wright } 79b30619f6SJames Wright 80b30619f6SJames Wright CEED_QFUNCTION(ChildStatsCollection_3D_Entropy)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 81b30619f6SJames Wright return ChildStatsCollection_CflPe(ctx, Q, in, out, STATEVAR_ENTROPY, 3); 82b30619f6SJames Wright } 83b30619f6SJames Wright 84b30619f6SJames Wright CEED_QFUNCTION(ChildStatsCollection_2D_Conserv)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 85b30619f6SJames Wright return ChildStatsCollection_CflPe(ctx, Q, in, out, STATEVAR_CONSERVATIVE, 2); 86b30619f6SJames Wright } 87b30619f6SJames Wright 88b30619f6SJames Wright CEED_QFUNCTION(ChildStatsCollection_2D_Prim)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 89b30619f6SJames Wright return ChildStatsCollection_CflPe(ctx, Q, in, out, STATEVAR_PRIMITIVE, 2); 90b30619f6SJames Wright } 91b30619f6SJames Wright 92b30619f6SJames Wright CEED_QFUNCTION(ChildStatsCollection_2D_Entropy)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 93b30619f6SJames Wright return ChildStatsCollection_CflPe(ctx, Q, in, out, STATEVAR_ENTROPY, 2); 94b30619f6SJames Wright } 95