21 const Number t_max )
const
26 constexpr ScalarNumber eps = std::numeric_limits<ScalarNumber>::epsilon();
27 const auto small = view_.vacuum_state_relaxation_small();
28 const auto large = view_.vacuum_state_relaxation_large();
39 const auto &rho_U = view_.density(U);
40 const auto &rho_P = view_.density(P);
42 const auto &rho_min = std::get<0>(bounds);
43 const auto &rho_max = std::get<1>(bounds);
49 const auto test_min = view_.filter_vacuum_density(
50 std::max(Number(0.), rho_U - relax * rho_max));
51 const auto test_max = view_.filter_vacuum_density(
52 std::max(Number(0.), rho_min - relax * rho_U));
53 if (!(test_min == Number(0.) && test_max == Number(0.))) {
55 std::cout << std::fixed << std::setprecision(16);
56 std::cout <<
"Bounds violation: low-order density (critical)!"
57 <<
"\n\t\trho min: " << rho_min
58 <<
"\n\t\trho min (delta): "
60 <<
"\n\t\trho: " << rho_U
61 <<
"\n\t\trho max (delta): "
63 <<
"\n\t\trho max: " << rho_max <<
"\n"
69 const Number denominator =
72 t_r = dealii::compare_and_apply_mask<dealii::SIMDComparison::less_than>(
81 (rho_max - rho_U) * denominator,
84 t_r = dealii::compare_and_apply_mask<dealii::SIMDComparison::less_than>(
93 (rho_U - rho_min) * denominator,
103 t_r = std::min(t_r, t_max);
104 t_r = std::max(t_r, t_min);
106#ifdef DEBUG_EXPENSIVE_BOUNDS_CHECK
110 const auto rho_new = view_.density(U + t_r * P);
111 const auto test_new_min = view_.filter_vacuum_density(
112 std::max(Number(0.), rho_new - relax * rho_max));
113 const auto test_new_max = view_.filter_vacuum_density(
114 std::max(Number(0.), rho_min - relax * rho_new));
115 if (!(test_new_min == Number(0.) && test_new_max == Number(0.))) {
117 std::cout << std::fixed << std::setprecision(16);
118 std::cout <<
"Bounds violation: high-order density!"
119 <<
"\n\t\trho min: " << rho_min
120 <<
"\n\t\trho min (delta): "
122 <<
"\n\t\trho: " << rho_new
123 <<
"\n\t\trho max (delta): "
125 <<
"\n\t\trho max: " << rho_max <<
"\n"
143 const auto &gamma = std::get<3>(bounds) ;
144 const Number gm1 = gamma - Number(1.);
146 const auto b = Number(view_.eos_covolume_constant());
147 const auto pinf = Number(view_.eos_interpolation_pinfty());
148 const auto q = Number(view_.eos_interpolation_q());
167 const auto &s_min = std::get<2>(bounds);
169#ifdef DEBUG_OUTPUT_LIMITER
170 std::cout << std::endl;
171 std::cout << std::fixed << std::setprecision(16);
172 std::cout <<
"t_l: (start) " << t_l << std::endl;
173 std::cout <<
"t_r: (start) " << t_r << std::endl;
176 for (
unsigned int n = 0; n < newton_max_iterations(); ++n) {
178 const auto U_r = U + t_r * P;
179 const auto rho_r = view_.density(U_r);
180 const auto rho_r_gamma =
ryujin::pow(rho_r, gamma);
181 const auto covolume_r = Number(1.) - b * rho_r;
183 const auto rho_e_r = view_.internal_energy(U_r);
184 const auto shift_r = rho_e_r - rho_r * q - pinf * covolume_r;
187 relax_small * rho_r * shift_r -
188 s_min * rho_r * rho_r_gamma *
ryujin::pow(covolume_r, -gm1);
190#ifndef DEBUG_EXPENSIVE_BOUNDS_CHECK
195 t_l = dealii::compare_and_apply_mask<
196 dealii::SIMDComparison::greater_than>(
197 psi_r, Number(0.), t_r, t_l);
215#ifdef DEBUG_OUTPUT_LIMITER
216 std::cout <<
"shortcut: t_l == t_r" << std::endl;
217 std::cout <<
"psi_l: " << psi_l << std::endl;
218 std::cout <<
"psi_r: " << psi_r << std::endl;
219 std::cout <<
"t_l: ( " << n <<
" ) " << t_l << std::endl;
220 std::cout <<
"t_r: ( " << n <<
" ) " << t_r << std::endl;
226 const auto U_l = U + t_l * P;
227 const auto rho_l = view_.density(U_l);
228 const auto rho_l_gamma =
ryujin::pow(rho_l, gamma);
229 const auto covolume_l = Number(1.) - b * rho_l;
230 const auto rho_e_l = view_.internal_energy(U_l);
231 const auto shift_l = rho_e_l - rho_l * q - pinf * covolume_l;
234 relax_small * rho_l * shift_l -
235 s_min * rho_l * rho_l_gamma *
ryujin::pow(covolume_l, -gm1);
241 const auto lower_bound = (
ScalarNumber(1.) - relax) * s_min * rho_l *
244 !(std::min(Number(0.), psi_l - lower_bound) == Number(0.))) {
246 std::cout << std::fixed << std::setprecision(16);
248 <<
"Bounds violation: low-order specific entropy (critical)!\n";
249 std::cout <<
"\t\tPsi left: 0 <= " << psi_l <<
"\n" << std::endl;
254#ifdef DEBUG_EXPENSIVE_BOUNDS_CHECK
259 t_l = dealii::compare_and_apply_mask<
260 dealii::SIMDComparison::greater_than>(
261 psi_r, Number(0.), t_r, t_l);
268 const Number tolerance(newton_tolerance());
269 if (std::max(Number(0.), t_r - t_l - tolerance) == Number(0.)) {
270#ifdef DEBUG_OUTPUT_LIMITER
271 std::cout <<
"break: t_l and t_r within tolerance" << std::endl;
272 std::cout <<
"psi_l: " << psi_l << std::endl;
273 std::cout <<
"psi_r: " << psi_r << std::endl;
274 std::cout <<
"t_l: ( " << n <<
" ) " << t_l << std::endl;
275 std::cout <<
"t_r: ( " << n <<
" ) " << t_r << std::endl;
282 const auto drho = view_.density(P);
283 const auto drho_e_l = view_.internal_energy_derivative(U_l) * P;
284 const auto drho_e_r = view_.internal_energy_derivative(U_r) * P;
286 const auto q_pinf_term_l =
289 const auto q_pinf_term_r =
293 const auto extra_term_l = s_min *
295 (covolume_l + gamma - b * rho_l);
296 const auto extra_term_r = s_min *
298 (covolume_r + gamma - b * rho_r);
300 const auto dpsi_l = rho_l * drho_e_l +
301 (rho_e_l - q_pinf_term_l - extra_term_l) * drho;
302 const auto dpsi_r = rho_r * drho_e_r +
303 (rho_e_r - q_pinf_term_r - extra_term_r) * drho;
306 t_l, t_r, psi_l, psi_r, dpsi_l, dpsi_r, Number(-1.));
308#ifdef DEBUG_OUTPUT_LIMITER
309 std::cout <<
"psi_l: " << psi_l << std::endl;
310 std::cout <<
"psi_r: " << psi_r << std::endl;
311 std::cout <<
"dpsi_l: " << dpsi_l << std::endl;
312 std::cout <<
"dpsi_r: " << dpsi_r << std::endl;
313 std::cout <<
"t_l: ( " << n <<
" ) " << t_l << std::endl;
314 std::cout <<
"t_r: ( " << n <<
" ) " << t_r << std::endl;
318#ifdef DEBUG_EXPENSIVE_BOUNDS_CHECK
323 const auto U_new = U + t_l * P;
325 const auto rho_new = view_.density(U_new);
326 const auto covolume_new = Number(1.) - b * rho_new;
328 const auto rho_new_gamma =
ryujin::pow(rho_new, gamma);
329 const auto rho_e_new = view_.internal_energy(U_new);
331 const auto shift_new = rho_e_new - rho_new * q - pinf * covolume_new;
334 relax_small * rho_new * shift_new -
335 s_min * rho_new * rho_new_gamma *
ryujin::pow(covolume_new, -gm1);
337 const auto lower_bound = (
ScalarNumber(1.) - relax) * s_min *
338 rho_new * rho_new_gamma *
341 const bool e_valid = std::min(Number(0.), shift_new) == Number(0.);
342 const bool psi_valid =
343 std::min(Number(0.), psi_new - lower_bound) == Number(0.);
345 if (!e_valid || !psi_valid) {
347 std::cout << std::fixed << std::setprecision(16);
348 std::cout <<
"Bounds violation: high-order specific entropy!\n";
349 std::cout <<
"\t\trho e: 0 <= " << rho_e_new <<
"\n";
350 std::cout <<
"\t\tPsi: 0 <= " << psi_new <<
"\n" << std::endl;
358 return {t_l, success};