14 namespace ShallowWater
16 template <
int dim,
typename Number>
17 std::tuple<Number, bool>
24 const auto view = hyperbolic_system.view<dim, Number>();
30 const auto &[h_min, h_max, v2_max] = bounds;
33 constexpr ScalarNumber eps = std::numeric_limits<ScalarNumber>::epsilon();
34 const auto small = view.dry_state_relaxation_small();
35 const auto large = view.dry_state_relaxation_large();
46 auto h_U = view.water_depth(U);
47 const auto &h_P = view.water_depth(P);
49 const auto test_min = view.filter_dry_water_depth(
50 std::max(Number(0.), h_U - relax * h_max));
51 const auto test_max = view.filter_dry_water_depth(
52 std::max(Number(0.), h_min - relax * h_U));
54 if (!(test_min == Number(0.) && test_max == Number(0.))) {
56 std::cout << std::fixed << std::setprecision(16);
57 std::cout <<
"Bounds violation: low-order water depth (critical)!\n"
58 <<
"\n\t\th min: " << h_min
62 <<
"\n\t\th max: " << h_max <<
"\n"
68 const Number denominator =
71 constexpr auto lt = dealii::SIMDComparison::less_than;
73 t_r = dealii::compare_and_apply_mask<lt>(
82 (h_max - h_U) * denominator,
85 t_r = dealii::compare_and_apply_mask<lt>(
94 (h_U - h_min) * denominator,
104 t_r = std::min(t_r, t_max);
105 t_r = std::max(t_r, t_min);
108#ifdef EXPENSIVE_BOUNDS_CHECK
112 const auto h_new = view.water_depth(U + t_r * P);
113 const auto test_new_min = view.filter_dry_water_depth(
114 std::max(Number(0.), h_new - relax * h_max));
115 const auto test_new_max = view.filter_dry_water_depth(
116 std::max(Number(0.), h_min - relax * h_new));
118 if (!(test_new_min == Number(0.) && test_new_max == Number(0.))) {
120 std::cout << std::fixed << std::setprecision(30);
121 std::cout <<
"Bounds violation: high-order water depth!\n"
122 <<
"\n\t\th min: " << h_min
124 <<
"\n\t\th: " << h_new
126 <<
"\n\t\th max: " << h_max <<
"\n"
148 const auto U_r = U + t_r * P;
149 const auto h_r = view.water_depth(U_r);
150 const auto q_r = view.momentum(U_r);
152 const auto psi_r = relax_small * h_r * h_r * v2_max - q_r.norm_square();
158 t_l = dealii::compare_and_apply_mask<
159 dealii::SIMDComparison::greater_than>(psi_r, Number(0.), t_r, t_l);
163 return {t_l, success};
165#ifdef DEBUG_OUTPUT_LIMITER
167 std::cout << std::endl;
168 std::cout << std::fixed << std::setprecision(16);
169 std::cout <<
"t_l: (start) " << t_l << std::endl;
170 std::cout <<
"t_r: (start) " << t_r << std::endl;
174 const auto U_l = U + t_l * P;
175 const auto h_l = view.water_depth(U_l);
176 const auto q_l = view.momentum(U_l);
178 const auto psi_l = relax_small * h_l * h_l * v2_max - q_l.norm_square();
188 const auto filtered_h_l = view.filter_dry_water_depth(h_l);
189 const auto lower_bound =
190 (
ScalarNumber(1.) - relax) * filtered_h_l * filtered_h_l * v2_max -
192 if (!(std::min(Number(0.), psi_l - lower_bound) == Number(0.))) {
194 std::cout << std::fixed << std::setprecision(16);
196 <<
"Bounds violation: low-order square velocity (critical)!\n";
197 std::cout <<
"\t\tPsi left: 0 <= " << psi_l <<
"\n" << std::endl;
206 const Number tolerance(parameters.newton_tolerance());
207 if (!(std::max(Number(0.), t_r - t_l - tolerance) == Number(0.))) {
225 const auto &h_U = view.water_depth(U);
226 const auto &h_P = view.water_depth(P);
227 const auto &q_U = view.momentum(U);
228 const auto &q_P = view.momentum(P);
231 (h_U + t_l * h_P) * h_P * v2_max -
234 (h_U + t_r * h_P) * h_P * v2_max -
238 t_l, t_r, psi_l, psi_r, dpsi_l, dpsi_r, Number(-1.));
240#ifdef DEBUG_OUTPUT_LIMITER
241 if (std::max(Number(0.), psi_r + Number(eps)) == Number(0.)) {
242 std::cout <<
"psi_l: " << psi_l << std::endl;
243 std::cout <<
"psi_r: " << psi_r << std::endl;
244 std::cout <<
"dpsi_l: " << dpsi_l << std::endl;
245 std::cout <<
"dpsi_r: " << dpsi_r << std::endl;
246 std::cout <<
"t_l: (end) " << t_l << std::endl;
247 std::cout <<
"t_r: (end) " << t_r << std::endl;
252#ifdef EXPENSIVE_BOUNDS_CHECK
257 const auto U_new = U + t_l * P;
258 const auto h_new = view.water_depth(U_new);
259 const auto q_new = view.momentum(U_new);
262 relax_small * h_new * h_new * v2_max - q_new.norm_square();
264 const auto lower_bound =
268 const bool psi_valid =
269 std::min(Number(0.), psi_new - lower_bound) == Number(0.);
272 std::cout << std::fixed << std::setprecision(16);
273 std::cout <<
"Bounds violation: high-order square velocity!\n";
274 std::cout <<
"\t\tPsi: 0 <= " << psi_new <<
"\n" << std::endl;
282 return {t_l, success};
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.))
typename View::ScalarNumber ScalarNumber
std::array< Number, n_bounds > Bounds
typename View::state_type state_type
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))