12#include <compile_time_options.h>
18 namespace ShallowWater
20 template <
typename ScalarNumber =
double>
25 : ParameterAcceptor(subsection)
29 "iterations", iterations_,
"Number of limiter iterations");
31 if constexpr (std::is_same_v<ScalarNumber, double>)
32 newton_tolerance_ = 1.e-10;
34 newton_tolerance_ = 1.e-4;
35 add_parameter(
"newton tolerance",
37 "Tolerance for the quadratic newton stopping criterion");
39 newton_max_iterations_ = 2;
40 add_parameter(
"newton max iterations",
41 newton_max_iterations_,
42 "Maximal number of quadratic newton iterations performed "
45 relaxation_factor_ = ScalarNumber(1.);
46 add_parameter(
"relaxation factor",
48 "Factor for scaling the relaxation window with r_i = "
49 "factor * (m_i/|Omega|)^(1.5/d).");
58 unsigned int iterations_;
59 ScalarNumber newton_tolerance_;
60 unsigned int newton_max_iterations_;
61 ScalarNumber relaxation_factor_;
70 template <
int dim,
typename Number =
double>
108 using Bounds = std::array<Number, n_bounds>;
116 : hyperbolic_system(hyperbolic_system)
117 , parameters(parameters)
118 , precomputed_values(precomputed_values)
135 const Bounds &bounds_right)
const;
160 void reset(
const unsigned int i,
171 const dealii::Tensor<1, dim, Number> &scaled_c_ij,
192 const Number t_min = Number(0.),
193 const Number t_max = Number(1.));
210 Number h_relaxation_numerator;
211 Number v2_relaxation_numerator;
212 Number relaxation_denominator;
225 template <
int dim,
typename Number>
229 const auto view = hyperbolic_system.view<dim, Number>();
230 const auto h_i = view.water_depth(U_i);
232 view.momentum(U_i) * view.inverse_water_depth_mollified(U_i);
233 const auto v2_i = v_i.norm_square();
235 return { h_i, h_i, v2_i};
239 template <
int dim,
typename Number>
240 DEAL_II_ALWAYS_INLINE
inline auto
244 const auto &[h_min_l, h_max_l, v2_max_l] = bounds_l;
245 const auto &[h_min_r, h_max_r, v2_max_r] = bounds_r;
247 return {std::min(h_min_l, h_min_r),
248 std::max(h_max_l, h_max_r),
249 std::max(v2_max_l, v2_max_r)};
253 template <
int dim,
typename Number>
254 DEAL_II_ALWAYS_INLINE
inline void
261 auto &[h_min, h_max, v2_max] = bounds_;
263 h_min = Number(std::numeric_limits<ScalarNumber>::max());
267 h_relaxation_numerator = Number(0.);
268 v2_relaxation_numerator = Number(0.);
269 relaxation_denominator = Number(0.);
273 template <
int dim,
typename Number>
278 const dealii::Tensor<1, dim, Number> &scaled_c_ij,
281 const auto view = hyperbolic_system.view<dim, Number>();
285 const auto f_star_ij = view.f(U_star_ij);
286 const auto f_star_ji = view.f(U_star_ji);
289 const auto U_ij_bar =
291 (U_star_ij + U_star_ji +
292 contract(
add(f_star_ij, -f_star_ji), scaled_c_ij)) +
297 auto &[h_min, h_max, v2_max] = bounds_;
299 const auto h_bar_ij = view.water_depth(U_ij_bar);
300 h_min = std::min(h_min, h_bar_ij);
301 h_max = std::max(h_max, h_bar_ij);
303 const auto v_bar_ij = view.momentum(U_ij_bar) *
304 view.inverse_water_depth_mollified(U_ij_bar);
305 const auto v2_bar_ij = v_bar_ij.norm_square();
306 v2_max = std::max(v2_max, v2_bar_ij);
311 const auto beta_ij = Number(1.);
313 relaxation_denominator += std::abs(beta_ij);
315 const auto h_i = view.water_depth(U_i);
316 const auto h_j = view.water_depth(U_j);
317 h_relaxation_numerator += beta_ij * (h_i + h_j);
320 view.momentum(U_i) * view.inverse_water_depth_mollified(U_i);
322 view.momentum(U_j) * view.inverse_water_depth_mollified(U_j);
323 v2_relaxation_numerator +=
324 beta_ij * (-vel_i.norm_square() + vel_j.norm_square());
328 template <
int dim,
typename Number>
329 DEAL_II_ALWAYS_INLINE
inline auto
332 auto relaxed_bounds = bounds_;
333 auto &[h_min, h_max, v2_max] = relaxed_bounds;
337 Number r_i = std::sqrt(hd_i);
338 if constexpr (dim == 2)
339 r_i = dealii::Utilities::fixed_power<3>(std::sqrt(r_i));
340 else if constexpr (dim == 1)
341 r_i = dealii::Utilities::fixed_power<3>(r_i);
342 r_i *= parameters.relaxation_factor();
344 constexpr ScalarNumber eps = std::numeric_limits<ScalarNumber>::epsilon();
347 std::abs(h_relaxation_numerator) /
348 (relaxation_denominator + Number(eps));
350 h_min = std::max((Number(1.) - r_i) * h_min, h_min - h_relaxed);
351 h_max = std::min((Number(1.) + r_i) * h_max, h_max + h_relaxed);
354 std::abs(v2_relaxation_numerator) /
355 (relaxation_denominator + Number(eps));
357 v2_max = std::min((Number(1.) + r_i) * v2_max, v2_max + v2_relaxed);
359 return relaxed_bounds;
typename get_value_type< Number >::type ScalarNumber
Vectors::MultiComponentVector< ScalarNumber, n_precomputed_values > PrecomputedVector
dealii::Tensor< 1, problem_dimension, Number > state_type
std::array< Number, n_precomputed_values > precomputed_type
static constexpr unsigned int problem_dimension
std::tuple< state_type, Number > flux_contribution_type
ACCESSOR_READ_ONLY(iterations)
ACCESSOR_READ_ONLY(relaxation_factor)
ACCESSOR_READ_ONLY(newton_tolerance)
ACCESSOR_READ_ONLY(newton_max_iterations)
LimiterParameters(const std::string &subsection="/Limiter")
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
typename View::flux_contribution_type flux_contribution_type
std::array< Number, n_bounds > Bounds
typename View::PrecomputedVector PrecomputedVector
void accumulate(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)
Bounds bounds(const Number hd_i) const
Limiter(const HyperbolicSystem &hyperbolic_system, const Parameters ¶meters, const PrecomputedVector &precomputed_values)
typename View::precomputed_type precomputed_type
Bounds combine_bounds(const Bounds &bounds_left, const Bounds &bounds_right) const
Bounds bounds_from_state(const unsigned int i, const state_type &U_i) const
void reset(const unsigned int i, const state_type &U_i, const flux_contribution_type &flux_i)
typename View::state_type state_type
static constexpr auto problem_dimension
static constexpr unsigned int n_bounds
LimiterParameters< ScalarNumber > Parameters
DEAL_II_ALWAYS_INLINE FT add(const FT &flux_left_ij, const FT &flux_right_ij)
DEAL_II_ALWAYS_INLINE dealii::Tensor< 1, problem_dim, T > contract(const FT &flux_ij, const TT &c_ij)