1ae2b091fSJames Wright // SPDX-FileCopyrightText: Copyright (c) 2017-2024, HONEE contributors. 2ae2b091fSJames Wright // SPDX-License-Identifier: Apache-2.0 OR BSD-2-Clause 39ed3d70dSJames Wright 49ed3d70dSJames Wright /// @file 59ed3d70dSJames Wright /// QFunctions for the `bc_freestream` and `bc_outflow` boundary conditions 69ed3d70dSJames Wright #include "bc_freestream_type.h" 79ed3d70dSJames Wright #include "newtonian_state.h" 89ed3d70dSJames Wright #include "newtonian_types.h" 99ed3d70dSJames Wright #include "riemann_solver.h" 109ed3d70dSJames Wright 119ed3d70dSJames Wright // ***************************************************************************** 129ed3d70dSJames Wright // Freestream Boundary Condition 139ed3d70dSJames Wright // ***************************************************************************** 149ed3d70dSJames Wright CEED_QFUNCTION_HELPER int Freestream(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out, StateVariable state_var, 159ed3d70dSJames Wright RiemannFluxType flux_type) { 164b96a86bSJames Wright const FreestreamContext context = (FreestreamContext)ctx; 179ed3d70dSJames Wright const CeedScalar(*q)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0]; 189ed3d70dSJames Wright const CeedScalar(*q_data_sur) = in[2]; 199ed3d70dSJames Wright CeedScalar(*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0]; 20*cde3d787SJames Wright CeedScalar(*jac_data_sur) = context->newt_ctx.is_implicit ? out[1] : NULL; 219ed3d70dSJames Wright 22*cde3d787SJames Wright const NewtonianIGProperties gas = context->newt_ctx.gas; 23*cde3d787SJames Wright const bool is_implicit = context->newt_ctx.is_implicit; 249ed3d70dSJames Wright 259ed3d70dSJames Wright CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 269ed3d70dSJames Wright const CeedScalar qi[5] = {q[0][i], q[1][i], q[2][i], q[3][i], q[4][i]}; 27*cde3d787SJames Wright const State s = StateFromQ(gas, qi, state_var); 289ed3d70dSJames Wright 29feb491a7SJames Wright CeedScalar wdetJb, normal[3]; 30feb491a7SJames Wright QdataBoundaryUnpack_3D(Q, i, q_data_sur, &wdetJb, NULL, normal); 319ed3d70dSJames Wright wdetJb *= is_implicit ? -1. : 1.; 329ed3d70dSJames Wright 339ed3d70dSJames Wright StateConservative flux; 349ed3d70dSJames Wright switch (flux_type) { 359ed3d70dSJames Wright case RIEMANN_HLL: 36*cde3d787SJames Wright flux = RiemannFlux_HLL(gas, s, context->S_infty, normal); 379ed3d70dSJames Wright break; 389ed3d70dSJames Wright case RIEMANN_HLLC: 39*cde3d787SJames Wright flux = RiemannFlux_HLLC(gas, s, context->S_infty, normal); 409ed3d70dSJames Wright break; 419ed3d70dSJames Wright } 429ed3d70dSJames Wright CeedScalar Flux[5]; 439ed3d70dSJames Wright UnpackState_U(flux, Flux); 449ed3d70dSJames Wright for (CeedInt j = 0; j < 5; j++) v[j][i] = -wdetJb * Flux[j]; 459ed3d70dSJames Wright 46ea091b8eSJames Wright if (is_implicit) StoredValuesPack(Q, i, 0, 5, qi, jac_data_sur); 474b96a86bSJames Wright } 489ed3d70dSJames Wright return 0; 499ed3d70dSJames Wright } 509ed3d70dSJames Wright 519ed3d70dSJames Wright CEED_QFUNCTION(Freestream_Conserv_HLL)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 529ed3d70dSJames Wright return Freestream(ctx, Q, in, out, STATEVAR_CONSERVATIVE, RIEMANN_HLL); 539ed3d70dSJames Wright } 549ed3d70dSJames Wright 559ed3d70dSJames Wright CEED_QFUNCTION(Freestream_Prim_HLL)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 569ed3d70dSJames Wright return Freestream(ctx, Q, in, out, STATEVAR_PRIMITIVE, RIEMANN_HLL); 579ed3d70dSJames Wright } 589ed3d70dSJames Wright 599b103f75SJames Wright CEED_QFUNCTION(Freestream_Entropy_HLL)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 609b103f75SJames Wright return Freestream(ctx, Q, in, out, STATEVAR_ENTROPY, RIEMANN_HLL); 619b103f75SJames Wright } 629b103f75SJames Wright 639ed3d70dSJames Wright CEED_QFUNCTION(Freestream_Conserv_HLLC)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 649ed3d70dSJames Wright return Freestream(ctx, Q, in, out, STATEVAR_CONSERVATIVE, RIEMANN_HLLC); 659ed3d70dSJames Wright } 669ed3d70dSJames Wright 679ed3d70dSJames Wright CEED_QFUNCTION(Freestream_Prim_HLLC)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 689ed3d70dSJames Wright return Freestream(ctx, Q, in, out, STATEVAR_PRIMITIVE, RIEMANN_HLLC); 699ed3d70dSJames Wright } 709ed3d70dSJames Wright 719b103f75SJames Wright CEED_QFUNCTION(Freestream_Entropy_HLLC)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 729b103f75SJames Wright return Freestream(ctx, Q, in, out, STATEVAR_ENTROPY, RIEMANN_HLLC); 739b103f75SJames Wright } 749b103f75SJames Wright 759ed3d70dSJames Wright CEED_QFUNCTION_HELPER int Freestream_Jacobian(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out, StateVariable state_var, 769ed3d70dSJames Wright RiemannFluxType flux_type) { 779ed3d70dSJames Wright const CeedScalar(*dq)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0]; 789ed3d70dSJames Wright const CeedScalar(*q_data_sur) = in[2]; 799ed3d70dSJames Wright const CeedScalar(*jac_data_sur) = in[4]; 809ed3d70dSJames Wright 819ed3d70dSJames Wright CeedScalar(*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0]; 829ed3d70dSJames Wright 839ed3d70dSJames Wright const FreestreamContext context = (FreestreamContext)ctx; 84*cde3d787SJames Wright const NewtonianIGProperties gas = context->newt_ctx.gas; 85*cde3d787SJames Wright const bool is_implicit = context->newt_ctx.is_implicit; 869ed3d70dSJames Wright const State dS_infty = {0}; 879ed3d70dSJames Wright 889ed3d70dSJames Wright CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 89feb491a7SJames Wright CeedScalar wdetJb, normal[3]; 90feb491a7SJames Wright QdataBoundaryUnpack_3D(Q, i, q_data_sur, &wdetJb, NULL, normal); 919ed3d70dSJames Wright wdetJb *= is_implicit ? -1. : 1.; 929ed3d70dSJames Wright 939ed3d70dSJames Wright CeedScalar qi[5], dqi[5]; 949ed3d70dSJames Wright StoredValuesUnpack(Q, i, 0, 5, jac_data_sur, qi); 959ed3d70dSJames Wright for (int j = 0; j < 5; j++) dqi[j] = dq[j][i]; 96*cde3d787SJames Wright State s = StateFromQ(gas, qi, state_var); 97*cde3d787SJames Wright State ds = StateFromQ_fwd(gas, s, dqi, state_var); 989ed3d70dSJames Wright 999ed3d70dSJames Wright StateConservative dflux; 1009ed3d70dSJames Wright switch (flux_type) { 1019ed3d70dSJames Wright case RIEMANN_HLL: 102*cde3d787SJames Wright dflux = RiemannFlux_HLL_fwd(gas, s, ds, context->S_infty, dS_infty, normal); 1039ed3d70dSJames Wright break; 1049ed3d70dSJames Wright case RIEMANN_HLLC: 105*cde3d787SJames Wright dflux = RiemannFlux_HLLC_fwd(gas, s, ds, context->S_infty, dS_infty, normal); 1069ed3d70dSJames Wright break; 1079ed3d70dSJames Wright } 1089ed3d70dSJames Wright CeedScalar dFlux[5]; 1099ed3d70dSJames Wright UnpackState_U(dflux, dFlux); 1109ed3d70dSJames Wright for (CeedInt j = 0; j < 5; j++) v[j][i] = -wdetJb * dFlux[j]; 1119ed3d70dSJames Wright } 1129ed3d70dSJames Wright return 0; 1139ed3d70dSJames Wright } 1149ed3d70dSJames Wright 1159ed3d70dSJames Wright CEED_QFUNCTION(Freestream_Jacobian_Conserv_HLL)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 1169ed3d70dSJames Wright return Freestream_Jacobian(ctx, Q, in, out, STATEVAR_CONSERVATIVE, RIEMANN_HLL); 1179ed3d70dSJames Wright } 1189ed3d70dSJames Wright 1199ed3d70dSJames Wright CEED_QFUNCTION(Freestream_Jacobian_Prim_HLL)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 1209ed3d70dSJames Wright return Freestream_Jacobian(ctx, Q, in, out, STATEVAR_PRIMITIVE, RIEMANN_HLL); 1219ed3d70dSJames Wright } 1229ed3d70dSJames Wright 1239b103f75SJames Wright CEED_QFUNCTION(Freestream_Jacobian_Entropy_HLL)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 1249b103f75SJames Wright return Freestream_Jacobian(ctx, Q, in, out, STATEVAR_ENTROPY, RIEMANN_HLL); 1259b103f75SJames Wright } 1269b103f75SJames Wright 1279ed3d70dSJames Wright CEED_QFUNCTION(Freestream_Jacobian_Conserv_HLLC)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 1289ed3d70dSJames Wright return Freestream_Jacobian(ctx, Q, in, out, STATEVAR_CONSERVATIVE, RIEMANN_HLLC); 1299ed3d70dSJames Wright } 1309ed3d70dSJames Wright 1319ed3d70dSJames Wright CEED_QFUNCTION(Freestream_Jacobian_Prim_HLLC)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 1329ed3d70dSJames Wright return Freestream_Jacobian(ctx, Q, in, out, STATEVAR_PRIMITIVE, RIEMANN_HLLC); 1339ed3d70dSJames Wright } 1349ed3d70dSJames Wright 1359b103f75SJames Wright CEED_QFUNCTION(Freestream_Jacobian_Entropy_HLLC)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 1369b103f75SJames Wright return Freestream_Jacobian(ctx, Q, in, out, STATEVAR_ENTROPY, RIEMANN_HLLC); 1379b103f75SJames Wright } 138