10#include <compile_time_options.h>
20 namespace ShallowWater
22 template <
int dim,
typename Number =
double>
30 template <
typename ScalarNumber =
double>
31 class Limiter :
public dealii::ParameterAcceptor
43 template <
int dim,
typename Number =
double>
56 const std::string &subsection =
"/Limiter")
57 : ParameterAcceptor(subsection)
58 , hyperbolic_system_(&hyperbolic_system)
62 "iterations", iterations_,
"Number of limiter iterations");
64 if constexpr (std::is_same_v<ScalarNumber, double>)
65 newton_tolerance_ = 1.e-10;
67 newton_tolerance_ = 1.e-4;
68 add_parameter(
"newton tolerance",
70 "Tolerance for the quadratic newton stopping criterion");
72 newton_max_iterations_ = 2;
73 add_parameter(
"newton max iterations",
74 newton_max_iterations_,
75 "Maximal number of quadratic newton iterations performed "
78 relaxation_factor_ = ScalarNumber(1.);
79 add_parameter(
"relaxation factor",
81 "Factor for scaling the relaxation window with r_i = "
82 "factor * (m_i/|Omega|)^(1.5/d).");
90 template <
int dim,
typename Number>
94 hyperbolic_system_->template view<dim, Number>(), *
this};
104 unsigned int iterations_;
105 ScalarNumber newton_tolerance_;
106 unsigned int newton_max_iterations_;
107 ScalarNumber relaxation_factor_;
115 dealii::ObserverPointer<const HyperbolicSystem> hyperbolic_system_;
119 template <
int,
typename>
132 template <
int dim,
typename Number>
168 using Bounds = std::array<Number, n_bounds>;
185 return limiter_.iterations_;
193 return limiter_.newton_tolerance_;
201 return limiter_.newton_max_iterations_;
209 return limiter_.relaxation_factor_;
217 const unsigned int i,
226 const Bounds &bounds_right)
const;
262 const unsigned int i,
274 const dealii::Tensor<1, dim, Number> &scaled_c_ij,
297 const Number t_min = Number(0.),
298 const Number t_max = Number(1.))
const;
316 Number h_relaxation_numerator_;
317 Number v2_relaxation_numerator_;
318 Number relaxation_denominator_;
331 template <
int dim,
typename Number>
332 DEAL_II_ALWAYS_INLINE
inline auto
338 const auto h_i = view_.water_depth(U_i);
340 view_.momentum(U_i) * view_.inverse_water_depth_mollified(U_i);
341 const auto v2_i = v_i.norm_square();
343 return { h_i, h_i, v2_i};
347 template <
int dim,
typename Number>
351 const auto &[h_min_l, h_max_l, v2_max_l] = bounds_l;
352 const auto &[h_min_r, h_max_r, v2_max_r] = bounds_r;
354 return {std::min(h_min_l, h_min_r),
355 std::max(h_max_l, h_max_r),
356 std::max(v2_max_l, v2_max_r)};
360 template <
int dim,
typename Number>
361 DEAL_II_ALWAYS_INLINE
inline auto
363 const Number &hd)
const
366 auto relaxed_bounds = bounds;
367 auto &[h_min, h_max, v2_max] = relaxed_bounds;
371 Number r = std::sqrt(hd);
372 if constexpr (dim == 2)
373 r = dealii::Utilities::fixed_power<3>(std::sqrt(r));
374 else if constexpr (dim == 1)
375 r = dealii::Utilities::fixed_power<3>(r);
376 r *= relaxation_factor();
378 constexpr ScalarNumber eps = std::numeric_limits<ScalarNumber>::epsilon();
379 h_min *= std::max((Number(1.) - r), Number(eps));
380 h_max *= (Number(1.) + r);
381 v2_max *= (Number(1.) + r);
383 return relaxed_bounds;
387 template <
int dim,
typename Number>
388 DEAL_II_ALWAYS_INLINE
inline void
396 auto &[h_min, h_max, v2_max] = bounds_;
398 h_min = Number(std::numeric_limits<ScalarNumber>::max());
402 h_relaxation_numerator_ = Number(0.);
403 v2_relaxation_numerator_ = Number(0.);
404 relaxation_denominator_ = Number(0.);
408 template <
int dim,
typename Number>
414 const dealii::Tensor<1, dim, Number> &scaled_c_ij,
419 const auto f_star_ij = view_.f(U_star_ij);
420 const auto f_star_ji = view_.f(U_star_ji);
423 const auto U_ij_bar =
425 (U_star_ij + U_star_ji +
426 contract(
add(f_star_ij, -f_star_ji), scaled_c_ij)) +
431 auto &[h_min, h_max, v2_max] = bounds_;
433 const auto h_bar_ij = view_.water_depth(U_ij_bar);
434 h_min = std::min(h_min, h_bar_ij);
435 h_max = std::max(h_max, h_bar_ij);
437 const auto v_bar_ij = view_.momentum(U_ij_bar) *
438 view_.inverse_water_depth_mollified(U_ij_bar);
439 const auto v2_bar_ij = v_bar_ij.norm_square();
440 v2_max = std::max(v2_max, v2_bar_ij);
445 const auto beta_ij = Number(1.);
447 relaxation_denominator_ += std::abs(beta_ij);
449 const auto h_i = view_.water_depth(U_i_);
450 const auto h_j = view_.water_depth(U_j);
451 h_relaxation_numerator_ += beta_ij * (h_i + h_j);
454 view_.momentum(U_i_) * view_.inverse_water_depth_mollified(U_i_);
456 view_.momentum(U_j) * view_.inverse_water_depth_mollified(U_j);
457 v2_relaxation_numerator_ +=
458 beta_ij * (-vel_i.norm_square() + vel_j.norm_square());
462 template <
int dim,
typename Number>
463 DEAL_II_ALWAYS_INLINE
inline auto
466 const auto &[h_min, h_max, v2_max] = bounds_;
468 auto relaxed_bounds = fully_relax_bounds(bounds_, hd_i);
469 auto &[h_min_relaxed, h_max_relaxed, v2_max_relaxed] = relaxed_bounds;
473 constexpr ScalarNumber eps = std::numeric_limits<ScalarNumber>::epsilon();
475 const Number h_relaxed =
ScalarNumber(2. * relaxation_factor()) *
476 std::abs(h_relaxation_numerator_) /
477 (relaxation_denominator_ + Number(eps));
479 const Number v2_relaxed =
ScalarNumber(2. * relaxation_factor()) *
480 std::abs(v2_relaxation_numerator_) /
481 (relaxation_denominator_ + Number(eps));
483 h_min_relaxed = std::max(h_min_relaxed, h_min - h_relaxed);
484 h_max_relaxed = std::min(h_max_relaxed, h_max + h_relaxed);
485 v2_max_relaxed = std::min(v2_max_relaxed, v2_max + v2_relaxed);
487 return relaxed_bounds;
typename get_value_type< Number >::type ScalarNumber
dealii::Tensor< 1, problem_dimension, Number > state_type
Vectors::MultiComponentVectorView< ScalarNumber, n_precomputed_values, dealii::VectorizedArray< ScalarNumber >::size(), dealii::MemorySpace::Host, false > PrecomputedVectorView
std::array< Number, n_precomputed_values > precomputed_type
static constexpr unsigned int problem_dimension
std::tuple< state_type, Number > flux_contribution_type
HyperbolicSystemView< dim, Number > View
unsigned int newton_max_iterations() const
typename View::PrecomputedVectorView PrecomputedVectorView
typename View::ScalarNumber ScalarNumber
Bounds projection_bounds_from_state(const PrecomputedVectorView &pv, const unsigned int i, const state_type &U_i) const
static constexpr auto problem_dimension
void reset(const PrecomputedVectorView &pv, const unsigned int i, const state_type &U_i, const flux_contribution_type &flux_i)
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.)) const
Bounds bounds(const Number hd_i) const
Bounds combine_bounds(const Bounds &bounds_left, const Bounds &bounds_right) const
static constexpr unsigned int n_bounds
ScalarNumber newton_tolerance() const
LimiterView(const View &view, const Limiter< ScalarNumber > &limiter)
void accumulate(const PrecomputedVectorView &pv, const state_type &U_j, const state_type &U_star_ij, const state_type &U_star_ji, const dealii::Tensor< 1, dim, Number > &scaled_c_ij, const state_type &affine_shift)
typename View::state_type state_type
std::array< Number, n_bounds > Bounds
Bounds fully_relax_bounds(const Bounds &bounds, const Number &hd) const
typename View::flux_contribution_type flux_contribution_type
unsigned int iterations() const
typename View::precomputed_type precomputed_type
ScalarNumber relaxation_factor() const
Limiter(const HyperbolicSystem &hyperbolic_system, const std::string &subsection="/Limiter")
DEAL_II_HOST_DEVICE_ALWAYS_INLINE dealii::Tensor< 1, problem_dim, T > contract(const FT &flux_ij, const TT &c_ij)
DEAL_II_HOST_DEVICE_ALWAYS_INLINE FT add(const FT &flux_left_ij, const FT &flux_right_ij)