15 template <
int dim,
typename Number>
16 std::tuple<Number, bool>
23 const auto view = hyperbolic_system.view<dim, Number>();
28 constexpr ScalarNumber eps = std::numeric_limits<ScalarNumber>::epsilon();
29 const auto small = view.vacuum_state_relaxation_small();
30 const auto large = view.vacuum_state_relaxation_large();
41 const auto &rho_U = view.density(U);
42 const auto &rho_P = view.density(P);
44 const auto &rho_min = std::get<0>(bounds);
45 const auto &rho_max = std::get<1>(bounds);
51 const auto test_min = view.filter_vacuum_density(
52 std::max(Number(0.), rho_U - relax * rho_max));
53 const auto test_max = view.filter_vacuum_density(
54 std::max(Number(0.), rho_min - relax * rho_U));
55 if (!(test_min == Number(0.) && test_max == Number(0.))) {
57 std::cout << std::fixed << std::setprecision(16);
58 std::cout <<
"Bounds violation: low-order density (critical)!"
59 <<
"\n\t\trho min: " << rho_min
60 <<
"\n\t\trho min (delta): "
62 <<
"\n\t\trho: " << rho_U
63 <<
"\n\t\trho max (delta): "
65 <<
"\n\t\trho max: " << rho_max <<
"\n"
71 const Number denominator =
74 t_r = dealii::compare_and_apply_mask<dealii::SIMDComparison::less_than>(
83 (rho_max - rho_U) * denominator,
86 t_r = dealii::compare_and_apply_mask<dealii::SIMDComparison::less_than>(
95 (rho_U - rho_min) * denominator,
105 t_r = std::min(t_r, t_max);
106 t_r = std::max(t_r, t_min);
108#ifdef EXPENSIVE_BOUNDS_CHECK
112 const auto rho_new = view.density(U + t_r * P);
113 const auto test_new_min = view.filter_vacuum_density(
114 std::max(Number(0.), rho_new - relax * rho_max));
115 const auto test_new_max = view.filter_vacuum_density(
116 std::max(Number(0.), rho_min - relax * rho_new));
117 if (!(test_new_min == Number(0.) && test_new_max == Number(0.))) {
119 std::cout << std::fixed << std::setprecision(16);
120 std::cout <<
"Bounds violation: high-order density!"
121 <<
"\n\t\trho min: " << rho_min
122 <<
"\n\t\trho min (delta): "
124 <<
"\n\t\trho: " << rho_new
125 <<
"\n\t\trho max (delta): "
127 <<
"\n\t\trho max: " << rho_max <<
"\n"
145 const auto &gamma = std::get<3>(bounds) ;
146 const Number gm1 = gamma - Number(1.);
148 const auto b = Number(view.eos_interpolation_b());
149 const auto pinf = Number(view.eos_interpolation_pinfty());
150 const auto q = Number(view.eos_interpolation_q());
169 const auto &s_min = std::get<2>(bounds);
171#ifdef DEBUG_OUTPUT_LIMITER
172 std::cout << std::endl;
173 std::cout << std::fixed << std::setprecision(16);
174 std::cout <<
"t_l: (start) " << t_l << std::endl;
175 std::cout <<
"t_r: (start) " << t_r << std::endl;
178 for (
unsigned int n = 0; n < parameters.newton_max_iterations(); ++n) {
180 const auto U_r = U + t_r * P;
181 const auto rho_r = view.density(U_r);
182 const auto rho_r_gamma =
ryujin::pow(rho_r, gamma);
183 const auto covolume_r = Number(1.) - b * rho_r;
185 const auto rho_e_r = view.internal_energy(U_r);
186 const auto shift_r = rho_e_r - rho_r * q - pinf * covolume_r;
189 relax_small * rho_r * shift_r -
190 s_min * rho_r * rho_r_gamma *
ryujin::pow(covolume_r, -gm1);
192#ifndef EXPENSIVE_BOUNDS_CHECK
197 t_l = dealii::compare_and_apply_mask<
198 dealii::SIMDComparison::greater_than>(
199 psi_r, Number(0.), t_r, t_l);
217#ifdef DEBUG_OUTPUT_LIMITER
218 std::cout <<
"shortcut: t_l == t_r" << std::endl;
219 std::cout <<
"psi_l: " << psi_l << std::endl;
220 std::cout <<
"psi_r: " << psi_r << std::endl;
221 std::cout <<
"t_l: ( " << n <<
" ) " << t_l << std::endl;
222 std::cout <<
"t_r: ( " << n <<
" ) " << t_r << std::endl;
228 const auto U_l = U + t_l * P;
229 const auto rho_l = view.density(U_l);
230 const auto rho_l_gamma =
ryujin::pow(rho_l, gamma);
231 const auto covolume_l = Number(1.) - b * rho_l;
232 const auto rho_e_l = view.internal_energy(U_l);
233 const auto shift_l = rho_e_l - rho_l * q - pinf * covolume_l;
236 relax_small * rho_l * shift_l -
237 s_min * rho_l * rho_l_gamma *
ryujin::pow(covolume_l, -gm1);
243 const auto lower_bound = (
ScalarNumber(1.) - relax) * s_min * rho_l *
246 !(std::min(Number(0.), psi_l - lower_bound) == Number(0.))) {
248 std::cout << std::fixed << std::setprecision(16);
250 <<
"Bounds violation: low-order specific entropy (critical)!\n";
251 std::cout <<
"\t\tPsi left: 0 <= " << psi_l <<
"\n" << std::endl;
256#ifdef EXPENSIVE_BOUNDS_CHECK
261 t_l = dealii::compare_and_apply_mask<
262 dealii::SIMDComparison::greater_than>(
263 psi_r, Number(0.), t_r, t_l);
270 const Number tolerance(parameters.newton_tolerance());
271 if (std::max(Number(0.), t_r - t_l - tolerance) == Number(0.)) {
272#ifdef DEBUG_OUTPUT_LIMITER
273 std::cout <<
"break: t_l and t_r within tolerance" << std::endl;
274 std::cout <<
"psi_l: " << psi_l << std::endl;
275 std::cout <<
"psi_r: " << psi_r << std::endl;
276 std::cout <<
"t_l: ( " << n <<
" ) " << t_l << std::endl;
277 std::cout <<
"t_r: ( " << n <<
" ) " << t_r << std::endl;
284 const auto drho = view.density(P);
285 const auto drho_e_l = view.internal_energy_derivative(U_l) * P;
286 const auto drho_e_r = view.internal_energy_derivative(U_r) * P;
288 const auto q_pinf_term_l =
291 const auto q_pinf_term_r =
295 const auto extra_term_l = s_min *
297 (covolume_l + gamma - b * rho_l);
298 const auto extra_term_r = s_min *
300 (covolume_r + gamma - b * rho_r);
302 const auto dpsi_l = rho_l * drho_e_l +
303 (rho_e_l - q_pinf_term_l - extra_term_l) * drho;
304 const auto dpsi_r = rho_r * drho_e_r +
305 (rho_e_r - q_pinf_term_r - extra_term_r) * drho;
308 t_l, t_r, psi_l, psi_r, dpsi_l, dpsi_r, Number(-1.));
310#ifdef DEBUG_OUTPUT_LIMITER
311 std::cout <<
"psi_l: " << psi_l << std::endl;
312 std::cout <<
"psi_r: " << psi_r << std::endl;
313 std::cout <<
"dpsi_l: " << dpsi_l << std::endl;
314 std::cout <<
"dpsi_r: " << dpsi_r << std::endl;
315 std::cout <<
"t_l: ( " << n <<
" ) " << t_l << std::endl;
316 std::cout <<
"t_r: ( " << n <<
" ) " << t_r << std::endl;
320#ifdef EXPENSIVE_BOUNDS_CHECK
325 const auto U_new = U + t_l * P;
327 const auto rho_new = view.density(U_new);
328 const auto covolume_new = Number(1.) - b * rho_new;
330 const auto rho_new_gamma =
ryujin::pow(rho_new, gamma);
331 const auto rho_e_new = view.internal_energy(U_new);
333 const auto shift_new = rho_e_new - rho_new * q - pinf * covolume_new;
336 relax_small * rho_new * shift_new -
337 s_min * rho_new * rho_new_gamma *
ryujin::pow(covolume_new, -gm1);
339 const auto lower_bound = (
ScalarNumber(1.) - relax) * s_min *
340 rho_new * rho_new_gamma *
343 const bool e_valid = std::min(Number(0.), shift_new) == Number(0.);
344 const bool psi_valid =
345 std::min(Number(0.), psi_new - lower_bound) == Number(0.);
347 if (!e_valid || !psi_valid) {
349 std::cout << std::fixed << std::setprecision(16);
350 std::cout <<
"Bounds violation: high-order specific entropy!\n";
351 std::cout <<
"\t\trho e: 0 <= " << rho_e_new <<
"\n";
352 std::cout <<
"\t\tPsi: 0 <= " << psi_new <<
"\n" << std::endl;
360 return {t_l, success};
typename View::state_type state_type
typename View::ScalarNumber ScalarNumber
std::tuple< Number, bool > limit(const Bounds &bounds, const state_type &U, const state_type &P, const Number t_min=Number(0.), const Number t_max=Number(1.))
std::array< Number, n_bounds > Bounds
T pow(const T x, const T b)
DEAL_II_ALWAYS_INLINE Number negative_part(const Number number)
DEAL_II_ALWAYS_INLINE Number positive_part(const Number number)
DEAL_II_ALWAYS_INLINE void quadratic_newton_step(Number &p_1, Number &p_2, const Number phi_p_1, const Number phi_p_2, const Number dphi_p_1, const Number dphi_p_2, const Number sign=Number(1.0))