1*5aed82e4SJeremy L Thompson // Copyright (c) 2017-2024, Lawrence Livermore National Security, LLC and other CEED contributors. 29f844368SJames Wright // All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 39f844368SJames Wright // 49f844368SJames Wright // SPDX-License-Identifier: BSD-2-Clause 59f844368SJames Wright // 69f844368SJames Wright // This file is part of CEED: http://github.com/ceed 79f844368SJames Wright 89f844368SJames Wright /// @file 99f844368SJames Wright /// QFunctions for the `bc_slip` boundary conditions 109f844368SJames Wright 119f844368SJames Wright #include "bc_freestream_type.h" 129f844368SJames Wright #include "newtonian_state.h" 139f844368SJames Wright #include "newtonian_types.h" 149f844368SJames Wright #include "riemann_solver.h" 159f844368SJames Wright 169f844368SJames Wright CEED_QFUNCTION_HELPER int Slip(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out, StateVariable state_var) { 179f844368SJames Wright const CeedScalar(*q)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0]; 189f844368SJames Wright const CeedScalar(*q_data_sur) = in[2]; 199f844368SJames Wright 209f844368SJames Wright CeedScalar(*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0]; 219f844368SJames Wright CeedScalar(*jac_data_sur) = out[1]; 229f844368SJames Wright 239f844368SJames Wright const NewtonianIdealGasContext newt_ctx = (const NewtonianIdealGasContext)ctx; 249f844368SJames Wright const CeedScalar zeros[6] = {0.}; 259f844368SJames Wright 269f844368SJames Wright CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 279f844368SJames Wright const CeedScalar qi[5] = {q[0][i], q[1][i], q[2][i], q[3][i], q[4][i]}; 289f844368SJames Wright State s = StateFromQ(newt_ctx, qi, state_var); 299f844368SJames Wright 309f844368SJames Wright CeedScalar wdetJb, norm[3]; 319f844368SJames Wright QdataBoundaryUnpack_3D(Q, i, q_data_sur, &wdetJb, NULL, norm); 329f844368SJames Wright wdetJb *= newt_ctx->is_implicit ? -1. : 1.; 339f844368SJames Wright 349f844368SJames Wright CeedScalar vel_reflect[3]; 359f844368SJames Wright const CeedScalar vel_normal = Dot3(s.Y.velocity, norm); 369f844368SJames Wright for (CeedInt j = 0; j < 3; j++) vel_reflect[j] = s.Y.velocity[j] - 2. * norm[j] * vel_normal; 379f844368SJames Wright const CeedScalar Y_reflect[5] = {s.Y.pressure, vel_reflect[0], vel_reflect[1], vel_reflect[2], s.Y.temperature}; 389f844368SJames Wright State s_reflect = StateFromY(newt_ctx, Y_reflect); 399f844368SJames Wright 409f844368SJames Wright StateConservative flux = RiemannFlux_HLLC(newt_ctx, s, s_reflect, norm); 419f844368SJames Wright 429f844368SJames Wright CeedScalar Flux[5]; 439f844368SJames Wright UnpackState_U(flux, Flux); 449f844368SJames Wright for (CeedInt j = 0; j < 5; j++) v[j][i] = -wdetJb * Flux[j]; 459f844368SJames Wright 469f844368SJames Wright StoredValuesPack(Q, i, 0, 5, qi, jac_data_sur); 479f844368SJames Wright StoredValuesPack(Q, i, 5, 6, zeros, jac_data_sur); // Every output value must be set 489f844368SJames Wright } 499f844368SJames Wright return 0; 509f844368SJames Wright } 519f844368SJames Wright 529f844368SJames Wright CEED_QFUNCTION(Slip_Conserv)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 539f844368SJames Wright return Slip(ctx, Q, in, out, STATEVAR_CONSERVATIVE); 549f844368SJames Wright } 559f844368SJames Wright 569f844368SJames Wright CEED_QFUNCTION(Slip_Prim)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 579f844368SJames Wright return Slip(ctx, Q, in, out, STATEVAR_PRIMITIVE); 589f844368SJames Wright } 599f844368SJames Wright 609f844368SJames Wright CEED_QFUNCTION_HELPER int Slip_Jacobian(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out, StateVariable state_var) { 619f844368SJames Wright const CeedScalar(*dq)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0]; 629f844368SJames Wright const CeedScalar(*q_data_sur) = in[2]; 639f844368SJames Wright const CeedScalar(*jac_data_sur) = in[4]; 649f844368SJames Wright 659f844368SJames Wright CeedScalar(*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0]; 669f844368SJames Wright 679f844368SJames Wright const NewtonianIdealGasContext newt_ctx = (const NewtonianIdealGasContext)ctx; 689f844368SJames Wright 699f844368SJames Wright CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 709f844368SJames Wright CeedScalar wdetJb, norm[3]; 719f844368SJames Wright QdataBoundaryUnpack_3D(Q, i, q_data_sur, &wdetJb, NULL, norm); 729f844368SJames Wright wdetJb *= newt_ctx->is_implicit ? -1. : 1.; 739f844368SJames Wright 749f844368SJames Wright CeedScalar qi[5], dqi[5]; 759f844368SJames Wright StoredValuesUnpack(Q, i, 0, 5, jac_data_sur, qi); 769f844368SJames Wright for (int j = 0; j < 5; j++) dqi[j] = dq[j][i]; 779f844368SJames Wright State s = StateFromQ(newt_ctx, qi, state_var); 789f844368SJames Wright State ds = StateFromQ_fwd(newt_ctx, s, dqi, state_var); 799f844368SJames Wright 809f844368SJames Wright CeedScalar vel_reflect[3]; 819f844368SJames Wright const CeedScalar vel_normal = Dot3(s.Y.velocity, norm); 829f844368SJames Wright for (CeedInt j = 0; j < 3; j++) vel_reflect[j] = s.Y.velocity[j] - 2. * norm[j] * vel_normal; 839f844368SJames Wright const CeedScalar Y_reflect[5] = {s.Y.pressure, vel_reflect[0], vel_reflect[1], vel_reflect[2], s.Y.temperature}; 849f844368SJames Wright State s_reflect = StateFromY(newt_ctx, Y_reflect); 859f844368SJames Wright 869f844368SJames Wright CeedScalar dvel_reflect[3]; 879f844368SJames Wright const CeedScalar dvel_normal = Dot3(ds.Y.velocity, norm); 889f844368SJames Wright for (CeedInt j = 0; j < 3; j++) dvel_reflect[j] = ds.Y.velocity[j] - 2. * norm[j] * dvel_normal; 899f844368SJames Wright const CeedScalar dY_reflect[5] = {ds.Y.pressure, dvel_reflect[0], dvel_reflect[1], dvel_reflect[2], ds.Y.temperature}; 909f844368SJames Wright State ds_reflect = StateFromY_fwd(newt_ctx, s_reflect, dY_reflect); 919f844368SJames Wright 929f844368SJames Wright StateConservative dflux = RiemannFlux_HLLC_fwd(newt_ctx, s, ds, s_reflect, ds_reflect, norm); 939f844368SJames Wright 949f844368SJames Wright CeedScalar dFlux[5]; 959f844368SJames Wright UnpackState_U(dflux, dFlux); 969f844368SJames Wright for (CeedInt j = 0; j < 5; j++) v[j][i] = -wdetJb * dFlux[j]; 979f844368SJames Wright } 989f844368SJames Wright return 0; 999f844368SJames Wright } 1009f844368SJames Wright 1019f844368SJames Wright CEED_QFUNCTION(Slip_Jacobian_Conserv)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 1029f844368SJames Wright return Slip_Jacobian(ctx, Q, in, out, STATEVAR_CONSERVATIVE); 1039f844368SJames Wright } 1049f844368SJames Wright 1059f844368SJames Wright CEED_QFUNCTION(Slip_Jacobian_Prim)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 1069f844368SJames Wright return Slip_Jacobian(ctx, Q, in, out, STATEVAR_PRIMITIVE); 1079f844368SJames Wright } 108