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_slip` 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 CEED_QFUNCTION_HELPER int Slip(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out, StateVariable state_var) { 124b96a86bSJames Wright const NewtonianIdealGasContext newt_ctx = (const NewtonianIdealGasContext)ctx; 139ed3d70dSJames Wright const CeedScalar(*q)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0]; 149ed3d70dSJames Wright const CeedScalar(*q_data_sur) = in[2]; 159ed3d70dSJames Wright CeedScalar(*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0]; 164b96a86bSJames Wright CeedScalar(*jac_data_sur) = newt_ctx->is_implicit ? out[1] : NULL; 179ed3d70dSJames Wright 189ed3d70dSJames Wright CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 199ed3d70dSJames Wright const CeedScalar qi[5] = {q[0][i], q[1][i], q[2][i], q[3][i], q[4][i]}; 209ed3d70dSJames Wright State s = StateFromQ(newt_ctx, qi, state_var); 219ed3d70dSJames Wright 2278e8b7daSJames Wright CeedScalar wdetJb, normal[3]; 2378e8b7daSJames Wright QdataBoundaryUnpack_3D(Q, i, q_data_sur, &wdetJb, NULL, normal); 249ed3d70dSJames Wright wdetJb *= newt_ctx->is_implicit ? -1. : 1.; 259ed3d70dSJames Wright 269ed3d70dSJames Wright CeedScalar vel_reflect[3]; 2778e8b7daSJames Wright const CeedScalar vel_normal = Dot3(s.Y.velocity, normal); 2878e8b7daSJames Wright for (CeedInt j = 0; j < 3; j++) vel_reflect[j] = s.Y.velocity[j] - 2. * normal[j] * vel_normal; 299ed3d70dSJames Wright const CeedScalar Y_reflect[5] = {s.Y.pressure, vel_reflect[0], vel_reflect[1], vel_reflect[2], s.Y.temperature}; 309ed3d70dSJames Wright State s_reflect = StateFromY(newt_ctx, Y_reflect); 319ed3d70dSJames Wright 3278e8b7daSJames Wright StateConservative flux = RiemannFlux_HLLC(newt_ctx, s, s_reflect, normal); 339ed3d70dSJames Wright 349ed3d70dSJames Wright CeedScalar Flux[5]; 359ed3d70dSJames Wright UnpackState_U(flux, Flux); 369ed3d70dSJames Wright for (CeedInt j = 0; j < 5; j++) v[j][i] = -wdetJb * Flux[j]; 379ed3d70dSJames Wright 38*ea091b8eSJames Wright if (newt_ctx->is_implicit) StoredValuesPack(Q, i, 0, 5, qi, jac_data_sur); 394b96a86bSJames Wright } 409ed3d70dSJames Wright return 0; 419ed3d70dSJames Wright } 429ed3d70dSJames Wright 439ed3d70dSJames Wright CEED_QFUNCTION(Slip_Conserv)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 449ed3d70dSJames Wright return Slip(ctx, Q, in, out, STATEVAR_CONSERVATIVE); 459ed3d70dSJames Wright } 469ed3d70dSJames Wright 479ed3d70dSJames Wright CEED_QFUNCTION(Slip_Prim)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 489ed3d70dSJames Wright return Slip(ctx, Q, in, out, STATEVAR_PRIMITIVE); 499ed3d70dSJames Wright } 509ed3d70dSJames Wright 519b103f75SJames Wright CEED_QFUNCTION(Slip_Entropy)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 529b103f75SJames Wright return Slip(ctx, Q, in, out, STATEVAR_ENTROPY); 539b103f75SJames Wright } 549b103f75SJames Wright 559ed3d70dSJames Wright CEED_QFUNCTION_HELPER int Slip_Jacobian(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out, StateVariable state_var) { 569ed3d70dSJames Wright const CeedScalar(*dq)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0]; 579ed3d70dSJames Wright const CeedScalar(*q_data_sur) = in[2]; 589ed3d70dSJames Wright const CeedScalar(*jac_data_sur) = in[4]; 599ed3d70dSJames Wright 609ed3d70dSJames Wright CeedScalar(*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0]; 619ed3d70dSJames Wright 629ed3d70dSJames Wright const NewtonianIdealGasContext newt_ctx = (const NewtonianIdealGasContext)ctx; 639ed3d70dSJames Wright 649ed3d70dSJames Wright CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 6578e8b7daSJames Wright CeedScalar wdetJb, normal[3]; 6678e8b7daSJames Wright QdataBoundaryUnpack_3D(Q, i, q_data_sur, &wdetJb, NULL, normal); 679ed3d70dSJames Wright wdetJb *= newt_ctx->is_implicit ? -1. : 1.; 689ed3d70dSJames Wright 699ed3d70dSJames Wright CeedScalar qi[5], dqi[5]; 709ed3d70dSJames Wright StoredValuesUnpack(Q, i, 0, 5, jac_data_sur, qi); 719ed3d70dSJames Wright for (int j = 0; j < 5; j++) dqi[j] = dq[j][i]; 729ed3d70dSJames Wright State s = StateFromQ(newt_ctx, qi, state_var); 739ed3d70dSJames Wright State ds = StateFromQ_fwd(newt_ctx, s, dqi, state_var); 749ed3d70dSJames Wright 759ed3d70dSJames Wright CeedScalar vel_reflect[3]; 7678e8b7daSJames Wright const CeedScalar vel_normal = Dot3(s.Y.velocity, normal); 7778e8b7daSJames Wright for (CeedInt j = 0; j < 3; j++) vel_reflect[j] = s.Y.velocity[j] - 2. * normal[j] * vel_normal; 789ed3d70dSJames Wright const CeedScalar Y_reflect[5] = {s.Y.pressure, vel_reflect[0], vel_reflect[1], vel_reflect[2], s.Y.temperature}; 799ed3d70dSJames Wright State s_reflect = StateFromY(newt_ctx, Y_reflect); 809ed3d70dSJames Wright 819ed3d70dSJames Wright CeedScalar dvel_reflect[3]; 8278e8b7daSJames Wright const CeedScalar dvel_normal = Dot3(ds.Y.velocity, normal); 8378e8b7daSJames Wright for (CeedInt j = 0; j < 3; j++) dvel_reflect[j] = ds.Y.velocity[j] - 2. * normal[j] * dvel_normal; 849ed3d70dSJames Wright const CeedScalar dY_reflect[5] = {ds.Y.pressure, dvel_reflect[0], dvel_reflect[1], dvel_reflect[2], ds.Y.temperature}; 859ed3d70dSJames Wright State ds_reflect = StateFromY_fwd(newt_ctx, s_reflect, dY_reflect); 869ed3d70dSJames Wright 8778e8b7daSJames Wright StateConservative dflux = RiemannFlux_HLLC_fwd(newt_ctx, s, ds, s_reflect, ds_reflect, normal); 889ed3d70dSJames Wright 899ed3d70dSJames Wright CeedScalar dFlux[5]; 909ed3d70dSJames Wright UnpackState_U(dflux, dFlux); 919ed3d70dSJames Wright for (CeedInt j = 0; j < 5; j++) v[j][i] = -wdetJb * dFlux[j]; 929ed3d70dSJames Wright } 939ed3d70dSJames Wright return 0; 949ed3d70dSJames Wright } 959ed3d70dSJames Wright 969ed3d70dSJames Wright CEED_QFUNCTION(Slip_Jacobian_Conserv)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 979ed3d70dSJames Wright return Slip_Jacobian(ctx, Q, in, out, STATEVAR_CONSERVATIVE); 989ed3d70dSJames Wright } 999ed3d70dSJames Wright 1009ed3d70dSJames Wright CEED_QFUNCTION(Slip_Jacobian_Prim)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 1019ed3d70dSJames Wright return Slip_Jacobian(ctx, Q, in, out, STATEVAR_PRIMITIVE); 1029ed3d70dSJames Wright } 1039b103f75SJames Wright 1049b103f75SJames Wright CEED_QFUNCTION(Slip_Jacobian_Entropy)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 1059b103f75SJames Wright return Slip_Jacobian(ctx, Q, in, out, STATEVAR_ENTROPY); 1069b103f75SJames Wright } 107