xref: /libCEED/examples/fluids/qfunctions/riemann_solver.h (revision 9f84436874b0bedcb473aab1faa446b08959d274)
1*9f844368SJames Wright // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors.
2*9f844368SJames Wright // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
3*9f844368SJames Wright //
4*9f844368SJames Wright // SPDX-License-Identifier: BSD-2-Clause
5*9f844368SJames Wright //
6*9f844368SJames Wright // This file is part of CEED:  http://github.com/ceed
7*9f844368SJames Wright 
8*9f844368SJames Wright /// @file
9*9f844368SJames Wright /// Helper functions for solving the Riemann problem.
10*9f844368SJames Wright // The left and right states are specified from the perspective of an outward-facing normal vector pointing left to right:
11*9f844368SJames Wright //
12*9f844368SJames Wright //     (domain)
13*9f844368SJames Wright //    /               (outward facing normal)
14*9f844368SJames Wright // |------------|   /
15*9f844368SJames Wright // |            |  /
16*9f844368SJames Wright // |    Left    |---->  Right
17*9f844368SJames Wright // | (Interior) |    (Exterior)
18*9f844368SJames Wright // |------------|
19*9f844368SJames Wright //
20*9f844368SJames Wright // The right state is exterior to the domain and the left state is the interior to the domain.
21*9f844368SJames Wright // Much of the work references Eleuterio F. Toro's "Riemann Solvers and Numerical Methods for Fluid Dynamics", 2009
22*9f844368SJames Wright 
23*9f844368SJames Wright #ifndef riemann_solver_h
24*9f844368SJames Wright #define riemann_solver_h
25*9f844368SJames Wright 
26*9f844368SJames Wright #include "newtonian_state.h"
27*9f844368SJames Wright #include "newtonian_types.h"
28*9f844368SJames Wright 
29*9f844368SJames Wright enum RiemannFluxType_ { RIEMANN_HLL, RIEMANN_HLLC };
30*9f844368SJames Wright typedef enum RiemannFluxType_ RiemannFluxType;
31*9f844368SJames Wright 
32*9f844368SJames Wright typedef struct {
33*9f844368SJames Wright   CeedScalar left, right;
34*9f844368SJames Wright } RoeWeights;
35*9f844368SJames Wright 
36*9f844368SJames Wright CEED_QFUNCTION_HELPER RoeWeights RoeSetup(CeedScalar rho_left, CeedScalar rho_right) {
37*9f844368SJames Wright   CeedScalar sqrt_left = sqrt(rho_left), sqrt_right = sqrt(rho_right);
38*9f844368SJames Wright   RoeWeights w = {sqrt_left / (sqrt_left + sqrt_right), sqrt_right / (sqrt_left + sqrt_right)};
39*9f844368SJames Wright   return w;
40*9f844368SJames Wright }
41*9f844368SJames Wright 
42*9f844368SJames Wright CEED_QFUNCTION_HELPER RoeWeights RoeSetup_fwd(CeedScalar rho_left, CeedScalar rho_right, CeedScalar drho_left, CeedScalar drho_right) {
43*9f844368SJames Wright   CeedScalar sqrt_left = sqrt(rho_left), sqrt_right = sqrt(rho_right);
44*9f844368SJames Wright   CeedScalar square_sum_root = Square(sqrt_left + sqrt_right);
45*9f844368SJames Wright   CeedScalar r_right = (sqrt_left / (2 * sqrt_right * square_sum_root)) * drho_right - (sqrt_right / (2 * sqrt_left * square_sum_root)) * drho_left;
46*9f844368SJames Wright   CeedScalar r_left  = (sqrt_right / (2 * sqrt_left * square_sum_root)) * drho_left - (sqrt_left / (2 * sqrt_right * square_sum_root)) * drho_right;
47*9f844368SJames Wright   RoeWeights dw      = {r_left, r_right};
48*9f844368SJames Wright   return dw;
49*9f844368SJames Wright }
50*9f844368SJames Wright 
51*9f844368SJames Wright CEED_QFUNCTION_HELPER CeedScalar RoeAverage(RoeWeights r, CeedScalar q_left, CeedScalar q_right) { return r.left * q_left + r.right * q_right; }
52*9f844368SJames Wright 
53*9f844368SJames Wright CEED_QFUNCTION_HELPER CeedScalar RoeAverage_fwd(RoeWeights r, RoeWeights dr, CeedScalar q_left, CeedScalar q_right, CeedScalar dq_left,
54*9f844368SJames Wright                                                 CeedScalar dq_right) {
55*9f844368SJames Wright   return q_right * dr.right + q_left * dr.left + r.right * dq_right + r.left * dq_left;
56*9f844368SJames Wright }
57*9f844368SJames Wright 
58*9f844368SJames Wright CEED_QFUNCTION_HELPER StateConservative Flux_HLL(State left, State right, StateConservative flux_left, StateConservative flux_right,
59*9f844368SJames Wright                                                  CeedScalar s_left, CeedScalar s_right) {
60*9f844368SJames Wright   CeedScalar U_left[5], U_right[5], F_right[5], F_left[5], F_hll[5];
61*9f844368SJames Wright   UnpackState_U(left.U, U_left);
62*9f844368SJames Wright   UnpackState_U(right.U, U_right);
63*9f844368SJames Wright   UnpackState_U(flux_left, F_left);
64*9f844368SJames Wright   UnpackState_U(flux_right, F_right);
65*9f844368SJames Wright   for (int i = 0; i < 5; i++) {
66*9f844368SJames Wright     F_hll[i] = (s_right * F_left[i] - s_left * F_right[i] + s_left * s_right * (U_right[i] - U_left[i])) / (s_right - s_left);
67*9f844368SJames Wright   }
68*9f844368SJames Wright   StateConservative F = {
69*9f844368SJames Wright       F_hll[0],
70*9f844368SJames Wright       {F_hll[1], F_hll[2], F_hll[3]},
71*9f844368SJames Wright       F_hll[4],
72*9f844368SJames Wright   };
73*9f844368SJames Wright   return F;
74*9f844368SJames Wright }
75*9f844368SJames Wright 
76*9f844368SJames Wright CEED_QFUNCTION_HELPER StateConservative Flux_HLL_fwd(State left, State right, State dleft, State dright, StateConservative flux_left,
77*9f844368SJames Wright                                                      StateConservative flux_right, StateConservative dflux_left, StateConservative dflux_right,
78*9f844368SJames Wright                                                      CeedScalar S_l, CeedScalar S_r, CeedScalar dS_l, CeedScalar dS_r) {
79*9f844368SJames Wright   CeedScalar U_l[5], U_r[5], F_r[5], F_l[5];
80*9f844368SJames Wright   UnpackState_U(left.U, U_l);
81*9f844368SJames Wright   UnpackState_U(right.U, U_r);
82*9f844368SJames Wright   UnpackState_U(flux_left, F_l);
83*9f844368SJames Wright   UnpackState_U(flux_right, F_r);
84*9f844368SJames Wright 
85*9f844368SJames Wright   CeedScalar dU_l[5], dU_r[5], dF_r[5], dF_l[5], dF_hll[5] = {0.};
86*9f844368SJames Wright   UnpackState_U(dleft.U, dU_l);
87*9f844368SJames Wright   UnpackState_U(dright.U, dU_r);
88*9f844368SJames Wright   UnpackState_U(dflux_left, dF_l);
89*9f844368SJames Wright   UnpackState_U(dflux_right, dF_r);
90*9f844368SJames Wright   for (int i = 0; i < 5; i++) {
91*9f844368SJames Wright     const CeedScalar U_diff      = U_r[i] - U_l[i];
92*9f844368SJames Wright     const CeedScalar S_diff      = S_r - S_l;
93*9f844368SJames Wright     const CeedScalar F_hll_denom = S_r * F_l[i] - S_l * F_r[i] + S_l * S_r * U_diff;
94*9f844368SJames Wright 
95*9f844368SJames Wright     dF_hll[i] += ((F_l[i] + S_r * U_diff) * S_diff - F_hll_denom) / Square(S_diff) * dS_r;
96*9f844368SJames Wright     dF_hll[i] += ((-F_r[i] + S_r * U_diff) * S_diff + F_hll_denom) / Square(S_diff) * dS_l;
97*9f844368SJames Wright     dF_hll[i] += (S_r * dF_l[i] - S_l * dF_r[i] + S_r * S_l * dU_r[i] - S_r * S_l * dU_l[i]) / S_diff;
98*9f844368SJames Wright   }
99*9f844368SJames Wright   StateConservative dF = {
100*9f844368SJames Wright       dF_hll[0],
101*9f844368SJames Wright       {dF_hll[1], dF_hll[2], dF_hll[3]},
102*9f844368SJames Wright       dF_hll[4],
103*9f844368SJames Wright   };
104*9f844368SJames Wright   return dF;
105*9f844368SJames Wright }
106*9f844368SJames Wright 
107*9f844368SJames Wright CEED_QFUNCTION_HELPER void ComputeHLLSpeeds_Roe(NewtonianIdealGasContext gas, State left, CeedScalar u_left, State right, CeedScalar u_right,
108*9f844368SJames Wright                                                 CeedScalar *s_left, CeedScalar *s_right) {
109*9f844368SJames Wright   const CeedScalar gamma = HeatCapacityRatio(gas);
110*9f844368SJames Wright 
111*9f844368SJames Wright   RoeWeights r = RoeSetup(left.U.density, right.U.density);
112*9f844368SJames Wright   // Speed estimate
113*9f844368SJames Wright   // Roe average eigenvalues for left and right non-linear waves.
114*9f844368SJames Wright   // Stability requires that these speed estimates are *at least* as fast as the physical wave speeds.
115*9f844368SJames Wright   CeedScalar u_roe = RoeAverage(r, u_left, u_right);
116*9f844368SJames Wright 
117*9f844368SJames Wright   // TODO: revisit this for gravity
118*9f844368SJames Wright   CeedScalar H_left  = TotalSpecificEnthalpy(gas, left);
119*9f844368SJames Wright   CeedScalar H_right = TotalSpecificEnthalpy(gas, right);
120*9f844368SJames Wright   CeedScalar H_roe   = RoeAverage(r, H_left, H_right);
121*9f844368SJames Wright   CeedScalar a_roe   = sqrt((gamma - 1) * (H_roe - 0.5 * Square(u_roe)));
122*9f844368SJames Wright 
123*9f844368SJames Wright   // Einfeldt (1988) justifies (and Toro's book repeats) that Roe speeds can be used here.
124*9f844368SJames Wright   *s_left  = u_roe - a_roe;
125*9f844368SJames Wright   *s_right = u_roe + a_roe;
126*9f844368SJames Wright }
127*9f844368SJames Wright 
128*9f844368SJames Wright CEED_QFUNCTION_HELPER void ComputeHLLSpeeds_Roe_fwd(NewtonianIdealGasContext gas, State left, State dleft, CeedScalar u_left, CeedScalar du_left,
129*9f844368SJames Wright                                                     State right, State dright, CeedScalar u_right, CeedScalar du_right, CeedScalar *s_left,
130*9f844368SJames Wright                                                     CeedScalar *ds_left, CeedScalar *s_right, CeedScalar *ds_right) {
131*9f844368SJames Wright   const CeedScalar gamma = HeatCapacityRatio(gas);
132*9f844368SJames Wright 
133*9f844368SJames Wright   RoeWeights r  = RoeSetup(left.U.density, right.U.density);
134*9f844368SJames Wright   RoeWeights dr = RoeSetup_fwd(left.U.density, right.U.density, dleft.U.density, dright.U.density);
135*9f844368SJames Wright   // Speed estimate
136*9f844368SJames Wright   // Roe average eigenvalues for left and right non-linear waves.
137*9f844368SJames Wright   // Stability requires that these speed estimates are *at least* as fast as the physical wave speeds.
138*9f844368SJames Wright   CeedScalar u_roe  = RoeAverage(r, u_left, u_right);
139*9f844368SJames Wright   CeedScalar du_roe = RoeAverage_fwd(r, dr, u_left, u_right, du_left, du_right);
140*9f844368SJames Wright 
141*9f844368SJames Wright   CeedScalar H_left   = TotalSpecificEnthalpy(gas, left);
142*9f844368SJames Wright   CeedScalar H_right  = TotalSpecificEnthalpy(gas, right);
143*9f844368SJames Wright   CeedScalar dH_left  = TotalSpecificEnthalpy_fwd(gas, left, dleft);
144*9f844368SJames Wright   CeedScalar dH_right = TotalSpecificEnthalpy_fwd(gas, right, dright);
145*9f844368SJames Wright 
146*9f844368SJames Wright   CeedScalar H_roe  = RoeAverage(r, H_left, H_right);
147*9f844368SJames Wright   CeedScalar dH_roe = RoeAverage_fwd(r, dr, H_left, H_right, dH_left, dH_right);
148*9f844368SJames Wright   CeedScalar a_roe  = sqrt((gamma - 1) * (H_roe - 0.5 * Square(u_roe)));
149*9f844368SJames Wright   CeedScalar da_roe = 0.5 * (gamma - 1) / sqrt(H_roe) * dH_roe - 0.5 * sqrt(gamma - 1) * u_roe / sqrt(H_roe - 0.5 * Square(u_roe)) * du_roe;
150*9f844368SJames Wright 
151*9f844368SJames Wright   *s_left   = u_roe - a_roe;
152*9f844368SJames Wright   *ds_left  = du_roe - da_roe;
153*9f844368SJames Wright   *s_right  = u_roe + a_roe;
154*9f844368SJames Wright   *ds_right = du_roe + da_roe;
155*9f844368SJames Wright }
156*9f844368SJames Wright 
157*9f844368SJames Wright // *****************************************************************************
158*9f844368SJames Wright // @brief Harten Lax VanLeer (HLL) approximate Riemann solver.
159*9f844368SJames Wright // Taking in two states (left, right) and returns RiemannFlux_HLL.
160*9f844368SJames Wright // The left and right states are specified from the perspective of an outward-facing normal vector pointing left to right.
161*9f844368SJames Wright //
162*9f844368SJames Wright // @param[in] gas    NewtonianIdealGasContext for the fluid
163*9f844368SJames Wright // @param[in] left   Fluid state of the domain interior (the current solution)
164*9f844368SJames Wright // @param[in] right  Fluid state of the domain exterior (free stream conditions)
165*9f844368SJames Wright // @param[in] normal Normalized, outward facing boundary normal vector
166*9f844368SJames Wright //
167*9f844368SJames Wright // @return StateConservative with HLL Riemann Flux
168*9f844368SJames Wright // *****************************************************************************
169*9f844368SJames Wright CEED_QFUNCTION_HELPER StateConservative RiemannFlux_HLL(NewtonianIdealGasContext gas, State left, State right, const CeedScalar normal[3]) {
170*9f844368SJames Wright   StateConservative flux_left  = FluxInviscidDotNormal(gas, left, normal);
171*9f844368SJames Wright   StateConservative flux_right = FluxInviscidDotNormal(gas, right, normal);
172*9f844368SJames Wright 
173*9f844368SJames Wright   CeedScalar u_left  = Dot3(left.Y.velocity, normal);
174*9f844368SJames Wright   CeedScalar u_right = Dot3(right.Y.velocity, normal);
175*9f844368SJames Wright 
176*9f844368SJames Wright   CeedScalar s_left, s_right;
177*9f844368SJames Wright   ComputeHLLSpeeds_Roe(gas, left, u_left, right, u_right, &s_left, &s_right);
178*9f844368SJames Wright 
179*9f844368SJames Wright   // Compute HLL flux
180*9f844368SJames Wright   if (0 <= s_left) {
181*9f844368SJames Wright     return flux_left;
182*9f844368SJames Wright   } else if (s_right <= 0) {
183*9f844368SJames Wright     return flux_right;
184*9f844368SJames Wright   } else {
185*9f844368SJames Wright     return Flux_HLL(left, right, flux_left, flux_right, s_left, s_right);
186*9f844368SJames Wright   }
187*9f844368SJames Wright }
188*9f844368SJames Wright 
189*9f844368SJames Wright // *****************************************************************************
190*9f844368SJames Wright // @brief Forward-mode Derivative of Harten Lax VanLeer (HLL) approximate Riemann solver.
191*9f844368SJames Wright //
192*9f844368SJames Wright // @param gas    NewtonianIdealGasContext for the fluid
193*9f844368SJames Wright // @param left   Fluid state of the domain interior (the current solution)
194*9f844368SJames Wright // @param right  Fluid state of the domain exterior (free stream conditions)
195*9f844368SJames Wright // @param dleft  Derivative of fluid state of the domain interior (the current solution)
196*9f844368SJames Wright // @param dright Derivative of fluid state of the domain exterior (free stream conditions)
197*9f844368SJames Wright // @param normal Normalized, outward facing boundary normal vector
198*9f844368SJames Wright //
199*9f844368SJames Wright // @return StateConservative with derivative of HLL Riemann Flux
200*9f844368SJames Wright // *****************************************************************************
201*9f844368SJames Wright CEED_QFUNCTION_HELPER StateConservative RiemannFlux_HLL_fwd(NewtonianIdealGasContext gas, State left, State dleft, State right, State dright,
202*9f844368SJames Wright                                                             const CeedScalar normal[3]) {
203*9f844368SJames Wright   StateConservative flux_left   = FluxInviscidDotNormal(gas, left, normal);
204*9f844368SJames Wright   StateConservative flux_right  = FluxInviscidDotNormal(gas, right, normal);
205*9f844368SJames Wright   StateConservative dflux_left  = FluxInviscidDotNormal_fwd(gas, left, dleft, normal);
206*9f844368SJames Wright   StateConservative dflux_right = FluxInviscidDotNormal_fwd(gas, right, dright, normal);
207*9f844368SJames Wright 
208*9f844368SJames Wright   CeedScalar u_left   = Dot3(left.Y.velocity, normal);
209*9f844368SJames Wright   CeedScalar u_right  = Dot3(right.Y.velocity, normal);
210*9f844368SJames Wright   CeedScalar du_left  = Dot3(dleft.Y.velocity, normal);
211*9f844368SJames Wright   CeedScalar du_right = Dot3(dright.Y.velocity, normal);
212*9f844368SJames Wright 
213*9f844368SJames Wright   CeedScalar s_left, ds_left, s_right, ds_right;
214*9f844368SJames Wright   ComputeHLLSpeeds_Roe_fwd(gas, left, dleft, u_left, du_left, right, dright, u_right, du_right, &s_left, &ds_left, &s_right, &ds_right);
215*9f844368SJames Wright 
216*9f844368SJames Wright   if (0 <= s_left) {
217*9f844368SJames Wright     return dflux_left;
218*9f844368SJames Wright   } else if (s_right <= 0) {
219*9f844368SJames Wright     return dflux_right;
220*9f844368SJames Wright   } else {
221*9f844368SJames Wright     return Flux_HLL_fwd(left, right, dleft, dright, flux_left, flux_right, dflux_left, dflux_right, s_left, s_right, ds_left, ds_right);
222*9f844368SJames Wright   }
223*9f844368SJames Wright }
224*9f844368SJames Wright 
225*9f844368SJames Wright CEED_QFUNCTION_HELPER StateConservative RiemannFlux_HLLC_Star(NewtonianIdealGasContext gas, State side, StateConservative F_side,
226*9f844368SJames Wright                                                               const CeedScalar normal[3], CeedScalar u_side, CeedScalar s_side, CeedScalar s_star) {
227*9f844368SJames Wright   CeedScalar fact  = side.U.density * (s_side - u_side) / (s_side - s_star);
228*9f844368SJames Wright   CeedScalar denom = side.U.density * (s_side - u_side);
229*9f844368SJames Wright   // U_* = fact * star
230*9f844368SJames Wright   StateConservative star = {
231*9f844368SJames Wright       1.0,
232*9f844368SJames Wright       {
233*9f844368SJames Wright         side.Y.velocity[0] + (s_star - u_side) * normal[0],
234*9f844368SJames Wright         side.Y.velocity[1] + (s_star - u_side) * normal[1],
235*9f844368SJames Wright         side.Y.velocity[2] + (s_star - u_side) * normal[2],
236*9f844368SJames Wright         },
237*9f844368SJames Wright       side.U.E_total / side.U.density  //
238*9f844368SJames Wright           + (s_star - u_side) * (s_star + side.Y.pressure / denom)
239*9f844368SJames Wright   };
240*9f844368SJames Wright   return StateConservativeAXPBYPCZ(1, F_side, s_side * fact, star, -s_side, side.U);
241*9f844368SJames Wright }
242*9f844368SJames Wright 
243*9f844368SJames Wright CEED_QFUNCTION_HELPER StateConservative RiemannFlux_HLLC_Star_fwd(NewtonianIdealGasContext gas, State side, State dside, StateConservative F_side,
244*9f844368SJames Wright                                                                   StateConservative dF_side, const CeedScalar normal[3], CeedScalar u_side,
245*9f844368SJames Wright                                                                   CeedScalar du_side, CeedScalar s_side, CeedScalar ds_side, CeedScalar s_star,
246*9f844368SJames Wright                                                                   CeedScalar ds_star) {
247*9f844368SJames Wright   CeedScalar fact  = side.U.density * (s_side - u_side) / (s_side - s_star);
248*9f844368SJames Wright   CeedScalar dfact = (side.U.density * (ds_side - du_side) + dside.U.density * (s_side - u_side)) / (s_side - s_star)  //
249*9f844368SJames Wright                      - fact / (s_side - s_star) * (ds_side - ds_star);
250*9f844368SJames Wright   CeedScalar denom  = side.U.density * (s_side - u_side);
251*9f844368SJames Wright   CeedScalar ddenom = side.U.density * (ds_side - du_side) + dside.U.density * (s_side - u_side);
252*9f844368SJames Wright 
253*9f844368SJames Wright   StateConservative star = {
254*9f844368SJames Wright       1.0,
255*9f844368SJames Wright       {
256*9f844368SJames Wright         side.Y.velocity[0] + (s_star - u_side) * normal[0],
257*9f844368SJames Wright         side.Y.velocity[1] + (s_star - u_side) * normal[1],
258*9f844368SJames Wright         side.Y.velocity[2] + (s_star - u_side) * normal[2],
259*9f844368SJames Wright         },
260*9f844368SJames Wright       side.U.E_total / side.U.density  //
261*9f844368SJames Wright           + (s_star - u_side) * (s_star + side.Y.pressure / denom)
262*9f844368SJames Wright   };
263*9f844368SJames Wright   StateConservative dstar = {
264*9f844368SJames Wright       0.,
265*9f844368SJames Wright       {
266*9f844368SJames Wright         dside.Y.velocity[0] + (ds_star - du_side) * normal[0],
267*9f844368SJames Wright         dside.Y.velocity[1] + (ds_star - du_side) * normal[1],
268*9f844368SJames Wright         dside.Y.velocity[2] + (ds_star - du_side) * normal[2],
269*9f844368SJames Wright         },
270*9f844368SJames Wright       dside.U.E_total / side.U.density - side.U.E_total / Square(side.U.density) * dside.U.density  //
271*9f844368SJames Wright           + (ds_star - du_side) * (s_star + side.Y.pressure / denom)  //
272*9f844368SJames Wright           + (s_star - u_side) * (ds_star + dside.Y.pressure / denom - side.Y.pressure / Square(denom) * ddenom)  //
273*9f844368SJames Wright   };
274*9f844368SJames Wright 
275*9f844368SJames Wright   const CeedScalar        a[] = {1, ds_side * fact + s_side * dfact, s_side * fact, -ds_side, -s_side};
276*9f844368SJames Wright   const StateConservative U[] = {dF_side, star, dstar, side.U, dside.U};
277*9f844368SJames Wright   return StateConservativeMult(5, a, U);
278*9f844368SJames Wright }
279*9f844368SJames Wright 
280*9f844368SJames Wright // HLLC Riemann solver (from Toro's book)
281*9f844368SJames Wright CEED_QFUNCTION_HELPER StateConservative RiemannFlux_HLLC(NewtonianIdealGasContext gas, State left, State right, const CeedScalar normal[3]) {
282*9f844368SJames Wright   StateConservative flux_left  = FluxInviscidDotNormal(gas, left, normal);
283*9f844368SJames Wright   StateConservative flux_right = FluxInviscidDotNormal(gas, right, normal);
284*9f844368SJames Wright 
285*9f844368SJames Wright   CeedScalar u_left  = Dot3(left.Y.velocity, normal);
286*9f844368SJames Wright   CeedScalar u_right = Dot3(right.Y.velocity, normal);
287*9f844368SJames Wright   CeedScalar s_left, s_right;
288*9f844368SJames Wright   ComputeHLLSpeeds_Roe(gas, left, u_left, right, u_right, &s_left, &s_right);
289*9f844368SJames Wright 
290*9f844368SJames Wright   // Contact wave speed; Toro (10.37)
291*9f844368SJames Wright   CeedScalar rhou_left = left.U.density * u_left, rhou_right = right.U.density * u_right;
292*9f844368SJames Wright   CeedScalar numer  = right.Y.pressure - left.Y.pressure + rhou_left * (s_left - u_left) - rhou_right * (s_right - u_right);
293*9f844368SJames Wright   CeedScalar denom  = left.U.density * (s_left - u_left) - right.U.density * (s_right - u_right);
294*9f844368SJames Wright   CeedScalar s_star = numer / denom;
295*9f844368SJames Wright 
296*9f844368SJames Wright   // Compute HLLC flux
297*9f844368SJames Wright   if (0 <= s_left) {
298*9f844368SJames Wright     return flux_left;
299*9f844368SJames Wright   } else if (0 <= s_star) {
300*9f844368SJames Wright     return RiemannFlux_HLLC_Star(gas, left, flux_left, normal, u_left, s_left, s_star);
301*9f844368SJames Wright   } else if (0 <= s_right) {
302*9f844368SJames Wright     return RiemannFlux_HLLC_Star(gas, right, flux_right, normal, u_right, s_right, s_star);
303*9f844368SJames Wright   } else {
304*9f844368SJames Wright     return flux_right;
305*9f844368SJames Wright   }
306*9f844368SJames Wright }
307*9f844368SJames Wright 
308*9f844368SJames Wright CEED_QFUNCTION_HELPER StateConservative RiemannFlux_HLLC_fwd(NewtonianIdealGasContext gas, State left, State dleft, State right, State dright,
309*9f844368SJames Wright                                                              const CeedScalar normal[3]) {
310*9f844368SJames Wright   StateConservative flux_left   = FluxInviscidDotNormal(gas, left, normal);
311*9f844368SJames Wright   StateConservative flux_right  = FluxInviscidDotNormal(gas, right, normal);
312*9f844368SJames Wright   StateConservative dflux_left  = FluxInviscidDotNormal_fwd(gas, left, dleft, normal);
313*9f844368SJames Wright   StateConservative dflux_right = FluxInviscidDotNormal_fwd(gas, right, dright, normal);
314*9f844368SJames Wright 
315*9f844368SJames Wright   CeedScalar u_left   = Dot3(left.Y.velocity, normal);
316*9f844368SJames Wright   CeedScalar u_right  = Dot3(right.Y.velocity, normal);
317*9f844368SJames Wright   CeedScalar du_left  = Dot3(dleft.Y.velocity, normal);
318*9f844368SJames Wright   CeedScalar du_right = Dot3(dright.Y.velocity, normal);
319*9f844368SJames Wright 
320*9f844368SJames Wright   CeedScalar s_left, ds_left, s_right, ds_right;
321*9f844368SJames Wright   ComputeHLLSpeeds_Roe_fwd(gas, left, dleft, u_left, du_left, right, dright, u_right, du_right, &s_left, &ds_left, &s_right, &ds_right);
322*9f844368SJames Wright 
323*9f844368SJames Wright   // Contact wave speed; Toro (10.37)
324*9f844368SJames Wright   CeedScalar rhou_left = left.U.density * u_left, drhou_left = left.U.density * du_left + dleft.U.density * u_left;
325*9f844368SJames Wright   CeedScalar rhou_right = right.U.density * u_right, drhou_right = right.U.density * du_right + dright.U.density * u_right;
326*9f844368SJames Wright   CeedScalar numer = right.Y.pressure - left.Y.pressure  //
327*9f844368SJames Wright                      + rhou_left * (s_left - u_left)     //
328*9f844368SJames Wright                      - rhou_right * (s_right - u_right);
329*9f844368SJames Wright   CeedScalar dnumer = dright.Y.pressure - dleft.Y.pressure                                //
330*9f844368SJames Wright                       + rhou_left * (ds_left - du_left) + drhou_left * (s_left - u_left)  //
331*9f844368SJames Wright                       - rhou_right * (ds_right - du_right) - drhou_right * (s_right - u_right);
332*9f844368SJames Wright   CeedScalar denom  = left.U.density * (s_left - u_left) - right.U.density * (s_right - u_right);
333*9f844368SJames Wright   CeedScalar ddenom = left.U.density * (ds_left - du_left) + dleft.U.density * (s_left - u_left)  //
334*9f844368SJames Wright                       - right.U.density * (ds_right - du_right) - dright.U.density * (s_right - u_right);
335*9f844368SJames Wright   CeedScalar s_star  = numer / denom;
336*9f844368SJames Wright   CeedScalar ds_star = dnumer / denom - numer / Square(denom) * ddenom;
337*9f844368SJames Wright 
338*9f844368SJames Wright   // Compute HLLC flux
339*9f844368SJames Wright   if (0 <= s_left) {
340*9f844368SJames Wright     return dflux_left;
341*9f844368SJames Wright   } else if (0 <= s_star) {
342*9f844368SJames Wright     return RiemannFlux_HLLC_Star_fwd(gas, left, dleft, flux_left, dflux_left, normal, u_left, du_left, s_left, ds_left, s_star, ds_star);
343*9f844368SJames Wright   } else if (0 <= s_right) {
344*9f844368SJames Wright     return RiemannFlux_HLLC_Star_fwd(gas, right, dright, flux_right, dflux_right, normal, u_right, du_right, s_right, ds_right, s_star, ds_star);
345*9f844368SJames Wright   } else {
346*9f844368SJames Wright     return dflux_right;
347*9f844368SJames Wright   }
348*9f844368SJames Wright }
349*9f844368SJames Wright 
350*9f844368SJames Wright #endif  // riemann_solver_h
351