1 // SPDX-FileCopyrightText: Copyright (c) 2017-2024, HONEE contributors. 2 // SPDX-License-Identifier: Apache-2.0 OR BSD-2-Clause 3 4 #include <ceed/types.h> 5 #include "newtonian_state.h" 6 #include "numerics.h" 7 8 CEED_QFUNCTION_HELPER int MonitorCFL(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out, StateVariable state_var, 9 CeedInt dim) { 10 const NewtonianIdealGasContext newt_ctx = (const NewtonianIdealGasContext)ctx; 11 const CeedScalar(*q)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0]; 12 const CeedScalar(*q_data) = in[1]; 13 CeedScalar(*v) = out[0]; 14 15 const NewtonianIGProperties gas = newt_ctx->gas; 16 17 CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 18 const CeedScalar qi[5] = {q[0][i], q[1][i], q[2][i], q[3][i], q[4][i]}; 19 const State s = StateFromQ(gas, qi, state_var); 20 21 switch (dim) { 22 case 2: { 23 CeedScalar wdetJ, dXdx[2][2], gijd_mat[2][2] = {{0.}}; 24 25 QdataUnpack_2D(Q, i, q_data, &wdetJ, dXdx); 26 MatMat2(dXdx, dXdx, CEED_TRANSPOSE, CEED_NOTRANSPOSE, gijd_mat); 27 // (1/2)^2 to account for reference element size; for length 1 square/cube element, gij should be identity matrix 28 ScaleN((CeedScalar *)gijd_mat, 0.25, Square(dim)); 29 // Multiplied by timestep outside of QFunction so that it can be used for both Advection and Newtonian 30 v[i] = CalculateCFL_2D(s.Y.velocity, 1, gijd_mat); 31 } break; 32 case 3: { 33 CeedScalar wdetJ, dXdx[3][3], gijd_mat[3][3] = {{0.}}; 34 35 QdataUnpack_3D(Q, i, q_data, &wdetJ, dXdx); 36 MatMat3(dXdx, dXdx, CEED_TRANSPOSE, CEED_NOTRANSPOSE, gijd_mat); 37 // (1/2)^2 to account for reference element size; for length 1 square/cube element, gij should be identity matrix 38 ScaleN((CeedScalar *)gijd_mat, 0.25, Square(dim)); 39 // Multiplied by timestep outside of QFunction so that it can be used for both Advection and Newtonian 40 v[i] = CalculateCFL_3D(s.Y.velocity, 1, gijd_mat); 41 } break; 42 } 43 } 44 return 0; 45 } 46 47 CEED_QFUNCTION(MonitorCFL_3D_Conserv)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 48 return MonitorCFL(ctx, Q, in, out, STATEVAR_CONSERVATIVE, 3); 49 } 50 51 CEED_QFUNCTION(MonitorCFL_3D_Prim)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 52 return MonitorCFL(ctx, Q, in, out, STATEVAR_PRIMITIVE, 3); 53 } 54 55 CEED_QFUNCTION(MonitorCFL_3D_Entropy)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 56 return MonitorCFL(ctx, Q, in, out, STATEVAR_ENTROPY, 3); 57 } 58 59 CEED_QFUNCTION(MonitorCFL_2D_Conserv)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 60 return MonitorCFL(ctx, Q, in, out, STATEVAR_CONSERVATIVE, 2); 61 } 62 63 CEED_QFUNCTION(MonitorCFL_2D_Prim)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 64 return MonitorCFL(ctx, Q, in, out, STATEVAR_PRIMITIVE, 2); 65 } 66 67 CEED_QFUNCTION(MonitorCFL_2D_Entropy)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 68 return MonitorCFL(ctx, Q, in, out, STATEVAR_ENTROPY, 2); 69 } 70