8#include <compile_time_options.h>
19 namespace EulerBarotropic
21 template <
int dim,
typename Number =
double>
29 template <
typename ScalarNumber =
double>
30 class Limiter :
public dealii::ParameterAcceptor
42 template <
int dim,
typename Number =
double>
55 const std::string &subsection =
"/Limiter")
56 : ParameterAcceptor(subsection)
57 , hyperbolic_system_(&hyperbolic_system)
61 "iterations", iterations_,
"Number of limiter iterations");
63 relaxation_factor_ = ScalarNumber(1.);
64 add_parameter(
"relaxation factor",
66 "Factor for scaling the relaxation window with r_i = "
67 "factor * (m_i/|Omega|)^(1.5/d).");
75 template <
int dim,
typename Number>
79 hyperbolic_system_->template view<dim, Number>(), *
this};
89 unsigned int iterations_;
90 ScalarNumber relaxation_factor_;
98 dealii::ObserverPointer<const HyperbolicSystem> hyperbolic_system_;
102 template <
int,
typename>
115 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;
230 const unsigned int i,
239 const unsigned int *js,
242 const dealii::Tensor<1, dim, Number> &scaled_c_ij,
274 const Number t_min = Number(0.),
275 const Number t_max = Number(1.))
const;
292 Number rho_relaxation_numerator_;
293 Number rho_relaxation_denominator_;
306 template <
int dim,
typename Number>
307 DEAL_II_ALWAYS_INLINE
inline auto
313 const auto rho_i = view_.density(U_i);
314 return { rho_i, rho_i};
318 template <
int dim,
typename Number>
322 const auto &[rho_min_l, rho_max_l] = bounds_left;
323 const auto &[rho_min_r, rho_max_r] = bounds_right;
325 return {std::min(rho_min_l, rho_min_r), std::max(rho_max_l, rho_max_r)};
329 template <
int dim,
typename Number>
330 DEAL_II_ALWAYS_INLINE
inline auto
332 const Number &hd)
const
335 auto relaxed_bounds = bounds;
336 auto &[rho_min_relaxed, rho_max_relaxed] = relaxed_bounds;
340 Number r = std::sqrt(hd);
341 if constexpr (dim == 2)
342 r = dealii::Utilities::fixed_power<3>(std::sqrt(r));
343 else if constexpr (dim == 1)
344 r = dealii::Utilities::fixed_power<3>(r);
345 r *= relaxation_factor();
347 constexpr ScalarNumber eps = std::numeric_limits<ScalarNumber>::epsilon();
348 rho_min_relaxed *= std::max(Number(1.) - r, Number(eps));
349 rho_max_relaxed *= (Number(1.) + r);
351 return relaxed_bounds;
355 template <
int dim,
typename Number>
356 DEAL_II_ALWAYS_INLINE
inline void
367 auto &[rho_min, rho_max] = bounds_;
369 rho_min = Number(std::numeric_limits<ScalarNumber>::max());
370 rho_max = Number(0.);
374 rho_relaxation_numerator_ = Number(0.);
375 rho_relaxation_denominator_ = Number(0.);
379 template <
int dim,
typename Number>
382 const unsigned int * ,
385 const dealii::Tensor<1, dim, Number> &scaled_c_ij,
392 Assert(std::max(affine_shift.norm(), Number(0.)) == Number(0.),
393 dealii::ExcNotImplemented());
396 auto &[rho_min, rho_max] = bounds_;
398 const auto rho_i = view_.density(U_i_);
399 const auto rho_j = view_.density(U_j);
402 const auto U_ij_bar =
407 const auto rho_ij_bar = view_.density(U_ij_bar);
411 rho_min = std::min(rho_min, rho_ij_bar);
412 rho_max = std::max(rho_max, rho_ij_bar);
417 const auto beta_ij = Number(1.);
418 rho_relaxation_numerator_ += beta_ij * (rho_i + rho_j);
419 rho_relaxation_denominator_ += std::abs(beta_ij);
423 template <
int dim,
typename Number>
424 DEAL_II_ALWAYS_INLINE
inline auto
427 const auto &[rho_min, rho_max] = bounds_;
429 auto relaxed_bounds = fully_relax_bounds(bounds_, hd_i);
430 auto &[rho_min_relaxed, rho_max_relaxed] = relaxed_bounds;
434 constexpr ScalarNumber eps = std::numeric_limits<ScalarNumber>::epsilon();
436 const auto rho_relaxation =
438 std::abs(rho_relaxation_numerator_) /
439 (std::abs(rho_relaxation_denominator_) + Number(eps));
441 rho_min_relaxed = std::max(rho_min_relaxed, rho_min - rho_relaxation);
442 rho_max_relaxed = std::min(rho_max_relaxed, rho_max + rho_relaxation);
444 return relaxed_bounds;
flux_type flux_contribution_type
std::array< Number, n_precomputed_values > precomputed_type
dealii::Tensor< 1, problem_dimension, Number > state_type
static constexpr unsigned int problem_dimension
typename get_value_type< Number >::type ScalarNumber
Vectors::MultiComponentVectorView< ScalarNumber, n_precomputed_values, dealii::VectorizedArray< ScalarNumber >::size(), dealii::MemorySpace::Host, false > PrecomputedVectorView
typename View::state_type state_type
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
typename View::ScalarNumber ScalarNumber
LimiterView(const View &view, const Limiter< ScalarNumber > &limiter)
Bounds combine_bounds(const Bounds &bounds_left, const Bounds &bounds_right) const
static constexpr auto problem_dimension
HyperbolicSystemView< dim, Number > View
typename View::precomputed_type precomputed_type
Bounds projection_bounds_from_state(const PrecomputedVectorView &pv, const unsigned int i, const state_type &U_i) const
ScalarNumber relaxation_factor() const
Bounds fully_relax_bounds(const Bounds &bounds, const Number &hd) const
static constexpr unsigned int n_bounds
Bounds bounds(const Number hd_i) const
unsigned int iterations() const
typename View::flux_contribution_type flux_contribution_type
std::array< Number, n_bounds > Bounds
void reset(const PrecomputedVectorView &pv, const unsigned int i, const state_type &U_i, const flux_contribution_type &flux_i)
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)
typename View::PrecomputedVectorView PrecomputedVectorView
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)