xref: /honee/qfunctions/bc_slip.h (revision 78e8b7da6af85c065c35ddcb7a107c82a97d64cc)
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 
189ed3d70dSJames Wright   CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
199ed3d70dSJames Wright     const CeedScalar qi[5] = {q[0][i], q[1][i], q[2][i], q[3][i], q[4][i]};
209ed3d70dSJames Wright     State            s     = StateFromQ(newt_ctx, qi, state_var);
219ed3d70dSJames Wright 
22*78e8b7daSJames Wright     CeedScalar wdetJb, normal[3];
23*78e8b7daSJames Wright     QdataBoundaryUnpack_3D(Q, i, q_data_sur, &wdetJb, NULL, normal);
249ed3d70dSJames Wright     wdetJb *= newt_ctx->is_implicit ? -1. : 1.;
259ed3d70dSJames Wright 
269ed3d70dSJames Wright     CeedScalar       vel_reflect[3];
27*78e8b7daSJames Wright     const CeedScalar vel_normal = Dot3(s.Y.velocity, normal);
28*78e8b7daSJames Wright     for (CeedInt j = 0; j < 3; j++) vel_reflect[j] = s.Y.velocity[j] - 2. * normal[j] * vel_normal;
299ed3d70dSJames Wright     const CeedScalar Y_reflect[5] = {s.Y.pressure, vel_reflect[0], vel_reflect[1], vel_reflect[2], s.Y.temperature};
309ed3d70dSJames Wright     State            s_reflect    = StateFromY(newt_ctx, Y_reflect);
319ed3d70dSJames Wright 
32*78e8b7daSJames Wright     StateConservative flux = RiemannFlux_HLLC(newt_ctx, s, s_reflect, normal);
339ed3d70dSJames Wright 
349ed3d70dSJames Wright     CeedScalar Flux[5];
359ed3d70dSJames Wright     UnpackState_U(flux, Flux);
369ed3d70dSJames Wright     for (CeedInt j = 0; j < 5; j++) v[j][i] = -wdetJb * Flux[j];
379ed3d70dSJames Wright 
384b96a86bSJames Wright     if (newt_ctx->is_implicit) {
394b96a86bSJames Wright       CeedScalar zeros[6] = {0.};
409ed3d70dSJames Wright       StoredValuesPack(Q, i, 0, 5, qi, jac_data_sur);
419ed3d70dSJames Wright       StoredValuesPack(Q, i, 5, 6, zeros, jac_data_sur);  // Every output value must be set
429ed3d70dSJames Wright     }
434b96a86bSJames Wright   }
449ed3d70dSJames Wright   return 0;
459ed3d70dSJames Wright }
469ed3d70dSJames Wright 
479ed3d70dSJames Wright CEED_QFUNCTION(Slip_Conserv)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
489ed3d70dSJames Wright   return Slip(ctx, Q, in, out, STATEVAR_CONSERVATIVE);
499ed3d70dSJames Wright }
509ed3d70dSJames Wright 
519ed3d70dSJames Wright CEED_QFUNCTION(Slip_Prim)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
529ed3d70dSJames Wright   return Slip(ctx, Q, in, out, STATEVAR_PRIMITIVE);
539ed3d70dSJames Wright }
549ed3d70dSJames Wright 
559b103f75SJames Wright CEED_QFUNCTION(Slip_Entropy)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
569b103f75SJames Wright   return Slip(ctx, Q, in, out, STATEVAR_ENTROPY);
579b103f75SJames Wright }
589b103f75SJames Wright 
599ed3d70dSJames Wright CEED_QFUNCTION_HELPER int Slip_Jacobian(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out, StateVariable state_var) {
609ed3d70dSJames Wright   const CeedScalar(*dq)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0];
619ed3d70dSJames Wright   const CeedScalar(*q_data_sur)     = in[2];
629ed3d70dSJames Wright   const CeedScalar(*jac_data_sur)   = in[4];
639ed3d70dSJames Wright 
649ed3d70dSJames Wright   CeedScalar(*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];
659ed3d70dSJames Wright 
669ed3d70dSJames Wright   const NewtonianIdealGasContext newt_ctx = (const NewtonianIdealGasContext)ctx;
679ed3d70dSJames Wright 
689ed3d70dSJames Wright   CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
69*78e8b7daSJames Wright     CeedScalar wdetJb, normal[3];
70*78e8b7daSJames Wright     QdataBoundaryUnpack_3D(Q, i, q_data_sur, &wdetJb, NULL, normal);
719ed3d70dSJames Wright     wdetJb *= newt_ctx->is_implicit ? -1. : 1.;
729ed3d70dSJames Wright 
739ed3d70dSJames Wright     CeedScalar qi[5], dqi[5];
749ed3d70dSJames Wright     StoredValuesUnpack(Q, i, 0, 5, jac_data_sur, qi);
759ed3d70dSJames Wright     for (int j = 0; j < 5; j++) dqi[j] = dq[j][i];
769ed3d70dSJames Wright     State s  = StateFromQ(newt_ctx, qi, state_var);
779ed3d70dSJames Wright     State ds = StateFromQ_fwd(newt_ctx, s, dqi, state_var);
789ed3d70dSJames Wright 
799ed3d70dSJames Wright     CeedScalar       vel_reflect[3];
80*78e8b7daSJames Wright     const CeedScalar vel_normal = Dot3(s.Y.velocity, normal);
81*78e8b7daSJames Wright     for (CeedInt j = 0; j < 3; j++) vel_reflect[j] = s.Y.velocity[j] - 2. * normal[j] * vel_normal;
829ed3d70dSJames Wright     const CeedScalar Y_reflect[5] = {s.Y.pressure, vel_reflect[0], vel_reflect[1], vel_reflect[2], s.Y.temperature};
839ed3d70dSJames Wright     State            s_reflect    = StateFromY(newt_ctx, Y_reflect);
849ed3d70dSJames Wright 
859ed3d70dSJames Wright     CeedScalar       dvel_reflect[3];
86*78e8b7daSJames Wright     const CeedScalar dvel_normal = Dot3(ds.Y.velocity, normal);
87*78e8b7daSJames Wright     for (CeedInt j = 0; j < 3; j++) dvel_reflect[j] = ds.Y.velocity[j] - 2. * normal[j] * dvel_normal;
889ed3d70dSJames Wright     const CeedScalar dY_reflect[5] = {ds.Y.pressure, dvel_reflect[0], dvel_reflect[1], dvel_reflect[2], ds.Y.temperature};
899ed3d70dSJames Wright     State            ds_reflect    = StateFromY_fwd(newt_ctx, s_reflect, dY_reflect);
909ed3d70dSJames Wright 
91*78e8b7daSJames Wright     StateConservative dflux = RiemannFlux_HLLC_fwd(newt_ctx, s, ds, s_reflect, ds_reflect, normal);
929ed3d70dSJames Wright 
939ed3d70dSJames Wright     CeedScalar dFlux[5];
949ed3d70dSJames Wright     UnpackState_U(dflux, dFlux);
959ed3d70dSJames Wright     for (CeedInt j = 0; j < 5; j++) v[j][i] = -wdetJb * dFlux[j];
969ed3d70dSJames Wright   }
979ed3d70dSJames Wright   return 0;
989ed3d70dSJames Wright }
999ed3d70dSJames Wright 
1009ed3d70dSJames Wright CEED_QFUNCTION(Slip_Jacobian_Conserv)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
1019ed3d70dSJames Wright   return Slip_Jacobian(ctx, Q, in, out, STATEVAR_CONSERVATIVE);
1029ed3d70dSJames Wright }
1039ed3d70dSJames Wright 
1049ed3d70dSJames Wright CEED_QFUNCTION(Slip_Jacobian_Prim)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
1059ed3d70dSJames Wright   return Slip_Jacobian(ctx, Q, in, out, STATEVAR_PRIMITIVE);
1069ed3d70dSJames Wright }
1079b103f75SJames Wright 
1089b103f75SJames Wright CEED_QFUNCTION(Slip_Jacobian_Entropy)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
1099b103f75SJames Wright   return Slip_Jacobian(ctx, Q, in, out, STATEVAR_ENTROPY);
1109b103f75SJames Wright }
111