xref: /honee/qfunctions/bc_slip.h (revision 9ed3d70d58d93bd474ae216081539cf94addd4d0)
1*9ed3d70dSJames Wright // Copyright (c) 2017-2023, Lawrence Livermore National Security, LLC and other CEED contributors.
2*9ed3d70dSJames Wright // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
3*9ed3d70dSJames Wright //
4*9ed3d70dSJames Wright // SPDX-License-Identifier: BSD-2-Clause
5*9ed3d70dSJames Wright //
6*9ed3d70dSJames Wright // This file is part of CEED:  http://github.com/ceed
7*9ed3d70dSJames Wright 
8*9ed3d70dSJames Wright /// @file
9*9ed3d70dSJames Wright /// QFunctions for the `bc_slip` boundary conditions
10*9ed3d70dSJames Wright 
11*9ed3d70dSJames Wright #include "bc_freestream_type.h"
12*9ed3d70dSJames Wright #include "newtonian_state.h"
13*9ed3d70dSJames Wright #include "newtonian_types.h"
14*9ed3d70dSJames Wright #include "riemann_solver.h"
15*9ed3d70dSJames Wright 
16*9ed3d70dSJames Wright CEED_QFUNCTION_HELPER int Slip(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out, StateVariable state_var) {
17*9ed3d70dSJames Wright   const CeedScalar(*q)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0];
18*9ed3d70dSJames Wright   const CeedScalar(*q_data_sur)    = in[2];
19*9ed3d70dSJames Wright 
20*9ed3d70dSJames Wright   CeedScalar(*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];
21*9ed3d70dSJames Wright   CeedScalar(*jac_data_sur)  = out[1];
22*9ed3d70dSJames Wright 
23*9ed3d70dSJames Wright   const NewtonianIdealGasContext newt_ctx = (const NewtonianIdealGasContext)ctx;
24*9ed3d70dSJames Wright   const CeedScalar               zeros[6] = {0.};
25*9ed3d70dSJames Wright 
26*9ed3d70dSJames Wright   CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
27*9ed3d70dSJames Wright     const CeedScalar qi[5] = {q[0][i], q[1][i], q[2][i], q[3][i], q[4][i]};
28*9ed3d70dSJames Wright     State            s     = StateFromQ(newt_ctx, qi, state_var);
29*9ed3d70dSJames Wright 
30*9ed3d70dSJames Wright     CeedScalar wdetJb, norm[3];
31*9ed3d70dSJames Wright     QdataBoundaryUnpack_3D(Q, i, q_data_sur, &wdetJb, NULL, norm);
32*9ed3d70dSJames Wright     wdetJb *= newt_ctx->is_implicit ? -1. : 1.;
33*9ed3d70dSJames Wright 
34*9ed3d70dSJames Wright     CeedScalar       vel_reflect[3];
35*9ed3d70dSJames Wright     const CeedScalar vel_normal = Dot3(s.Y.velocity, norm);
36*9ed3d70dSJames Wright     for (CeedInt j = 0; j < 3; j++) vel_reflect[j] = s.Y.velocity[j] - 2. * norm[j] * vel_normal;
37*9ed3d70dSJames Wright     const CeedScalar Y_reflect[5] = {s.Y.pressure, vel_reflect[0], vel_reflect[1], vel_reflect[2], s.Y.temperature};
38*9ed3d70dSJames Wright     State            s_reflect    = StateFromY(newt_ctx, Y_reflect);
39*9ed3d70dSJames Wright 
40*9ed3d70dSJames Wright     StateConservative flux = RiemannFlux_HLLC(newt_ctx, s, s_reflect, norm);
41*9ed3d70dSJames Wright 
42*9ed3d70dSJames Wright     CeedScalar Flux[5];
43*9ed3d70dSJames Wright     UnpackState_U(flux, Flux);
44*9ed3d70dSJames Wright     for (CeedInt j = 0; j < 5; j++) v[j][i] = -wdetJb * Flux[j];
45*9ed3d70dSJames Wright 
46*9ed3d70dSJames Wright     StoredValuesPack(Q, i, 0, 5, qi, jac_data_sur);
47*9ed3d70dSJames Wright     StoredValuesPack(Q, i, 5, 6, zeros, jac_data_sur);  // Every output value must be set
48*9ed3d70dSJames Wright   }
49*9ed3d70dSJames Wright   return 0;
50*9ed3d70dSJames Wright }
51*9ed3d70dSJames Wright 
52*9ed3d70dSJames Wright CEED_QFUNCTION(Slip_Conserv)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
53*9ed3d70dSJames Wright   return Slip(ctx, Q, in, out, STATEVAR_CONSERVATIVE);
54*9ed3d70dSJames Wright }
55*9ed3d70dSJames Wright 
56*9ed3d70dSJames Wright CEED_QFUNCTION(Slip_Prim)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
57*9ed3d70dSJames Wright   return Slip(ctx, Q, in, out, STATEVAR_PRIMITIVE);
58*9ed3d70dSJames Wright }
59*9ed3d70dSJames Wright 
60*9ed3d70dSJames Wright CEED_QFUNCTION_HELPER int Slip_Jacobian(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out, StateVariable state_var) {
61*9ed3d70dSJames Wright   const CeedScalar(*dq)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0];
62*9ed3d70dSJames Wright   const CeedScalar(*q_data_sur)     = in[2];
63*9ed3d70dSJames Wright   const CeedScalar(*jac_data_sur)   = in[4];
64*9ed3d70dSJames Wright 
65*9ed3d70dSJames Wright   CeedScalar(*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];
66*9ed3d70dSJames Wright 
67*9ed3d70dSJames Wright   const NewtonianIdealGasContext newt_ctx = (const NewtonianIdealGasContext)ctx;
68*9ed3d70dSJames Wright 
69*9ed3d70dSJames Wright   CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
70*9ed3d70dSJames Wright     CeedScalar wdetJb, norm[3];
71*9ed3d70dSJames Wright     QdataBoundaryUnpack_3D(Q, i, q_data_sur, &wdetJb, NULL, norm);
72*9ed3d70dSJames Wright     wdetJb *= newt_ctx->is_implicit ? -1. : 1.;
73*9ed3d70dSJames Wright 
74*9ed3d70dSJames Wright     CeedScalar qi[5], dqi[5];
75*9ed3d70dSJames Wright     StoredValuesUnpack(Q, i, 0, 5, jac_data_sur, qi);
76*9ed3d70dSJames Wright     for (int j = 0; j < 5; j++) dqi[j] = dq[j][i];
77*9ed3d70dSJames Wright     State s  = StateFromQ(newt_ctx, qi, state_var);
78*9ed3d70dSJames Wright     State ds = StateFromQ_fwd(newt_ctx, s, dqi, state_var);
79*9ed3d70dSJames Wright 
80*9ed3d70dSJames Wright     CeedScalar       vel_reflect[3];
81*9ed3d70dSJames Wright     const CeedScalar vel_normal = Dot3(s.Y.velocity, norm);
82*9ed3d70dSJames Wright     for (CeedInt j = 0; j < 3; j++) vel_reflect[j] = s.Y.velocity[j] - 2. * norm[j] * vel_normal;
83*9ed3d70dSJames Wright     const CeedScalar Y_reflect[5] = {s.Y.pressure, vel_reflect[0], vel_reflect[1], vel_reflect[2], s.Y.temperature};
84*9ed3d70dSJames Wright     State            s_reflect    = StateFromY(newt_ctx, Y_reflect);
85*9ed3d70dSJames Wright 
86*9ed3d70dSJames Wright     CeedScalar       dvel_reflect[3];
87*9ed3d70dSJames Wright     const CeedScalar dvel_normal = Dot3(ds.Y.velocity, norm);
88*9ed3d70dSJames Wright     for (CeedInt j = 0; j < 3; j++) dvel_reflect[j] = ds.Y.velocity[j] - 2. * norm[j] * dvel_normal;
89*9ed3d70dSJames Wright     const CeedScalar dY_reflect[5] = {ds.Y.pressure, dvel_reflect[0], dvel_reflect[1], dvel_reflect[2], ds.Y.temperature};
90*9ed3d70dSJames Wright     State            ds_reflect    = StateFromY_fwd(newt_ctx, s_reflect, dY_reflect);
91*9ed3d70dSJames Wright 
92*9ed3d70dSJames Wright     StateConservative dflux = RiemannFlux_HLLC_fwd(newt_ctx, s, ds, s_reflect, ds_reflect, norm);
93*9ed3d70dSJames Wright 
94*9ed3d70dSJames Wright     CeedScalar dFlux[5];
95*9ed3d70dSJames Wright     UnpackState_U(dflux, dFlux);
96*9ed3d70dSJames Wright     for (CeedInt j = 0; j < 5; j++) v[j][i] = -wdetJb * dFlux[j];
97*9ed3d70dSJames Wright   }
98*9ed3d70dSJames Wright   return 0;
99*9ed3d70dSJames Wright }
100*9ed3d70dSJames Wright 
101*9ed3d70dSJames Wright CEED_QFUNCTION(Slip_Jacobian_Conserv)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
102*9ed3d70dSJames Wright   return Slip_Jacobian(ctx, Q, in, out, STATEVAR_CONSERVATIVE);
103*9ed3d70dSJames Wright }
104*9ed3d70dSJames Wright 
105*9ed3d70dSJames Wright CEED_QFUNCTION(Slip_Jacobian_Prim)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
106*9ed3d70dSJames Wright   return Slip_Jacobian(ctx, Q, in, out, STATEVAR_PRIMITIVE);
107*9ed3d70dSJames Wright }
108