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