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