443 const dealii::Tensor<1, dim, Number> &scaled_c_ij,
448 const auto f_star_ij = view_.f(U_star_ij);
449 const auto f_star_ji = view_.f(U_star_ji);
452 const auto U_ij_bar =
454 (U_star_ij + U_star_ji +
455 contract(
add(f_star_ij, -f_star_ji), scaled_c_ij)) +
460 auto &[h_min, h_max, v2_max] = bounds_;
462 const auto h_bar_ij = view_.water_depth(U_ij_bar);
463 h_min = std::min(h_min, h_bar_ij);
464 h_max = std::max(h_max, h_bar_ij);
466 const auto v_bar_ij = view_.momentum(U_ij_bar) *
467 view_.inverse_water_depth_mollified(U_ij_bar);
468 const auto v2_bar_ij = v_bar_ij.norm_square();
469 v2_max = std::max(v2_max, v2_bar_ij);
474 const auto beta_ij = Number(1.);
476 relaxation_denominator_ += std::abs(beta_ij);
478 const auto h_i = view_.water_depth(U_i_);
479 const auto h_j = view_.water_depth(U_j);
480 h_relaxation_numerator_ += beta_ij * (h_i + h_j);
483 view_.momentum(U_i_) * view_.inverse_water_depth_mollified(U_i_);
485 view_.momentum(U_j) * view_.inverse_water_depth_mollified(U_j);
486 v2_relaxation_numerator_ +=
487 beta_ij * (-vel_i.norm_square() + vel_j.norm_square());
496 const auto &[h_min, h_max, v2_max] = bounds_;
498 auto relaxed_bounds = fully_relax_bounds(bounds_, hd_i);
499 auto &[h_min_relaxed, h_max_relaxed, v2_max_relaxed] = relaxed_bounds;
503 constexpr ScalarNumber eps = std::numeric_limits<ScalarNumber>::epsilon();
505 const Number h_relaxed =
ScalarNumber(2. * relaxation_factor()) *
506 std::abs(h_relaxation_numerator_) /
507 (relaxation_denominator_ + Number(eps));
509 const Number v2_relaxed =
ScalarNumber(2. * relaxation_factor()) *
510 std::abs(v2_relaxation_numerator_) /
511 (relaxation_denominator_ + Number(eps));
513 h_min_relaxed = std::max(h_min_relaxed, h_min - h_relaxed);
514 h_max_relaxed = std::min(h_max_relaxed, h_max + h_relaxed);
515 v2_max_relaxed = std::min(v2_max_relaxed, v2_max + v2_relaxed);
517 return relaxed_bounds;
528 const Number t_max )
const
534 const auto &[h_min, h_max, v2_max] = bounds;
537 constexpr ScalarNumber eps = std::numeric_limits<ScalarNumber>::epsilon();
538 const auto small = view_.dry_state_relaxation_small();
539 const auto large = view_.dry_state_relaxation_large();
540 const auto relax_small =
ScalarNumber(1. + small * eps);
550 auto h_U = view_.water_depth(U);
551 const auto &h_P = view_.water_depth(P);
553 const auto test_min = view_.filter_dry_water_depth(
554 std::max(Number(0.), h_U - relax * h_max));
555 const auto test_max = view_.filter_dry_water_depth(
556 std::max(Number(0.), h_min - relax * h_U));
558 if (!(test_min == Number(0.) && test_max == Number(0.))) {
560 std::cout << std::fixed << std::setprecision(16);
561 std::cout <<
"Bounds violation: low-order water depth (critical)!\n"
562 <<
"\n\t\th min: " << h_min
564 <<
"\n\t\th: " << h_U
566 <<
"\n\t\th max: " << h_max <<
"\n"
572 const Number denominator =
575 constexpr auto lt = dealii::SIMDComparison::less_than;
577 t_r = ryujin::compare_and_apply_mask<lt>(
586 (h_max - h_U) * denominator,
589 t_r = ryujin::compare_and_apply_mask<lt>(
598 (h_U - h_min) * denominator,
608 t_r = std::min(t_r, t_max);
609 t_r = std::max(t_r, t_min);
612#ifdef DEBUG_EXPENSIVE_BOUNDS_CHECK
616 const auto h_new = view_.water_depth(U + t_r * P);
617 const auto test_new_min = view_.filter_dry_water_depth(
618 std::max(Number(0.), h_new - relax * h_max));
619 const auto test_new_max = view_.filter_dry_water_depth(
620 std::max(Number(0.), h_min - relax * h_new));
622 if (!(test_new_min == Number(0.) && test_new_max == Number(0.))) {
624 std::cout << std::fixed << std::setprecision(30);
625 std::cout <<
"Bounds violation: high-order water depth!\n"
626 <<
"\n\t\th min: " << h_min
628 <<
"\n\t\th: " << h_new
630 <<
"\n\t\th max: " << h_max <<
"\n"
652 const auto U_r = U + t_r * P;
653 const auto h_r = view_.water_depth(U_r);
654 const auto q_r = view_.momentum(U_r);
656 const auto psi_r = relax_small * h_r * h_r * v2_max - q_r.norm_square();
663 dealii::SIMDComparison::greater_than>(psi_r, Number(0.), t_r, t_l);
667 return {t_l, success};
669#ifdef DEBUG_OUTPUT_LIMITER
671 std::cout << std::endl;
672 std::cout << std::fixed << std::setprecision(16);
673 std::cout <<
"t_l: (start) " << t_l << std::endl;
674 std::cout <<
"t_r: (start) " << t_r << std::endl;
678 const auto U_l = U + t_l * P;
679 const auto h_l = view_.water_depth(U_l);
680 const auto q_l = view_.momentum(U_l);
682 const auto psi_l = relax_small * h_l * h_l * v2_max - q_l.norm_square();
692 const auto filtered_h_l = view_.filter_dry_water_depth(h_l);
693 const auto lower_bound =
694 (
ScalarNumber(1.) - relax) * filtered_h_l * filtered_h_l * v2_max -
696 if (!(std::min(Number(0.), psi_l - lower_bound) == Number(0.))) {
698 std::cout << std::fixed << std::setprecision(16);
700 <<
"Bounds violation: low-order square velocity (critical)!\n";
701 std::cout <<
"\t\tPsi left: 0 <= " << psi_l <<
"\n" << std::endl;
710 const Number tolerance(newton_tolerance());
711 if (!(std::max(Number(0.), t_r - t_l - tolerance) == Number(0.))) {
731 const auto &h_U = view_.water_depth(U);
732 const auto &h_P = view_.water_depth(P);
733 const auto &q_U = view_.momentum(U);
734 const auto &q_P = view_.momentum(P);
737 (relax_small * (h_U + t_l * h_P) * h_P * v2_max -
738 ((q_U * q_P) + q_P * q_P * t_l));
740 (relax_small * (h_U + t_r * h_P) * h_P * v2_max -
741 ((q_U * q_P) + q_P * q_P * t_r));
744 t_l, t_r, psi_l, psi_r, dpsi_l, dpsi_r, Number(-1.));
746#ifdef DEBUG_OUTPUT_LIMITER
747 if (std::max(Number(0.), psi_r + Number(eps)) == Number(0.)) {
748 std::cout <<
"psi_l: " << psi_l << std::endl;
749 std::cout <<
"psi_r: " << psi_r << std::endl;
750 std::cout <<
"dpsi_l: " << dpsi_l << std::endl;
751 std::cout <<
"dpsi_r: " << dpsi_r << std::endl;
752 std::cout <<
"t_l: (end) " << t_l << std::endl;
753 std::cout <<
"t_r: (end) " << t_r << std::endl;
758#ifdef DEBUG_EXPENSIVE_BOUNDS_CHECK
763 const auto U_new = U + t_l * P;
764 const auto h_new = view_.water_depth(U_new);
765 const auto q_new = view_.momentum(U_new);
768 relax_small * h_new * h_new * v2_max - q_new.norm_square();
770 const auto lower_bound =
774 const bool psi_valid =
775 std::min(Number(0.), psi_new - lower_bound) == Number(0.);
778 std::cout << std::fixed << std::setprecision(16);
779 std::cout <<
"Bounds violation: high-order square velocity!\n";
780 std::cout <<
"\t\tPsi: 0 <= " << psi_new <<
"\n" << std::endl;
788 return {t_l, success};