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 18*cde3d787SJames Wright const NewtonianIGProperties gas = newt_ctx->gas; 19*cde3d787SJames Wright 209ed3d70dSJames Wright CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 219ed3d70dSJames Wright const CeedScalar qi[5] = {q[0][i], q[1][i], q[2][i], q[3][i], q[4][i]}; 22*cde3d787SJames Wright State s = StateFromQ(gas, qi, state_var); 239ed3d70dSJames Wright 2478e8b7daSJames Wright CeedScalar wdetJb, normal[3]; 2578e8b7daSJames Wright QdataBoundaryUnpack_3D(Q, i, q_data_sur, &wdetJb, NULL, normal); 269ed3d70dSJames Wright wdetJb *= newt_ctx->is_implicit ? -1. : 1.; 279ed3d70dSJames Wright 289ed3d70dSJames Wright CeedScalar vel_reflect[3]; 2978e8b7daSJames Wright const CeedScalar vel_normal = Dot3(s.Y.velocity, normal); 3078e8b7daSJames Wright for (CeedInt j = 0; j < 3; j++) vel_reflect[j] = s.Y.velocity[j] - 2. * normal[j] * vel_normal; 319ed3d70dSJames Wright const CeedScalar Y_reflect[5] = {s.Y.pressure, vel_reflect[0], vel_reflect[1], vel_reflect[2], s.Y.temperature}; 32*cde3d787SJames Wright State s_reflect = StateFromY(gas, Y_reflect); 339ed3d70dSJames Wright 34*cde3d787SJames Wright StateConservative flux = RiemannFlux_HLLC(gas, s, s_reflect, normal); 359ed3d70dSJames Wright 369ed3d70dSJames Wright CeedScalar Flux[5]; 379ed3d70dSJames Wright UnpackState_U(flux, Flux); 389ed3d70dSJames Wright for (CeedInt j = 0; j < 5; j++) v[j][i] = -wdetJb * Flux[j]; 399ed3d70dSJames Wright 40ea091b8eSJames Wright if (newt_ctx->is_implicit) StoredValuesPack(Q, i, 0, 5, qi, jac_data_sur); 414b96a86bSJames Wright } 429ed3d70dSJames Wright return 0; 439ed3d70dSJames Wright } 449ed3d70dSJames Wright 459ed3d70dSJames Wright CEED_QFUNCTION(Slip_Conserv)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 469ed3d70dSJames Wright return Slip(ctx, Q, in, out, STATEVAR_CONSERVATIVE); 479ed3d70dSJames Wright } 489ed3d70dSJames Wright 499ed3d70dSJames Wright CEED_QFUNCTION(Slip_Prim)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 509ed3d70dSJames Wright return Slip(ctx, Q, in, out, STATEVAR_PRIMITIVE); 519ed3d70dSJames Wright } 529ed3d70dSJames Wright 539b103f75SJames Wright CEED_QFUNCTION(Slip_Entropy)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 549b103f75SJames Wright return Slip(ctx, Q, in, out, STATEVAR_ENTROPY); 559b103f75SJames Wright } 569b103f75SJames Wright 579ed3d70dSJames Wright CEED_QFUNCTION_HELPER int Slip_Jacobian(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out, StateVariable state_var) { 589ed3d70dSJames Wright const CeedScalar(*dq)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0]; 599ed3d70dSJames Wright const CeedScalar(*q_data_sur) = in[2]; 609ed3d70dSJames Wright const CeedScalar(*jac_data_sur) = in[4]; 619ed3d70dSJames Wright 629ed3d70dSJames Wright CeedScalar(*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0]; 639ed3d70dSJames Wright 649ed3d70dSJames Wright const NewtonianIdealGasContext newt_ctx = (const NewtonianIdealGasContext)ctx; 65*cde3d787SJames Wright const NewtonianIGProperties gas = newt_ctx->gas; 669ed3d70dSJames Wright 679ed3d70dSJames Wright CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 6878e8b7daSJames Wright CeedScalar wdetJb, normal[3]; 6978e8b7daSJames Wright QdataBoundaryUnpack_3D(Q, i, q_data_sur, &wdetJb, NULL, normal); 709ed3d70dSJames Wright wdetJb *= newt_ctx->is_implicit ? -1. : 1.; 719ed3d70dSJames Wright 729ed3d70dSJames Wright CeedScalar qi[5], dqi[5]; 739ed3d70dSJames Wright StoredValuesUnpack(Q, i, 0, 5, jac_data_sur, qi); 749ed3d70dSJames Wright for (int j = 0; j < 5; j++) dqi[j] = dq[j][i]; 75*cde3d787SJames Wright State s = StateFromQ(gas, qi, state_var); 76*cde3d787SJames Wright State ds = StateFromQ_fwd(gas, s, dqi, state_var); 779ed3d70dSJames Wright 789ed3d70dSJames Wright CeedScalar vel_reflect[3]; 7978e8b7daSJames Wright const CeedScalar vel_normal = Dot3(s.Y.velocity, normal); 8078e8b7daSJames Wright for (CeedInt j = 0; j < 3; j++) vel_reflect[j] = s.Y.velocity[j] - 2. * normal[j] * vel_normal; 819ed3d70dSJames Wright const CeedScalar Y_reflect[5] = {s.Y.pressure, vel_reflect[0], vel_reflect[1], vel_reflect[2], s.Y.temperature}; 82*cde3d787SJames Wright State s_reflect = StateFromY(gas, Y_reflect); 839ed3d70dSJames Wright 849ed3d70dSJames Wright CeedScalar dvel_reflect[3]; 8578e8b7daSJames Wright const CeedScalar dvel_normal = Dot3(ds.Y.velocity, normal); 8678e8b7daSJames Wright for (CeedInt j = 0; j < 3; j++) dvel_reflect[j] = ds.Y.velocity[j] - 2. * normal[j] * dvel_normal; 879ed3d70dSJames Wright const CeedScalar dY_reflect[5] = {ds.Y.pressure, dvel_reflect[0], dvel_reflect[1], dvel_reflect[2], ds.Y.temperature}; 88*cde3d787SJames Wright State ds_reflect = StateFromY_fwd(gas, s_reflect, dY_reflect); 899ed3d70dSJames Wright 90*cde3d787SJames Wright StateConservative dflux = RiemannFlux_HLLC_fwd(gas, s, ds, s_reflect, ds_reflect, normal); 919ed3d70dSJames Wright 929ed3d70dSJames Wright CeedScalar dFlux[5]; 939ed3d70dSJames Wright UnpackState_U(dflux, dFlux); 949ed3d70dSJames Wright for (CeedInt j = 0; j < 5; j++) v[j][i] = -wdetJb * dFlux[j]; 959ed3d70dSJames Wright } 969ed3d70dSJames Wright return 0; 979ed3d70dSJames Wright } 989ed3d70dSJames Wright 999ed3d70dSJames Wright CEED_QFUNCTION(Slip_Jacobian_Conserv)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 1009ed3d70dSJames Wright return Slip_Jacobian(ctx, Q, in, out, STATEVAR_CONSERVATIVE); 1019ed3d70dSJames Wright } 1029ed3d70dSJames Wright 1039ed3d70dSJames Wright CEED_QFUNCTION(Slip_Jacobian_Prim)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 1049ed3d70dSJames Wright return Slip_Jacobian(ctx, Q, in, out, STATEVAR_PRIMITIVE); 1059ed3d70dSJames Wright } 1069b103f75SJames Wright 1079b103f75SJames Wright CEED_QFUNCTION(Slip_Jacobian_Entropy)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 1089b103f75SJames Wright return Slip_Jacobian(ctx, Q, in, out, STATEVAR_ENTROPY); 1099b103f75SJames Wright } 110