1 // SPDX-FileCopyrightText: Copyright (c) 2017-2024, HONEE contributors. 2 // SPDX-License-Identifier: Apache-2.0 OR BSD-2-Clause 3 4 /// @file 5 /// QFunctions for the `bc_freestream` and `bc_outflow` boundary conditions 6 #include "bc_freestream_type.h" 7 #include "newtonian_state.h" 8 #include "newtonian_types.h" 9 #include "riemann_solver.h" 10 11 // ***************************************************************************** 12 // Freestream Boundary Condition 13 // ***************************************************************************** 14 CEED_QFUNCTION_HELPER int Freestream(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out, StateVariable state_var, 15 RiemannFluxType flux_type) { 16 const FreestreamContext context = (FreestreamContext)ctx; 17 const CeedScalar(*q)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0]; 18 const CeedScalar(*q_data_sur) = in[2]; 19 CeedScalar(*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0]; 20 CeedScalar(*jac_data_sur) = context->newtonian_ctx.is_implicit ? out[1] : NULL; 21 22 const NewtonianIdealGasContext newt_ctx = &context->newtonian_ctx; 23 const bool is_implicit = newt_ctx->is_implicit; 24 25 CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 26 const CeedScalar qi[5] = {q[0][i], q[1][i], q[2][i], q[3][i], q[4][i]}; 27 const State s = StateFromQ(newt_ctx, qi, state_var); 28 29 CeedScalar wdetJb, normal[3]; 30 QdataBoundaryUnpack_3D(Q, i, q_data_sur, &wdetJb, NULL, normal); 31 wdetJb *= is_implicit ? -1. : 1.; 32 33 StateConservative flux; 34 switch (flux_type) { 35 case RIEMANN_HLL: 36 flux = RiemannFlux_HLL(newt_ctx, s, context->S_infty, normal); 37 break; 38 case RIEMANN_HLLC: 39 flux = RiemannFlux_HLLC(newt_ctx, s, context->S_infty, normal); 40 break; 41 } 42 CeedScalar Flux[5]; 43 UnpackState_U(flux, Flux); 44 for (CeedInt j = 0; j < 5; j++) v[j][i] = -wdetJb * Flux[j]; 45 46 if (is_implicit) { 47 CeedScalar zeros[6] = {0.}; 48 StoredValuesPack(Q, i, 0, 5, qi, jac_data_sur); 49 StoredValuesPack(Q, i, 5, 6, zeros, jac_data_sur); // Every output value must be set 50 } 51 } 52 return 0; 53 } 54 55 CEED_QFUNCTION(Freestream_Conserv_HLL)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 56 return Freestream(ctx, Q, in, out, STATEVAR_CONSERVATIVE, RIEMANN_HLL); 57 } 58 59 CEED_QFUNCTION(Freestream_Prim_HLL)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 60 return Freestream(ctx, Q, in, out, STATEVAR_PRIMITIVE, RIEMANN_HLL); 61 } 62 63 CEED_QFUNCTION(Freestream_Entropy_HLL)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 64 return Freestream(ctx, Q, in, out, STATEVAR_ENTROPY, RIEMANN_HLL); 65 } 66 67 CEED_QFUNCTION(Freestream_Conserv_HLLC)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 68 return Freestream(ctx, Q, in, out, STATEVAR_CONSERVATIVE, RIEMANN_HLLC); 69 } 70 71 CEED_QFUNCTION(Freestream_Prim_HLLC)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 72 return Freestream(ctx, Q, in, out, STATEVAR_PRIMITIVE, RIEMANN_HLLC); 73 } 74 75 CEED_QFUNCTION(Freestream_Entropy_HLLC)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 76 return Freestream(ctx, Q, in, out, STATEVAR_ENTROPY, RIEMANN_HLLC); 77 } 78 79 CEED_QFUNCTION_HELPER int Freestream_Jacobian(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out, StateVariable state_var, 80 RiemannFluxType flux_type) { 81 const CeedScalar(*dq)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0]; 82 const CeedScalar(*q_data_sur) = in[2]; 83 const CeedScalar(*jac_data_sur) = in[4]; 84 85 CeedScalar(*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0]; 86 87 const FreestreamContext context = (FreestreamContext)ctx; 88 const NewtonianIdealGasContext newt_ctx = &context->newtonian_ctx; 89 const bool is_implicit = newt_ctx->is_implicit; 90 const State dS_infty = {0}; 91 92 CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 93 CeedScalar wdetJb, normal[3]; 94 QdataBoundaryUnpack_3D(Q, i, q_data_sur, &wdetJb, NULL, normal); 95 wdetJb *= is_implicit ? -1. : 1.; 96 97 CeedScalar qi[5], dqi[5]; 98 StoredValuesUnpack(Q, i, 0, 5, jac_data_sur, qi); 99 for (int j = 0; j < 5; j++) dqi[j] = dq[j][i]; 100 State s = StateFromQ(newt_ctx, qi, state_var); 101 State ds = StateFromQ_fwd(newt_ctx, s, dqi, state_var); 102 103 StateConservative dflux; 104 switch (flux_type) { 105 case RIEMANN_HLL: 106 dflux = RiemannFlux_HLL_fwd(newt_ctx, s, ds, context->S_infty, dS_infty, normal); 107 break; 108 case RIEMANN_HLLC: 109 dflux = RiemannFlux_HLLC_fwd(newt_ctx, s, ds, context->S_infty, dS_infty, normal); 110 break; 111 } 112 CeedScalar dFlux[5]; 113 UnpackState_U(dflux, dFlux); 114 for (CeedInt j = 0; j < 5; j++) v[j][i] = -wdetJb * dFlux[j]; 115 } 116 return 0; 117 } 118 119 CEED_QFUNCTION(Freestream_Jacobian_Conserv_HLL)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 120 return Freestream_Jacobian(ctx, Q, in, out, STATEVAR_CONSERVATIVE, RIEMANN_HLL); 121 } 122 123 CEED_QFUNCTION(Freestream_Jacobian_Prim_HLL)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 124 return Freestream_Jacobian(ctx, Q, in, out, STATEVAR_PRIMITIVE, RIEMANN_HLL); 125 } 126 127 CEED_QFUNCTION(Freestream_Jacobian_Entropy_HLL)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 128 return Freestream_Jacobian(ctx, Q, in, out, STATEVAR_ENTROPY, RIEMANN_HLL); 129 } 130 131 CEED_QFUNCTION(Freestream_Jacobian_Conserv_HLLC)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 132 return Freestream_Jacobian(ctx, Q, in, out, STATEVAR_CONSERVATIVE, RIEMANN_HLLC); 133 } 134 135 CEED_QFUNCTION(Freestream_Jacobian_Prim_HLLC)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 136 return Freestream_Jacobian(ctx, Q, in, out, STATEVAR_PRIMITIVE, RIEMANN_HLLC); 137 } 138 139 CEED_QFUNCTION(Freestream_Jacobian_Entropy_HLLC)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 140 return Freestream_Jacobian(ctx, Q, in, out, STATEVAR_ENTROPY, RIEMANN_HLLC); 141 } 142