187fd7f33SJames Wright // SPDX-FileCopyrightText: Copyright (c) 2017-2024, HONEE contributors. 287fd7f33SJames Wright // SPDX-License-Identifier: Apache-2.0 OR BSD-2-Clause 387fd7f33SJames Wright 487fd7f33SJames Wright #include <ceed/types.h> 587fd7f33SJames Wright #include "newtonian_state.h" 6*2a28a40bSJames Wright #include "numerics.h" 787fd7f33SJames Wright 887fd7f33SJames Wright CEED_QFUNCTION_HELPER int MonitorCFL(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out, StateVariable state_var, 987fd7f33SJames Wright CeedInt dim) { 1087fd7f33SJames Wright const NewtonianIdealGasContext gas = (const NewtonianIdealGasContext)ctx; 1187fd7f33SJames Wright const CeedScalar(*q)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0]; 1287fd7f33SJames Wright const CeedScalar(*q_data) = in[1]; 1387fd7f33SJames Wright CeedScalar(*v) = out[0]; 1487fd7f33SJames Wright 1587fd7f33SJames Wright CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 1687fd7f33SJames Wright const CeedScalar qi[5] = {q[0][i], q[1][i], q[2][i], q[3][i], q[4][i]}; 1787fd7f33SJames Wright const State s = StateFromQ(gas, qi, state_var); 1887fd7f33SJames Wright 19*2a28a40bSJames Wright switch (dim) { 20*2a28a40bSJames Wright case 2: { 21*2a28a40bSJames Wright CeedScalar wdetJ, dXdx[2][2], gijd_mat[2][2] = {{0.}}; 22*2a28a40bSJames Wright 23*2a28a40bSJames Wright QdataUnpack_2D(Q, i, q_data, &wdetJ, dXdx); 24*2a28a40bSJames Wright MatMat2(dXdx, dXdx, CEED_TRANSPOSE, CEED_NOTRANSPOSE, gijd_mat); 2587fd7f33SJames Wright // (1/2)^2 to account for reference element size; for length 1 square/cube element, gij should be identity matrix 2687fd7f33SJames Wright ScaleN((CeedScalar *)gijd_mat, 0.25, Square(dim)); 27*2a28a40bSJames Wright // Multiplied by timestep outside of QFunction so that it can be used for both Advection and Newtonian 28*2a28a40bSJames Wright v[i] = CalculateCFL_2D(s.Y.velocity, 1, gijd_mat); 29*2a28a40bSJames Wright } break; 30*2a28a40bSJames Wright case 3: { 31*2a28a40bSJames Wright CeedScalar wdetJ, dXdx[3][3], gijd_mat[3][3] = {{0.}}; 32*2a28a40bSJames Wright 33*2a28a40bSJames Wright QdataUnpack_3D(Q, i, q_data, &wdetJ, dXdx); 34*2a28a40bSJames Wright MatMat3(dXdx, dXdx, CEED_TRANSPOSE, CEED_NOTRANSPOSE, gijd_mat); 35*2a28a40bSJames Wright // (1/2)^2 to account for reference element size; for length 1 square/cube element, gij should be identity matrix 36*2a28a40bSJames Wright ScaleN((CeedScalar *)gijd_mat, 0.25, Square(dim)); 37*2a28a40bSJames Wright // Multiplied by timestep outside of QFunction so that it can be used for both Advection and Newtonian 38*2a28a40bSJames Wright v[i] = CalculateCFL_3D(s.Y.velocity, 1, gijd_mat); 39*2a28a40bSJames Wright } break; 40*2a28a40bSJames Wright } 4187fd7f33SJames Wright } 4287fd7f33SJames Wright return 0; 4387fd7f33SJames Wright } 4487fd7f33SJames Wright 4587fd7f33SJames Wright CEED_QFUNCTION(MonitorCFL_3D_Conserv)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 4687fd7f33SJames Wright return MonitorCFL(ctx, Q, in, out, STATEVAR_CONSERVATIVE, 3); 4787fd7f33SJames Wright } 4887fd7f33SJames Wright 4987fd7f33SJames Wright CEED_QFUNCTION(MonitorCFL_3D_Prim)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 5087fd7f33SJames Wright return MonitorCFL(ctx, Q, in, out, STATEVAR_PRIMITIVE, 3); 5187fd7f33SJames Wright } 5287fd7f33SJames Wright 5387fd7f33SJames Wright CEED_QFUNCTION(MonitorCFL_3D_Entropy)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 5487fd7f33SJames Wright return MonitorCFL(ctx, Q, in, out, STATEVAR_ENTROPY, 3); 5587fd7f33SJames Wright } 5687fd7f33SJames Wright 5787fd7f33SJames Wright CEED_QFUNCTION(MonitorCFL_2D_Conserv)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 5887fd7f33SJames Wright return MonitorCFL(ctx, Q, in, out, STATEVAR_CONSERVATIVE, 2); 5987fd7f33SJames Wright } 6087fd7f33SJames Wright 6187fd7f33SJames Wright CEED_QFUNCTION(MonitorCFL_2D_Prim)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 6287fd7f33SJames Wright return MonitorCFL(ctx, Q, in, out, STATEVAR_PRIMITIVE, 2); 6387fd7f33SJames Wright } 6487fd7f33SJames Wright 6587fd7f33SJames Wright CEED_QFUNCTION(MonitorCFL_2D_Entropy)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 6687fd7f33SJames Wright return MonitorCFL(ctx, Q, in, out, STATEVAR_ENTROPY, 2); 6787fd7f33SJames Wright } 68