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