xref: /honee/qfunctions/monitor_cfl.h (revision 475f0cac5d40259768f4556cf888e8f2448554cb)
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"
62a28a40bSJames Wright #include "numerics.h"
787fd7f33SJames Wright 
MonitorCFL(void * ctx,CeedInt Q,const CeedScalar * const * in,CeedScalar * const * out,StateVariable state_var,CeedInt dim)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) {
10*cde3d787SJames Wright   const NewtonianIdealGasContext newt_ctx = (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 
15*cde3d787SJames Wright   const NewtonianIGProperties gas = newt_ctx->gas;
16*cde3d787SJames Wright 
1787fd7f33SJames Wright   CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
1887fd7f33SJames Wright     const CeedScalar qi[5] = {q[0][i], q[1][i], q[2][i], q[3][i], q[4][i]};
1987fd7f33SJames Wright     const State      s     = StateFromQ(gas, qi, state_var);
2087fd7f33SJames Wright 
212a28a40bSJames Wright     switch (dim) {
222a28a40bSJames Wright       case 2: {
232a28a40bSJames Wright         CeedScalar wdetJ, dXdx[2][2], gijd_mat[2][2] = {{0.}};
242a28a40bSJames Wright 
252a28a40bSJames Wright         QdataUnpack_2D(Q, i, q_data, &wdetJ, dXdx);
262a28a40bSJames Wright         MatMat2(dXdx, dXdx, CEED_TRANSPOSE, CEED_NOTRANSPOSE, gijd_mat);
2787fd7f33SJames Wright         // (1/2)^2 to account for reference element size; for length 1 square/cube element, gij should be identity matrix
2887fd7f33SJames Wright         ScaleN((CeedScalar *)gijd_mat, 0.25, Square(dim));
292a28a40bSJames Wright         // Multiplied by timestep outside of QFunction so that it can be used for both Advection and Newtonian
302a28a40bSJames Wright         v[i] = CalculateCFL_2D(s.Y.velocity, 1, gijd_mat);
312a28a40bSJames Wright       } break;
322a28a40bSJames Wright       case 3: {
332a28a40bSJames Wright         CeedScalar wdetJ, dXdx[3][3], gijd_mat[3][3] = {{0.}};
342a28a40bSJames Wright 
352a28a40bSJames Wright         QdataUnpack_3D(Q, i, q_data, &wdetJ, dXdx);
362a28a40bSJames Wright         MatMat3(dXdx, dXdx, CEED_TRANSPOSE, CEED_NOTRANSPOSE, gijd_mat);
372a28a40bSJames Wright         // (1/2)^2 to account for reference element size; for length 1 square/cube element, gij should be identity matrix
382a28a40bSJames Wright         ScaleN((CeedScalar *)gijd_mat, 0.25, Square(dim));
392a28a40bSJames Wright         // Multiplied by timestep outside of QFunction so that it can be used for both Advection and Newtonian
402a28a40bSJames Wright         v[i] = CalculateCFL_3D(s.Y.velocity, 1, gijd_mat);
412a28a40bSJames Wright       } break;
422a28a40bSJames Wright     }
4387fd7f33SJames Wright   }
4487fd7f33SJames Wright   return 0;
4587fd7f33SJames Wright }
4687fd7f33SJames Wright 
MonitorCFL_3D_Conserv(void * ctx,CeedInt Q,const CeedScalar * const * in,CeedScalar * const * out)4787fd7f33SJames Wright CEED_QFUNCTION(MonitorCFL_3D_Conserv)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
4887fd7f33SJames Wright   return MonitorCFL(ctx, Q, in, out, STATEVAR_CONSERVATIVE, 3);
4987fd7f33SJames Wright }
5087fd7f33SJames Wright 
MonitorCFL_3D_Prim(void * ctx,CeedInt Q,const CeedScalar * const * in,CeedScalar * const * out)5187fd7f33SJames Wright CEED_QFUNCTION(MonitorCFL_3D_Prim)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
5287fd7f33SJames Wright   return MonitorCFL(ctx, Q, in, out, STATEVAR_PRIMITIVE, 3);
5387fd7f33SJames Wright }
5487fd7f33SJames Wright 
MonitorCFL_3D_Entropy(void * ctx,CeedInt Q,const CeedScalar * const * in,CeedScalar * const * out)5587fd7f33SJames Wright CEED_QFUNCTION(MonitorCFL_3D_Entropy)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
5687fd7f33SJames Wright   return MonitorCFL(ctx, Q, in, out, STATEVAR_ENTROPY, 3);
5787fd7f33SJames Wright }
5887fd7f33SJames Wright 
MonitorCFL_2D_Conserv(void * ctx,CeedInt Q,const CeedScalar * const * in,CeedScalar * const * out)5987fd7f33SJames Wright CEED_QFUNCTION(MonitorCFL_2D_Conserv)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
6087fd7f33SJames Wright   return MonitorCFL(ctx, Q, in, out, STATEVAR_CONSERVATIVE, 2);
6187fd7f33SJames Wright }
6287fd7f33SJames Wright 
MonitorCFL_2D_Prim(void * ctx,CeedInt Q,const CeedScalar * const * in,CeedScalar * const * out)6387fd7f33SJames Wright CEED_QFUNCTION(MonitorCFL_2D_Prim)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
6487fd7f33SJames Wright   return MonitorCFL(ctx, Q, in, out, STATEVAR_PRIMITIVE, 2);
6587fd7f33SJames Wright }
6687fd7f33SJames Wright 
MonitorCFL_2D_Entropy(void * ctx,CeedInt Q,const CeedScalar * const * in,CeedScalar * const * out)6787fd7f33SJames Wright CEED_QFUNCTION(MonitorCFL_2D_Entropy)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
6887fd7f33SJames Wright   return MonitorCFL(ctx, Q, in, out, STATEVAR_ENTROPY, 2);
6987fd7f33SJames Wright }
70