15aed82e4SJeremy 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 #include "bc_freestream_type.h" 119f844368SJames Wright #include "newtonian_state.h" 129f844368SJames Wright #include "newtonian_types.h" 139f844368SJames Wright #include "riemann_solver.h" 149f844368SJames Wright 159f844368SJames Wright CEED_QFUNCTION_HELPER int Slip(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out, StateVariable state_var) { 16f21e6b1cSJames Wright const NewtonianIdealGasContext newt_ctx = (const NewtonianIdealGasContext)ctx; 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 CeedScalar(*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0]; 20f21e6b1cSJames Wright CeedScalar(*jac_data_sur) = newt_ctx->is_implicit ? out[1] : NULL; 219f844368SJames Wright 229f844368SJames Wright CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 239f844368SJames Wright const CeedScalar qi[5] = {q[0][i], q[1][i], q[2][i], q[3][i], q[4][i]}; 249f844368SJames Wright State s = StateFromQ(newt_ctx, qi, state_var); 259f844368SJames Wright 269f844368SJames Wright CeedScalar wdetJb, norm[3]; 279f844368SJames Wright QdataBoundaryUnpack_3D(Q, i, q_data_sur, &wdetJb, NULL, norm); 289f844368SJames Wright wdetJb *= newt_ctx->is_implicit ? -1. : 1.; 299f844368SJames Wright 309f844368SJames Wright CeedScalar vel_reflect[3]; 319f844368SJames Wright const CeedScalar vel_normal = Dot3(s.Y.velocity, norm); 329f844368SJames Wright for (CeedInt j = 0; j < 3; j++) vel_reflect[j] = s.Y.velocity[j] - 2. * norm[j] * vel_normal; 339f844368SJames Wright const CeedScalar Y_reflect[5] = {s.Y.pressure, vel_reflect[0], vel_reflect[1], vel_reflect[2], s.Y.temperature}; 349f844368SJames Wright State s_reflect = StateFromY(newt_ctx, Y_reflect); 359f844368SJames Wright 369f844368SJames Wright StateConservative flux = RiemannFlux_HLLC(newt_ctx, s, s_reflect, norm); 379f844368SJames Wright 389f844368SJames Wright CeedScalar Flux[5]; 399f844368SJames Wright UnpackState_U(flux, Flux); 409f844368SJames Wright for (CeedInt j = 0; j < 5; j++) v[j][i] = -wdetJb * Flux[j]; 419f844368SJames Wright 42f21e6b1cSJames Wright if (newt_ctx->is_implicit) { 43f21e6b1cSJames Wright CeedScalar zeros[6] = {0.}; 449f844368SJames Wright StoredValuesPack(Q, i, 0, 5, qi, jac_data_sur); 459f844368SJames Wright StoredValuesPack(Q, i, 5, 6, zeros, jac_data_sur); // Every output value must be set 469f844368SJames Wright } 47f21e6b1cSJames Wright } 489f844368SJames Wright return 0; 499f844368SJames Wright } 509f844368SJames Wright 519f844368SJames Wright CEED_QFUNCTION(Slip_Conserv)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 529f844368SJames Wright return Slip(ctx, Q, in, out, STATEVAR_CONSERVATIVE); 539f844368SJames Wright } 549f844368SJames Wright 559f844368SJames Wright CEED_QFUNCTION(Slip_Prim)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 569f844368SJames Wright return Slip(ctx, Q, in, out, STATEVAR_PRIMITIVE); 579f844368SJames Wright } 589f844368SJames Wright 59*a2d72b6fSJames Wright CEED_QFUNCTION(Slip_Entropy)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 60*a2d72b6fSJames Wright return Slip(ctx, Q, in, out, STATEVAR_ENTROPY); 61*a2d72b6fSJames Wright } 62*a2d72b6fSJames Wright 639f844368SJames Wright CEED_QFUNCTION_HELPER int Slip_Jacobian(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out, StateVariable state_var) { 649f844368SJames Wright const CeedScalar(*dq)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0]; 659f844368SJames Wright const CeedScalar(*q_data_sur) = in[2]; 669f844368SJames Wright const CeedScalar(*jac_data_sur) = in[4]; 679f844368SJames Wright 689f844368SJames Wright CeedScalar(*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0]; 699f844368SJames Wright 709f844368SJames Wright const NewtonianIdealGasContext newt_ctx = (const NewtonianIdealGasContext)ctx; 719f844368SJames Wright 729f844368SJames Wright CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 739f844368SJames Wright CeedScalar wdetJb, norm[3]; 749f844368SJames Wright QdataBoundaryUnpack_3D(Q, i, q_data_sur, &wdetJb, NULL, norm); 759f844368SJames Wright wdetJb *= newt_ctx->is_implicit ? -1. : 1.; 769f844368SJames Wright 779f844368SJames Wright CeedScalar qi[5], dqi[5]; 789f844368SJames Wright StoredValuesUnpack(Q, i, 0, 5, jac_data_sur, qi); 799f844368SJames Wright for (int j = 0; j < 5; j++) dqi[j] = dq[j][i]; 809f844368SJames Wright State s = StateFromQ(newt_ctx, qi, state_var); 819f844368SJames Wright State ds = StateFromQ_fwd(newt_ctx, s, dqi, state_var); 829f844368SJames Wright 839f844368SJames Wright CeedScalar vel_reflect[3]; 849f844368SJames Wright const CeedScalar vel_normal = Dot3(s.Y.velocity, norm); 859f844368SJames Wright for (CeedInt j = 0; j < 3; j++) vel_reflect[j] = s.Y.velocity[j] - 2. * norm[j] * vel_normal; 869f844368SJames Wright const CeedScalar Y_reflect[5] = {s.Y.pressure, vel_reflect[0], vel_reflect[1], vel_reflect[2], s.Y.temperature}; 879f844368SJames Wright State s_reflect = StateFromY(newt_ctx, Y_reflect); 889f844368SJames Wright 899f844368SJames Wright CeedScalar dvel_reflect[3]; 909f844368SJames Wright const CeedScalar dvel_normal = Dot3(ds.Y.velocity, norm); 919f844368SJames Wright for (CeedInt j = 0; j < 3; j++) dvel_reflect[j] = ds.Y.velocity[j] - 2. * norm[j] * dvel_normal; 929f844368SJames Wright const CeedScalar dY_reflect[5] = {ds.Y.pressure, dvel_reflect[0], dvel_reflect[1], dvel_reflect[2], ds.Y.temperature}; 939f844368SJames Wright State ds_reflect = StateFromY_fwd(newt_ctx, s_reflect, dY_reflect); 949f844368SJames Wright 959f844368SJames Wright StateConservative dflux = RiemannFlux_HLLC_fwd(newt_ctx, s, ds, s_reflect, ds_reflect, norm); 969f844368SJames Wright 979f844368SJames Wright CeedScalar dFlux[5]; 989f844368SJames Wright UnpackState_U(dflux, dFlux); 999f844368SJames Wright for (CeedInt j = 0; j < 5; j++) v[j][i] = -wdetJb * dFlux[j]; 1009f844368SJames Wright } 1019f844368SJames Wright return 0; 1029f844368SJames Wright } 1039f844368SJames Wright 1049f844368SJames Wright CEED_QFUNCTION(Slip_Jacobian_Conserv)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 1059f844368SJames Wright return Slip_Jacobian(ctx, Q, in, out, STATEVAR_CONSERVATIVE); 1069f844368SJames Wright } 1079f844368SJames Wright 1089f844368SJames Wright CEED_QFUNCTION(Slip_Jacobian_Prim)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 1099f844368SJames Wright return Slip_Jacobian(ctx, Q, in, out, STATEVAR_PRIMITIVE); 1109f844368SJames Wright } 111*a2d72b6fSJames Wright 112*a2d72b6fSJames Wright CEED_QFUNCTION(Slip_Jacobian_Entropy)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 113*a2d72b6fSJames Wright return Slip_Jacobian(ctx, Q, in, out, STATEVAR_ENTROPY); 114*a2d72b6fSJames Wright } 115