8#include <compile_time_options.h>
18 namespace ScalarConservation
20 template <
int dim,
typename Number =
double>
28 template <
typename ScalarNumber =
double>
29 class Limiter :
public dealii::ParameterAcceptor
41 template <
int dim,
typename Number =
double>
54 const std::string &subsection =
"/Limiter")
55 : ParameterAcceptor(subsection)
56 , hyperbolic_system_(&hyperbolic_system)
60 "iterations", iterations_,
"Number of limiter iterations");
62 relaxation_factor_ = ScalarNumber(1.);
63 add_parameter(
"relaxation factor",
65 "Factor for scaling the relaxation window with r_i = "
66 "factor * (m_i/|Omega|)^(1.5/d).");
74 template <
int dim,
typename Number>
78 hyperbolic_system_->template view<dim, Number>(), *
this};
88 unsigned int iterations_;
89 ScalarNumber relaxation_factor_;
97 dealii::ObserverPointer<const HyperbolicSystem> hyperbolic_system_;
101 template <
int,
typename>
114 template <
int dim,
typename Number>
151 using Bounds = std::array<Number, n_bounds>;
168 return limiter_.iterations_;
176 return limiter_.relaxation_factor_;
184 const unsigned int i,
193 const Bounds &bounds_right)
const;
227 const unsigned int i,
236 const unsigned int *js,
239 const dealii::Tensor<1, dim, Number> &scaled_c_ij,
262 const Number t_min = Number(0.),
263 const Number t_max = Number(1.))
const;
280 Number u_relaxation_numerator_;
281 Number u_relaxation_denominator_;
293 template <
int dim,
typename Number>
294 DEAL_II_ALWAYS_INLINE
inline auto
300 const auto u_i = view_.state(U_i);
305 template <
int dim,
typename Number>
309 const auto &[u_min_l, u_max_l] = bounds_left;
310 const auto &[u_min_r, u_max_r] = bounds_right;
312 return {std::min(u_min_l, u_min_r), std::max(u_max_l, u_max_r)};
316 template <
int dim,
typename Number>
317 DEAL_II_ALWAYS_INLINE
inline auto
319 const Number &hd)
const
322 auto relaxed_bounds = bounds;
323 auto &[u_min, u_max] = relaxed_bounds;
327 Number r = std::sqrt(hd);
328 if constexpr (dim == 2)
329 r = dealii::Utilities::fixed_power<3>(std::sqrt(r));
330 else if constexpr (dim == 1)
331 r = dealii::Utilities::fixed_power<3>(r);
332 r *= relaxation_factor();
334 u_min = std::min((Number(1.) - r) * u_min, (Number(1.) + r) * u_min);
335 u_max = std::max((Number(1.) + r) * u_max, (Number(1.) - r) * u_max);
337 return relaxed_bounds;
341 template <
int dim,
typename Number>
342 DEAL_II_ALWAYS_INLINE
inline void
353 auto &[u_min, u_max] = bounds_;
355 u_min = Number(std::numeric_limits<ScalarNumber>::max());
356 u_max = Number(std::numeric_limits<ScalarNumber>::lowest());
360 u_relaxation_numerator_ = Number(0.);
361 u_relaxation_denominator_ = Number(0.);
365 template <
int dim,
typename Number>
368 const unsigned int * ,
371 const dealii::Tensor<1, dim, Number> &scaled_c_ij,
375 auto &[u_min, u_max] = bounds_;
377 const auto u_i = view_.state(U_i_);
378 const auto u_j = view_.state(U_j);
380 const auto U_ij_bar =
385 const auto u_ij_bar = view_.state(U_ij_bar);
389 u_min = std::min(u_min, u_ij_bar);
390 u_max = std::max(u_max, u_ij_bar);
395 const auto beta_ij = Number(1.);
396 u_relaxation_numerator_ += beta_ij * (u_i + u_j);
397 u_relaxation_denominator_ += std::abs(beta_ij);
401 template <
int dim,
typename Number>
402 DEAL_II_ALWAYS_INLINE
inline auto
405 const auto &[u_min, u_max] = bounds_;
407 auto relaxed_bounds = fully_relax_bounds(bounds_, hd_i);
408 auto &[u_min_relaxed, u_max_relaxed] = relaxed_bounds;
412 constexpr ScalarNumber eps = std::numeric_limits<ScalarNumber>::epsilon();
414 const Number u_relaxation =
416 std::abs(u_relaxation_numerator_) /
417 (std::abs(u_relaxation_denominator_) + Number(eps));
419 u_min_relaxed = std::max(u_min_relaxed, u_min - u_relaxation);
420 u_max_relaxed = std::min(u_max_relaxed, u_max + u_relaxation);
422 return relaxed_bounds;
static constexpr unsigned int problem_dimension
std::array< Number, n_precomputed_values > precomputed_type
Vectors::MultiComponentVectorView< ScalarNumber, n_precomputed_values, dealii::VectorizedArray< ScalarNumber >::size(), dealii::MemorySpace::Host, false > PrecomputedVectorView
typename get_value_type< Number >::type ScalarNumber
dealii::Tensor< 1, problem_dimension, Number > state_type
flux_type flux_contribution_type
LimiterView(const View &view, const Limiter< ScalarNumber > &limiter)
Bounds combine_bounds(const Bounds &bounds_left, const Bounds &bounds_right) const
typename View::state_type state_type
void reset(const PrecomputedVectorView &pv, const unsigned int i, const state_type &U_i, const flux_contribution_type &flux_i)
std::array< Number, n_bounds > Bounds
typename View::PrecomputedVectorView PrecomputedVectorView
ScalarNumber relaxation_factor() const
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
HyperbolicSystemView< dim, Number > View
static constexpr auto problem_dimension
typename View::precomputed_type precomputed_type
static constexpr unsigned int n_bounds
Bounds bounds(const Number hd_i) const
unsigned int iterations() const
typename View::ScalarNumber ScalarNumber
Bounds projection_bounds_from_state(const PrecomputedVectorView &pv, const unsigned int i, const state_type &U_i) const
typename View::flux_contribution_type flux_contribution_type
Bounds fully_relax_bounds(const Bounds &bounds, const Number &hd) const
void accumulate(const PrecomputedVectorView &pv, const unsigned int *js, const state_type &U_j, const flux_contribution_type &flux_j, const dealii::Tensor< 1, dim, Number > &scaled_c_ij, const state_type &affine_shift)
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)