Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
riemann_hllc.hpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
10#pragma once
11
20
22
23namespace shammath {
24
37 template<FluidStateAdiabaticSpec FSpec>
38 inline constexpr typename FSpec::Tcons hllc_adiab_toro_flux(
39 const FSpec &fspec,
40 const typename FSpec::Tprim &prim_l,
41 const typename FSpec::Tprim &prim_r,
42 const typename FSpec::Tvec &n) {
43 using Tscal = typename FSpec::Tscal;
44 using Tvec = typename FSpec::Tvec;
45 using Tcons = typename FSpec::Tcons;
46
47 // fspec.gamma() directly if defined, else gamma_l/gamma_r each from fspec.gamma(prim)
48 const auto [gamma_l, gamma_r] = get_adiabatic_index_lr(fspec, prim_l, prim_r);
49
50 // Conservative form is only needed for the star-state algebra below.
51 const Tcons c_l = fspec.prim_to_cons(prim_l);
52 const Tcons c_r = fspec.prim_to_cons(prim_r);
53
54 // sound speeds
55 const auto cs_l = fspec.sound_speed(prim_l);
56 const auto cs_r = fspec.sound_speed(prim_r);
57
58 // Left variables
59 const auto rho_l = prim_l.rho;
60 const auto press_l = prim_l.press;
61 const auto velx_l = fspec.vn(prim_l, n);
62
63 // Right variables
64 const auto rho_r = prim_r.rho;
65 const auto press_r = prim_r.press;
66 const auto velx_r = fspec.vn(prim_r, n);
67
68 // Left and right state fluxes
69 const auto f_l = fspec.flux(prim_l, n, velx_l);
70 const auto f_r = fspec.flux(prim_r, n, velx_r);
71
73 // First compute the pressure estimation in the star region using the primitive variable
74 // solver
75 //
76 // Toro from section 9.3 or Equation (10.67).
77 //
78 // TODO: It will be interresting to implement and test various pressure estimate algorithms
79 // such as : / Two-Rarefaction Riemann Solver (TRRS), Two-Shock Riemann Solver (TSRS) and
80 // Adaptive / Riemann Solvers(AIRS or ANRS)
82 Tscal rho_bar = 0.5 * (rho_l + rho_r);
83 Tscal cs_bar = 0.5 * (cs_l + cs_r);
84 Tscal p_pvrs = 0.5 * (press_l + press_r) - 0.5 * (velx_r - velx_l) * rho_bar * cs_bar;
85 // Pressure in the star region estimate
86 Tscal press_star = sham::max(0., p_pvrs);
87
88 // Once the pressure in the star region is known, we then estimates the wave speeds
89 // following https://ui.adsabs.harvard.edu/abs/1994ShWav...4...25T/abstract or Equations
90 // (10.59 - 10.60) from Toro
91 Tscal q_l = 0, q_r = 0;
92 if (press_star <= press_l) {
93 q_l = 1.;
94 } else {
95 q_l = sycl::sqrt(
96 1.
97 + (0.5 * (1. + gamma_l) / (Tscal) gamma_l) * (press_star / (Tscal) press_l - 1.));
98 }
99
100 if (press_star <= press_r) {
101 q_r = 1.;
102 } else {
103 q_r = sycl::sqrt(
104 1.
105 + (0.5 * (1. + gamma_r) / (Tscal) gamma_r) * (press_star / (Tscal) press_r - 1.));
106 }
107
108 // wave speed Toro from Equation (10.59)
109 Tscal s_l = velx_l - cs_l * q_l;
110 Tscal s_r = velx_r + cs_r * q_r;
111
112 // lagrangian sound speed
113 const Tscal var_l = rho_l * (s_l - velx_l);
114 const Tscal var_r = rho_r * (s_r - velx_r);
115
116 // NOLINTBEGIN(readability-identifier-naming)
117
118 // S* speed estimate
119 // Equation (10.37) from Toro 3rd Edition , Springer 2009
120 const Tscal S_star
121 = (prim_r.press - prim_l.press + velx_l * var_l - velx_r * var_r) / (var_l - var_r);
122
123 // New pressure estimate in the star region as average the pressure estimate at right
124 // and left of S_star in the star region
125 // Equation (10.42) from Toro 3rd Edition , Springer 2009
126 const Tscal press_lr
127 = 0.5 * (press_l + press_r + var_l * (S_star - velx_l) + var_r * (S_star - velx_r));
128 Tcons D_star{0, S_star, n};
129
130 // NOLINTEND(readability-identifier-naming)
131
132 // Equation (10.40) from Toro 3rd Edition , Springer 2009
133 // Left intermediate conservative state in the star region
134 // Tcons c_l_star = (s_l * c_l - f_l + press_star * D_star) * (1.0 / (s_l - S_star));
135 Tcons c_l_star = (s_l * c_l - f_l + press_lr * D_star) * (1.0 / (s_l - S_star));
136
137 // Equation (10.40) from Toro 3rd Edition , Springer 2009
138 // Right intermediate conservative state in the star region
139 // Tcons c_r_star = (s_r * c_r - f_r + press_star * D_star) * (1.0 / (s_r - S_star));
140 Tcons c_r_star = (s_r * c_r - f_r + press_lr * D_star) * (1.0 / (s_r - S_star));
141
142 // intemediate Flux in the star region
143 // Equation (10.38) from Toro 3rd Edition , Springer 2009
144 Tcons f_l_star = f_l + s_l * (c_l_star - c_l);
145 Tcons f_r_star = f_r + s_r * (c_r_star - c_r);
146
147 // HLLC flux
148 if (s_l >= 0) {
149 return f_l;
150 } else if (S_star >= 0) {
151 return f_l_star;
152 } else if (s_r >= 0) {
153 return f_r_star;
154 } else
155 return f_r;
156 }
157
172 template<FluidStateSpec FSpec>
173 inline constexpr typename FSpec::Tcons hllc_davis_flux(
174 const FSpec &fspec,
175 const typename FSpec::Tprim &prim_l,
176 const typename FSpec::Tprim &prim_r,
177 const typename FSpec::Tvec &n) {
178 using Tscal = typename FSpec::Tscal;
179 using Tvec = typename FSpec::Tvec;
180 using Tcons = typename FSpec::Tcons;
181
182 // Conservative form is only needed for the star-state algebra below.
183 const Tcons c_l = fspec.prim_to_cons(prim_l);
184 const Tcons c_r = fspec.prim_to_cons(prim_r);
185
186 // sound speeds
187 const auto cs_l = fspec.sound_speed(prim_l);
188 const auto cs_r = fspec.sound_speed(prim_r);
189
190 // Left variables
191 const auto rho_l = prim_l.rho;
192 const auto press_l = prim_l.press;
193 const auto velx_l = fspec.vn(prim_l, n);
194
195 // Right variables
196 const auto rho_r = prim_r.rho;
197 const auto press_r = prim_r.press;
198 const auto velx_r = fspec.vn(prim_r, n);
199
200 // Left and right state fluxes
201 const auto f_l = fspec.flux(prim_l, n, velx_l);
202 const auto f_r = fspec.flux(prim_r, n, velx_r);
203
204 // Davis estimate, but we'll see later
205 Tscal s_l = sham::min(velx_l - cs_l, velx_r - cs_r);
206 Tscal s_r = sham::max(velx_l + cs_l, velx_r + cs_r);
207
208 // lagrangian sound speed
209 const Tscal var_l = rho_l * (s_l - velx_l);
210 const Tscal var_r = rho_r * (s_r - velx_r);
211
212 // NOLINTBEGIN(readability-identifier-naming)
213
214 // S* speed estimate
215 // Equation (10.37) from Toro 3rd Edition , Springer 2009
216 const Tscal S_star
217 = (prim_r.press - prim_l.press + velx_l * var_l - velx_r * var_r) / (var_l - var_r);
218
219 // New pressure estimate in the star region as average the pressure estimate at right
220 // and left of S_star in the star region
221 // Equation (10.42) from Toro 3rd Edition , Springer 2009
222 const Tscal press_lr
223 = 0.5 * (press_l + press_r + var_l * (S_star - velx_l) + var_r * (S_star - velx_r));
224 Tcons D_star{0, S_star, n};
225
226 // NOLINTEND(readability-identifier-naming)
227
228 // Equation (10.40) from Toro 3rd Edition , Springer 2009
229 // Left intermediate conservative state in the star region
230 Tcons c_l_star = (s_l * c_l - f_l + press_lr * D_star) * (1.0 / (s_l - S_star));
231
232 // Equation (10.40) from Toro 3rd Edition , Springer 2009
233 // Right intermediate conservative state in the star region
234 Tcons c_r_star = (s_r * c_r - f_r + press_lr * D_star) * (1.0 / (s_r - S_star));
235
236 // intemediate Flux in the star region
237 // Equation (10.38) from Toro 3rd Edition , Springer 2009
238 Tcons f_l_star = f_l + s_l * (c_l_star - c_l);
239 Tcons f_r_star = f_r + s_r * (c_r_star - c_r);
240
241 // HLLC flux
242 if (s_l >= 0) {
243 return f_l;
244 } else if (S_star >= 0) {
245 return f_l_star;
246 } else if (s_r >= 0) {
247 return f_r_star;
248 } else
249 return f_r;
250 }
251
252} // namespace shammath
namespace for math utility
Definition AABB.hpp:26
constexpr std::pair< typename FSpec::Tscal, typename FSpec::Tscal > get_adiabatic_index_lr(const FSpec &fspec, const typename FSpec::Tprim &prim_l, const typename FSpec::Tprim &prim_r)
Read the left/right adiabatic indices a HLLC-style solver should use for a given L/R pair.
constexpr FSpec::Tcons hllc_davis_flux(const FSpec &fspec, const typename FSpec::Tprim &prim_l, const typename FSpec::Tprim &prim_r, const typename FSpec::Tvec &n)
HLLC solver based on section 10.4 from Toro 3rd Edition , Springer 2009, using the Davis (1988) wave ...
constexpr FSpec::Tcons hllc_adiab_toro_flux(const FSpec &fspec, const typename FSpec::Tprim &prim_l, const typename FSpec::Tprim &prim_r, const typename FSpec::Tvec &n)
HLLC solver based on section 10.4 from Toro 3rd Edition , Springer 2009. The wave speeds estimates ar...
Gas and dust conservative/primitive states and axis-transform helpers shared by every gas and dust Ri...