8#include <compile_time_options.h>
51 template <
int dim,
typename Number>
52 DEAL_II_ALWAYS_INLINE
inline Number
71 const Number first_radicand = (
ScalarNumber(3.) * gamma + Number(11.)) /
74 const Number second_radicand =
75 Number(5. / 6.) + slope * (gamma - Number(3.));
77 Number radicand = std::min(first_radicand, second_radicand);
78 radicand = std::min(Number(1.), radicand);
79 radicand = std::max(Number(1. / 2.), radicand);
81 return std::sqrt(radicand);
85 template <
int dim,
typename Number>
87 const Number &rho,
const Number &gamma,
const Number &a)
const
89 const auto view = hyperbolic_system.view<dim, Number>();
90 const auto interpolation_b = view.eos_interpolation_b();
92 const Number numerator =
93 ScalarNumber(2.) * a * (Number(1.) - interpolation_b * rho);
95 const Number denominator = gamma - Number(1.);
101 template <
int dim,
typename Number>
102 DEAL_II_ALWAYS_INLINE
inline Number
107 const auto view = hyperbolic_system.view<dim, Number>();
108 const auto pinf = view.eos_interpolation_pinfty();
110 const auto &[rho_i, u_i, p_i, gamma_i, a_i] = riemann_data_i;
111 const auto &[rho_j, u_j, p_j, gamma_j, a_j] = riemann_data_j;
112 const auto alpha_i = alpha(rho_i, gamma_i, a_i);
113 const auto alpha_j = alpha(rho_j, gamma_j, a_j);
123 const Number p_min = std::min(p_i, p_j);
124 const Number p_max = std::max(p_i, p_j);
126 const Number gamma_min =
127 dealii::compare_and_apply_mask<dealii::SIMDComparison::less_than>(
128 p_i, p_j, gamma_i, gamma_j);
130 const Number alpha_min =
131 dealii::compare_and_apply_mask<dealii::SIMDComparison::less_than>(
132 p_i, p_j, alpha_i, alpha_j);
134 const Number alpha_hat_min = c(gamma_min) * alpha_min;
136 const Number alpha_max = dealii::compare_and_apply_mask<
137 dealii::SIMDComparison::greater_than_or_equal>(
138 p_i, p_j, alpha_i, alpha_j);
140 const Number gamma_m = std::min(gamma_i, gamma_j);
141 const Number gamma_M = std::max(gamma_i, gamma_j);
143 const Number numerator =
144 dealii::compare_and_apply_mask<dealii::SIMDComparison::equal>(
154 const Number p_ratio =
safe_division(p_min + pinf, p_max + pinf);
162 const Number r_exponent =
163 (gamma_M - gamma_min) / (
ScalarNumber(2.) * gamma_min * gamma_M);
170 const Number first_exponent =
173 const Number first_exponent_inverse =
176 const Number first_denom =
177 alpha_hat_min *
ryujin::pow(p_ratio, r_exponent - first_exponent) +
180 const Number p_1_tilde =
182 first_exponent_inverse) -
185#ifdef DEBUG_RIEMANN_SOLVER
186 std::cout <<
"RS p_1_tilde = " << p_1_tilde <<
"\n";
194 const Number second_exponent =
197 const Number second_exponent_inverse =
200 Number second_denom =
201 alpha_hat_min *
ryujin::pow(p_ratio, -second_exponent) +
204 const Number p_2_tilde =
206 second_exponent_inverse) -
209#ifdef DEBUG_RIEMANN_SOLVER
210 std::cout <<
"RS p_2_tilde = " << p_2_tilde <<
"\n";
213 return std::min(p_1_tilde, p_2_tilde);
217 template <
int dim,
typename Number>
218 DEAL_II_ALWAYS_INLINE
inline Number
223 const auto view = hyperbolic_system.view<dim, Number>();
224 const auto pinf = view.eos_interpolation_pinfty();
226 const auto &[rho_i, u_i, p_i, gamma_i, a_i] = riemann_data_i;
227 const auto &[rho_j, u_j, p_j, gamma_j, a_j] = riemann_data_j;
229 const Number gamma_m = std::min(gamma_i, gamma_j);
231 const Number alpha_hat_i = c(gamma_i) * alpha(rho_i, gamma_i, a_i);
232 const Number alpha_hat_j = c(gamma_j) * alpha(rho_j, gamma_j, a_j);
240 const Number exponent =
242 const Number exponent_inverse = Number(1.) / exponent;
244 const Number numerator =
245 dealii::compare_and_apply_mask<dealii::SIMDComparison::equal>(
251 const Number denominator =
256 const Number p_1_tilde =
261#ifdef DEBUG_RIEMANN_SOLVER
262 std::cout <<
"SS p_1_tilde = " << p_1_tilde <<
"\n";
265 const auto p_2_tilde = p_star_failsafe(riemann_data_i, riemann_data_j);
267 return std::min(p_1_tilde, p_2_tilde);
271 template <
int dim,
typename Number>
272 DEAL_II_ALWAYS_INLINE
inline Number
277 const auto view = hyperbolic_system.view<dim, Number>();
278 const auto interpolation_b = view.eos_interpolation_b();
279 const auto pinf = view.eos_interpolation_pinfty();
281 const auto &[rho_i, u_i, p_i, gamma_i, a_i] = riemann_data_i;
282 const auto &[rho_j, u_j, p_j, gamma_j, a_j] = riemann_data_j;
290 const Number p_max = std::max(p_i, p_j) + pinf;
293 ScalarNumber(2.) * (Number(1.) - interpolation_b * rho_i) * p_max,
294 rho_i * ((gamma_i + Number(1.)) * p_max +
295 (gamma_i - Number(1.)) * (p_i + pinf)));
297 const Number x_i = std::sqrt(radicand_i);
300 ScalarNumber(2.) * (Number(1.) - interpolation_b * rho_j) * p_max,
301 rho_j * ((gamma_j + Number(1.)) * p_max +
302 (gamma_j - Number(1.)) * (p_j + pinf)));
304 const Number x_j = std::sqrt(radicand_j);
306 const Number a = x_i + x_j;
308 dealii::compare_and_apply_mask<dealii::SIMDComparison::equal>(
309 a, Number(0.), Number(0.), u_j - u_i);
311 const Number c = -(p_i + pinf) * x_i - (p_j + pinf) * x_j;
318 const Number p_2_tilde = base * base - pinf;
320#ifdef DEBUG_RIEMANN_SOLVER
321 std::cout <<
"SS p_2_tilde = " << p_2_tilde <<
"\n";
327 template <
int dim,
typename Number>
328 DEAL_II_ALWAYS_INLINE
inline Number
333 const auto view = hyperbolic_system.view<dim, Number>();
334 const auto pinf = view.eos_interpolation_pinfty();
336 const auto &[rho_i, u_i, p_i, gamma_i, a_i] = riemann_data_i;
337 const auto &[rho_j, u_j, p_j, gamma_j, a_j] = riemann_data_j;
338 const auto alpha_i = alpha(rho_i, gamma_i, a_i);
339 const auto alpha_j = alpha(rho_j, gamma_j, a_j);
349 const Number p_min = std::min(p_i, p_j) + pinf;
350 const Number p_max = std::max(p_i, p_j) + pinf;
352 const Number gamma_min =
353 dealii::compare_and_apply_mask<dealii::SIMDComparison::less_than>(
354 p_i, p_j, gamma_i, gamma_j);
356 const Number alpha_min =
357 dealii::compare_and_apply_mask<dealii::SIMDComparison::less_than>(
358 p_i, p_j, alpha_i, alpha_j);
360 const Number alpha_hat_min = c(gamma_min) * alpha_min;
362 const Number gamma_max = dealii::compare_and_apply_mask<
363 dealii::SIMDComparison::greater_than_or_equal>(
364 p_i, p_j, gamma_i, gamma_j);
366 const Number alpha_max = dealii::compare_and_apply_mask<
367 dealii::SIMDComparison::greater_than_or_equal>(
368 p_i, p_j, alpha_i, alpha_j);
370 const Number alpha_hat_max = c(gamma_max) * alpha_max;
372 const Number gamma_m = std::min(gamma_i, gamma_j);
373 const Number gamma_M = std::max(gamma_i, gamma_j);
383 const Number r_exponent =
384 (gamma_M - gamma_min) / (
ScalarNumber(2.) * gamma_min * gamma_M);
393 const Number exponent =
395 const Number exponent_inverse = Number(1.) / exponent;
397 const Number numerator =
400 Number denominator = alpha_hat_min *
ryujin::pow(p_ratio, -exponent) +
405 const Number p_tilde = p_max *
ryujin::pow(temp, exponent_inverse) - pinf;
407#ifdef DEBUG_RIEMANN_SOLVER
408 std::cout <<
"IN p_*_tilde = " << p_tilde <<
"\n";
415 template <
int dim,
typename Number>
416 DEAL_II_ALWAYS_INLINE
inline Number
418 const Number p_star)
const
420 constexpr ScalarNumber
min = std::numeric_limits<ScalarNumber>::min();
422 const auto view = hyperbolic_system.view<dim, Number>();
423 const auto interpolation_b = view.eos_interpolation_b();
424 const auto pinf = view.eos_interpolation_pinfty();
426 const auto &[rho, u, p, gamma, a] = riemann_data;
428 const Number one_minus_b_rho = Number(1.) - interpolation_b * rho;
429 const Number gamma_minus_one = gamma - Number(1.);
432 ScalarNumber(2.) * one_minus_b_rho / (rho * (gamma + Number(1.)));
434 const Number Bz = gamma_minus_one / (gamma + Number(1.)) * (p + pinf);
436 const Number radicand =
safe_division(Az, p_star + pinf + Bz);
439 const Number true_value = (p_star - p) * std::sqrt(radicand);
441 const auto exponent = ScalarNumber(0.5) * gamma_minus_one / gamma;
444 const Number factor =
ryujin::pow(ratio, exponent) - Number(1.);
447 const auto false_value = ScalarNumber(2.) * a * one_minus_b_rho * factor /
448 std::max(gamma_minus_one, Number(min));
450 return dealii::compare_and_apply_mask<
451 dealii::SIMDComparison::greater_than_or_equal>(
452 p_star, p, true_value, false_value);
456 template <
int dim,
typename Number>
457 DEAL_II_ALWAYS_INLINE
inline Number
459 const primitive_type &riemann_data_j,
460 const Number p_in)
const
462 const Number &u_i = riemann_data_i[1];
463 const Number &u_j = riemann_data_j[1];
465 return f(riemann_data_i, p_in) + f(riemann_data_j, p_in) + u_j - u_i;
469 template <
int dim,
typename Number>
470 DEAL_II_ALWAYS_INLINE
inline Number
475 const auto view = hyperbolic_system.view<dim, Number>();
476 const auto interpolation_b = view.eos_interpolation_b();
477 const auto pinf = view.eos_interpolation_pinfty();
479 const auto &[rho_i, u_i, p_i, gamma_i, a_i] = riemann_data_i;
480 const auto &[rho_j, u_j, p_j, gamma_j, a_j] = riemann_data_j;
482 const Number p_max = std::max(p_i, p_j) + pinf;
484 const Number radicand_inverse_i =
486 Number(1.) - interpolation_b * rho_i) *
487 ((gamma_i + Number(1.)) * p_max +
488 (gamma_i - Number(1.)) * (p_i + pinf));
490 const Number value_i =
493 const Number radicand_inverse_j =
495 Number(1.) - interpolation_b * rho_j) *
496 ((gamma_j + Number(1.)) * p_max +
497 (gamma_j - Number(1.)) * (p_j + pinf));
499 const Number value_j =
502 return value_i + value_j + u_j - u_i;
506 template <
int dim,
typename Number>
507 DEAL_II_ALWAYS_INLINE
inline Number
511 const auto view = hyperbolic_system.view<dim, Number>();
512 const auto pinf = view.eos_interpolation_pinfty();
514 const auto &[rho, u, p, gamma, a] = riemann_data;
521 return u - a * std::sqrt(Number(1.) + factor * tmp);
525 template <
int dim,
typename Number>
526 DEAL_II_ALWAYS_INLINE
inline Number
528 const Number p_star)
const
530 const auto view = hyperbolic_system.view<dim, Number>();
531 const auto pinf = view.eos_interpolation_pinfty();
533 const auto &[rho, u, p, gamma, a] = riemann_data;
540 return u + a * std::sqrt(Number(1.) + factor * tmp);
544 template <
int dim,
typename Number>
545 DEAL_II_ALWAYS_INLINE
inline Number
549 const Number p_star)
const
551 const Number nu_11 = lambda1_minus(riemann_data_i, p_star);
552 const Number nu_32 = lambda3_plus(riemann_data_j, p_star);
558 template <
int dim,
typename Number>
559 DEAL_II_ALWAYS_INLINE
inline auto
563 const dealii::Tensor<1, dim, Number> &n_ij)
const ->
primitive_type
565 const auto view = hyperbolic_system.view<dim, Number>();
567 const auto rho = view.density(U);
570 const auto m = view.momentum(U);
571 const auto proj_m = n_ij * m;
573 const auto gamma = view.surrogate_gamma(U, p);
575 const auto interpolation_b = view.eos_interpolation_b();
576 const auto pinf = view.eos_interpolation_pinfty();
577 const auto x = Number(1.) - interpolation_b * rho;
578 const auto a = std::sqrt(gamma * (p + pinf) / (rho * x));
580#ifdef EXPENSIVE_BOUNDS_CHECK
584 dealii::ExcMessage(
"Internal error: p + pinf < 0."));
589 dealii::ExcMessage(
"Internal error: 1. - b * rho <= 0."));
594 dealii::ExcMessage(
"Internal error: gamma < 1."));
597 return {{rho, proj_m * rho_inverse, p, gamma, a}};
601 template <
int dim,
typename Number>
606 const auto view = hyperbolic_system.view<dim, Number>();
607 const auto pinf = view.eos_interpolation_pinfty();
609 const auto &[rho_i, u_i, p_i, gamma_i, a_i] = riemann_data_i;
610 const auto &[rho_j, u_j, p_j, gamma_j, a_j] = riemann_data_j;
612#ifdef DEBUG_RIEMANN_SOLVER
613 std::cout <<
"rho_left: " << rho_i << std::endl;
614 std::cout <<
"u_left: " << u_i << std::endl;
615 std::cout <<
"p_left: " << p_i << std::endl;
616 std::cout <<
"gamma_left: " << gamma_i << std::endl;
617 std::cout <<
"a_left: " << a_i << std::endl;
618 std::cout <<
"rho_right: " << rho_j << std::endl;
619 std::cout <<
"u_right: " << u_j << std::endl;
620 std::cout <<
"p_right: " << p_j << std::endl;
621 std::cout <<
"gamma_right: " << gamma_j << std::endl;
622 std::cout <<
"a_right: " << a_j << std::endl;
625 const Number p_max = std::max(p_i, p_j) + pinf;
626 const Number phi_p_max = phi_of_p_max(riemann_data_i, riemann_data_j);
628 if (!view.compute_strict_bounds()) {
629#ifdef DEBUG_RIEMANN_SOLVER
630 const Number p_star_RS = p_star_RS_full(riemann_data_i, riemann_data_j);
631 const Number p_star_SS = p_star_SS_full(riemann_data_i, riemann_data_j);
632 const Number p_debug =
633 dealii::compare_and_apply_mask<dealii::SIMDComparison::less_than>(
634 phi_p_max, Number(0.), p_star_SS, std::min(p_max, p_star_RS));
635 std::cout <<
" p^*_debug = " << p_debug <<
"\n";
636 std::cout <<
" phi(p_*_d) = "
637 << phi(riemann_data_i, riemann_data_j, p_debug) <<
"\n";
638 std::cout <<
"-> lambda_deb = "
639 << compute_lambda(riemann_data_i, riemann_data_j, p_debug)
643 const Number p_star_tilde =
644 p_star_interpolated(riemann_data_i, riemann_data_j);
645 const Number p_star_backup =
646 p_star_failsafe(riemann_data_i, riemann_data_j);
649 dealii::compare_and_apply_mask<dealii::SIMDComparison::less_than>(
652 std::min(p_star_tilde, p_star_backup),
653 std::min(p_max, p_star_tilde));
655#ifdef DEBUG_RIEMANN_SOLVER
656 std::cout <<
" p^*_tilde = " << p_2 <<
"\n";
657 std::cout <<
" phi(p_*_t) = "
658 << phi(riemann_data_i, riemann_data_j, p_2) <<
"\n";
659 std::cout <<
"-> lambda_max = "
660 << compute_lambda(riemann_data_i, riemann_data_j, p_2) <<
"\n"
664 return compute_lambda(riemann_data_i, riemann_data_j, p_2);
667 const Number p_star_RS = p_star_RS_full(riemann_data_i, riemann_data_j);
668 const Number p_star_SS = p_star_SS_full(riemann_data_i, riemann_data_j);
671 dealii::compare_and_apply_mask<dealii::SIMDComparison::less_than>(
672 phi_p_max, Number(0.), p_star_SS, std::min(p_max, p_star_RS));
674#ifdef DEBUG_RIEMANN_SOLVER
675 std::cout <<
" p^*_tilde = " << p_2 <<
"\n";
676 std::cout <<
" phi(p_*_t) = "
677 << phi(riemann_data_i, riemann_data_j, p_2) <<
"\n";
678 std::cout <<
"-> lambda_max = "
679 << compute_lambda(riemann_data_i, riemann_data_j, p_2)
683 return compute_lambda(riemann_data_i, riemann_data_j, p_2);
687 template <
int dim,
typename Number>
691 const unsigned int i,
692 const unsigned int *js,
693 const dealii::Tensor<1, dim, Number> &n_ij)
const
695 const auto &[p_i, unused_i, s_i, eta_i] =
696 precomputed_values.template get_tensor<Number, precomputed_type>(i);
698 const auto &[p_j, unused_j, s_j, eta_j] =
699 precomputed_values.template get_tensor<Number, precomputed_type>(js);
701 const auto riemann_data_i = riemann_data_from_state(U_i, p_i, n_ij);
702 const auto riemann_data_j = riemann_data_from_state(U_j, p_j, n_ij);
704 return compute(riemann_data_i, riemann_data_j);
Number p_star_RS_full(const primitive_type &riemann_data_i, const primitive_type &riemann_data_j) const
Number lambda1_minus(const primitive_type &riemann_data, const Number p_star) const
Number alpha(const Number &rho, const Number &gamma, const Number &a) const
primitive_type riemann_data_from_state(const state_type &U, const Number &p, const dealii::Tensor< 1, dim, Number > &n_ij) const
Number p_star_failsafe(const primitive_type &riemann_data_i, const primitive_type &riemann_data_j) const
Number p_star_SS_full(const primitive_type &riemann_data_i, const primitive_type &riemann_data_j) const
Number lambda3_plus(const primitive_type &primitive_state, const Number p_star) const
typename View::state_type state_type
typename std::array< Number, riemann_data_size > primitive_type
Number p_star_interpolated(const primitive_type &riemann_data_i, const primitive_type &riemann_data_j) const
Number phi_of_p_max(const primitive_type &riemann_data_i, const primitive_type &riemann_data_j) const
Number compute_lambda(const primitive_type &riemann_data_i, const primitive_type &riemann_data_j, const Number p_star) const
typename View::ScalarNumber ScalarNumber
Number c(const Number &gamma_Z) const
Number compute(const primitive_type &riemann_data_i, const primitive_type &riemann_data_j) const
#define AssertThrowSIMD(variable, condition, exception)
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 Number safe_division(const Number &numerator, const Number &denominator)