1*9f844368SJames Wright // Copyright (c) 2017-2023, Lawrence Livermore National Security, LLC and other CEED contributors. 2*9f844368SJames Wright // All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 3*9f844368SJames Wright // 4*9f844368SJames Wright // SPDX-License-Identifier: BSD-2-Clause 5*9f844368SJames Wright // 6*9f844368SJames Wright // This file is part of CEED: http://github.com/ceed 7*9f844368SJames Wright 8*9f844368SJames Wright /// @file 9*9f844368SJames Wright /// QFunctions for the `bc_slip` boundary conditions 10*9f844368SJames Wright 11*9f844368SJames Wright #include "bc_freestream_type.h" 12*9f844368SJames Wright #include "newtonian_state.h" 13*9f844368SJames Wright #include "newtonian_types.h" 14*9f844368SJames Wright #include "riemann_solver.h" 15*9f844368SJames Wright 16*9f844368SJames Wright CEED_QFUNCTION_HELPER int Slip(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out, StateVariable state_var) { 17*9f844368SJames Wright const CeedScalar(*q)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0]; 18*9f844368SJames Wright const CeedScalar(*q_data_sur) = in[2]; 19*9f844368SJames Wright 20*9f844368SJames Wright CeedScalar(*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0]; 21*9f844368SJames Wright CeedScalar(*jac_data_sur) = out[1]; 22*9f844368SJames Wright 23*9f844368SJames Wright const NewtonianIdealGasContext newt_ctx = (const NewtonianIdealGasContext)ctx; 24*9f844368SJames Wright const CeedScalar zeros[6] = {0.}; 25*9f844368SJames Wright 26*9f844368SJames Wright CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 27*9f844368SJames Wright const CeedScalar qi[5] = {q[0][i], q[1][i], q[2][i], q[3][i], q[4][i]}; 28*9f844368SJames Wright State s = StateFromQ(newt_ctx, qi, state_var); 29*9f844368SJames Wright 30*9f844368SJames Wright CeedScalar wdetJb, norm[3]; 31*9f844368SJames Wright QdataBoundaryUnpack_3D(Q, i, q_data_sur, &wdetJb, NULL, norm); 32*9f844368SJames Wright wdetJb *= newt_ctx->is_implicit ? -1. : 1.; 33*9f844368SJames Wright 34*9f844368SJames Wright CeedScalar vel_reflect[3]; 35*9f844368SJames Wright const CeedScalar vel_normal = Dot3(s.Y.velocity, norm); 36*9f844368SJames Wright for (CeedInt j = 0; j < 3; j++) vel_reflect[j] = s.Y.velocity[j] - 2. * norm[j] * vel_normal; 37*9f844368SJames Wright const CeedScalar Y_reflect[5] = {s.Y.pressure, vel_reflect[0], vel_reflect[1], vel_reflect[2], s.Y.temperature}; 38*9f844368SJames Wright State s_reflect = StateFromY(newt_ctx, Y_reflect); 39*9f844368SJames Wright 40*9f844368SJames Wright StateConservative flux = RiemannFlux_HLLC(newt_ctx, s, s_reflect, norm); 41*9f844368SJames Wright 42*9f844368SJames Wright CeedScalar Flux[5]; 43*9f844368SJames Wright UnpackState_U(flux, Flux); 44*9f844368SJames Wright for (CeedInt j = 0; j < 5; j++) v[j][i] = -wdetJb * Flux[j]; 45*9f844368SJames Wright 46*9f844368SJames Wright StoredValuesPack(Q, i, 0, 5, qi, jac_data_sur); 47*9f844368SJames Wright StoredValuesPack(Q, i, 5, 6, zeros, jac_data_sur); // Every output value must be set 48*9f844368SJames Wright } 49*9f844368SJames Wright return 0; 50*9f844368SJames Wright } 51*9f844368SJames Wright 52*9f844368SJames Wright CEED_QFUNCTION(Slip_Conserv)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 53*9f844368SJames Wright return Slip(ctx, Q, in, out, STATEVAR_CONSERVATIVE); 54*9f844368SJames Wright } 55*9f844368SJames Wright 56*9f844368SJames Wright CEED_QFUNCTION(Slip_Prim)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 57*9f844368SJames Wright return Slip(ctx, Q, in, out, STATEVAR_PRIMITIVE); 58*9f844368SJames Wright } 59*9f844368SJames Wright 60*9f844368SJames Wright CEED_QFUNCTION_HELPER int Slip_Jacobian(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out, StateVariable state_var) { 61*9f844368SJames Wright const CeedScalar(*dq)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0]; 62*9f844368SJames Wright const CeedScalar(*q_data_sur) = in[2]; 63*9f844368SJames Wright const CeedScalar(*jac_data_sur) = in[4]; 64*9f844368SJames Wright 65*9f844368SJames Wright CeedScalar(*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0]; 66*9f844368SJames Wright 67*9f844368SJames Wright const NewtonianIdealGasContext newt_ctx = (const NewtonianIdealGasContext)ctx; 68*9f844368SJames Wright 69*9f844368SJames Wright CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 70*9f844368SJames Wright CeedScalar wdetJb, norm[3]; 71*9f844368SJames Wright QdataBoundaryUnpack_3D(Q, i, q_data_sur, &wdetJb, NULL, norm); 72*9f844368SJames Wright wdetJb *= newt_ctx->is_implicit ? -1. : 1.; 73*9f844368SJames Wright 74*9f844368SJames Wright CeedScalar qi[5], dqi[5]; 75*9f844368SJames Wright StoredValuesUnpack(Q, i, 0, 5, jac_data_sur, qi); 76*9f844368SJames Wright for (int j = 0; j < 5; j++) dqi[j] = dq[j][i]; 77*9f844368SJames Wright State s = StateFromQ(newt_ctx, qi, state_var); 78*9f844368SJames Wright State ds = StateFromQ_fwd(newt_ctx, s, dqi, state_var); 79*9f844368SJames Wright 80*9f844368SJames Wright CeedScalar vel_reflect[3]; 81*9f844368SJames Wright const CeedScalar vel_normal = Dot3(s.Y.velocity, norm); 82*9f844368SJames Wright for (CeedInt j = 0; j < 3; j++) vel_reflect[j] = s.Y.velocity[j] - 2. * norm[j] * vel_normal; 83*9f844368SJames Wright const CeedScalar Y_reflect[5] = {s.Y.pressure, vel_reflect[0], vel_reflect[1], vel_reflect[2], s.Y.temperature}; 84*9f844368SJames Wright State s_reflect = StateFromY(newt_ctx, Y_reflect); 85*9f844368SJames Wright 86*9f844368SJames Wright CeedScalar dvel_reflect[3]; 87*9f844368SJames Wright const CeedScalar dvel_normal = Dot3(ds.Y.velocity, norm); 88*9f844368SJames Wright for (CeedInt j = 0; j < 3; j++) dvel_reflect[j] = ds.Y.velocity[j] - 2. * norm[j] * dvel_normal; 89*9f844368SJames Wright const CeedScalar dY_reflect[5] = {ds.Y.pressure, dvel_reflect[0], dvel_reflect[1], dvel_reflect[2], ds.Y.temperature}; 90*9f844368SJames Wright State ds_reflect = StateFromY_fwd(newt_ctx, s_reflect, dY_reflect); 91*9f844368SJames Wright 92*9f844368SJames Wright StateConservative dflux = RiemannFlux_HLLC_fwd(newt_ctx, s, ds, s_reflect, ds_reflect, norm); 93*9f844368SJames Wright 94*9f844368SJames Wright CeedScalar dFlux[5]; 95*9f844368SJames Wright UnpackState_U(dflux, dFlux); 96*9f844368SJames Wright for (CeedInt j = 0; j < 5; j++) v[j][i] = -wdetJb * dFlux[j]; 97*9f844368SJames Wright } 98*9f844368SJames Wright return 0; 99*9f844368SJames Wright } 100*9f844368SJames Wright 101*9f844368SJames Wright CEED_QFUNCTION(Slip_Jacobian_Conserv)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 102*9f844368SJames Wright return Slip_Jacobian(ctx, Q, in, out, STATEVAR_CONSERVATIVE); 103*9f844368SJames Wright } 104*9f844368SJames Wright 105*9f844368SJames Wright CEED_QFUNCTION(Slip_Jacobian_Prim)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 106*9f844368SJames Wright return Slip_Jacobian(ctx, Q, in, out, STATEVAR_PRIMITIVE); 107*9f844368SJames Wright } 108