8#include <compile_time_options.h>
21 template <
int dim,
typename Number =
double>
56 template <
typename ScalarNumber =
double>
57 class Limiter :
public dealii::ParameterAcceptor
69 template <
int dim,
typename Number =
double>
82 const std::string &subsection =
"/Limiter")
83 : ParameterAcceptor(subsection)
84 , hyperbolic_system_(&hyperbolic_system)
88 "iterations", iterations_,
"Number of limiter iterations");
90 if constexpr (std::is_same_v<ScalarNumber, double>)
91 newton_tolerance_ = 1.e-10;
93 newton_tolerance_ = 1.e-4;
94 add_parameter(
"newton tolerance",
96 "Tolerance for the quadratic newton stopping criterion");
98 newton_max_iterations_ = 2;
99 add_parameter(
"newton max iterations",
100 newton_max_iterations_,
101 "Maximal number of quadratic newton iterations performed "
104 relaxation_factor_ = ScalarNumber(1.);
105 add_parameter(
"relaxation factor",
107 "Factor for scaling the relaxation window with r_i = "
108 "factor * (m_i/|Omega|)^(1.5/d).");
116 template <
int dim,
typename Number>
120 hyperbolic_system_->template view<dim, Number>(), *
this};
130 unsigned int iterations_;
131 ScalarNumber newton_tolerance_;
132 unsigned int newton_max_iterations_;
133 ScalarNumber relaxation_factor_;
141 dealii::ObserverPointer<const HyperbolicSystem> hyperbolic_system_;
145 template <
int,
typename>
158 template <
int dim,
typename Number>
194 using Bounds = std::array<Number, n_bounds>;
211 return limiter_.iterations_;
219 return limiter_.newton_tolerance_;
227 return limiter_.newton_max_iterations_;
235 return limiter_.relaxation_factor_;
243 const unsigned int i,
252 const Bounds &bounds_right)
const;
289 const unsigned int i,
298 const unsigned int *js,
301 const dealii::Tensor<1, dim, Number> &scaled_c_ij,
333 const Number t_min = Number(0.),
334 const Number t_max = Number(1.))
const;
351 Number rho_relaxation_numerator_;
352 Number rho_relaxation_denominator_;
353 Number s_interp_max_;
366 template <
int dim,
typename Number>
367 DEAL_II_ALWAYS_INLINE
inline auto
370 const unsigned int i,
373 const auto rho_i = view_.density(U_i);
374 const auto &[p_i, gamma_min_i, s_i, eta_i] =
375 pv.template read_tensor<Number, precomputed_type>(i);
384 template <
int dim,
typename Number>
388 const auto &[rho_min_l, rho_max_l, s_min_l, gamma_min_l] = bounds_left;
389 const auto &[rho_min_r, rho_max_r, s_min_r, gamma_min_r] = bounds_right;
391 return {std::min(rho_min_l, rho_min_r),
392 std::max(rho_max_l, rho_max_r),
393 std::min(s_min_l, s_min_r),
394 std::min(gamma_min_l, gamma_min_r)};
398 template <
int dim,
typename Number>
399 DEAL_II_ALWAYS_INLINE
inline auto
401 const Number &hd)
const
404 const auto &[rho_min, rho_max, s_min, gamma_min] = bounds;
406 auto relaxed_bounds = bounds;
407 auto &[rho_min_relaxed, rho_max_relaxed, s_min_relaxed, g_m_relaxed] =
412 Number r = std::sqrt(hd);
413 if constexpr (dim == 2)
414 r = dealii::Utilities::fixed_power<3>(std::sqrt(r));
415 else if constexpr (dim == 1)
416 r = dealii::Utilities::fixed_power<3>(r);
417 r *= relaxation_factor();
419 constexpr ScalarNumber eps = std::numeric_limits<ScalarNumber>::epsilon();
420 rho_min_relaxed *= std::max(Number(1.) - r, Number(eps));
421 rho_max_relaxed *= (Number(1.) + r);
422 s_min_relaxed *= std::max(Number(1.) - r, Number(eps));
430 const auto numerator = (gamma_min + Number(1.)) * rho_max;
431 const auto covolume_b = view_.eos_covolume_constant();
432 const auto denominator =
433 gamma_min - Number(1.) +
ScalarNumber(2.) * covolume_b * rho_max;
434 const auto rho_compressibility_bound = numerator / denominator;
436 rho_max_relaxed = std::min(rho_compressibility_bound, rho_max_relaxed);
438 return relaxed_bounds;
442 template <
int dim,
typename Number>
443 DEAL_II_ALWAYS_INLINE
inline void
445 const unsigned int i,
454 auto &[rho_min, rho_max, s_min, gamma_min] = bounds_;
456 rho_min = Number(std::numeric_limits<ScalarNumber>::max());
457 rho_max = Number(0.);
458 s_min = Number(std::numeric_limits<ScalarNumber>::max());
460 const auto &[p_i, gamma_min_i, s_i, eta_i] =
461 pv.template read_tensor<Number, precomputed_type>(i);
463 gamma_min = gamma_min_i;
467 rho_relaxation_numerator_ = Number(0.);
468 rho_relaxation_denominator_ = Number(0.);
469 s_interp_max_ = Number(0.);
473 template <
int dim,
typename Number>
476 const unsigned int *js,
479 const dealii::Tensor<1, dim, Number> &scaled_c_ij,
486 Assert(std::max(affine_shift.norm(), Number(0.)) == Number(0.),
487 dealii::ExcNotImplemented());
490 auto &[rho_min, rho_max, s_min, gamma_min] = bounds_;
492 const auto rho_i = view_.density(U_i_);
493 const auto rho_j = view_.density(U_j);
496 const auto U_ij_bar =
501 const auto rho_ij_bar = view_.density(U_ij_bar);
505 rho_min = std::min(rho_min, rho_ij_bar);
506 rho_max = std::max(rho_max, rho_ij_bar);
511 const auto beta_ij = Number(1.);
512 rho_relaxation_numerator_ += beta_ij * (rho_i + rho_j);
513 rho_relaxation_denominator_ += std::abs(beta_ij);
517 if (view_.compute_strict_bounds()) {
528 const auto s_j = view_.surrogate_specific_entropy(U_j, gamma_min);
530 const auto s_ij_bar =
531 view_.surrogate_specific_entropy(U_ij_bar, gamma_min);
533 const Number s_interp = view_.surrogate_specific_entropy(
536 s_min = std::min(s_min, s_j);
537 s_min = std::min(s_min, s_ij_bar);
538 s_interp_max_ = std::max(s_interp_max_, s_interp);
547 const auto [p_j, gamma_min_j, s_j, eta_j] =
548 pv.template read_tensor<Number, precomputed_type>(js);
550 const auto s_ij_bar =
551 view_.surrogate_specific_entropy(U_ij_bar, gamma_min);
553 s_min = std::min(s_min, s_j);
554 s_min = std::min(s_min, s_ij_bar);
555 s_interp_max_ = std::max(s_interp_max_, s_ij_bar);
560 template <
int dim,
typename Number>
561 DEAL_II_ALWAYS_INLINE
inline auto
564 const auto &[rho_min, rho_max, s_min, gamma_min] = bounds_;
566 auto relaxed_bounds = fully_relax_bounds(bounds_, hd_i);
567 auto &[rho_min_relaxed, rho_max_relaxed, s_min_relaxed, g_m_relaxed] =
572 constexpr ScalarNumber eps = std::numeric_limits<ScalarNumber>::epsilon();
574 const auto rho_relaxation =
576 std::abs(rho_relaxation_numerator_) /
577 (std::abs(rho_relaxation_denominator_) + Number(eps));
579 const auto entropy_relaxation =
580 relaxation_factor() * (s_interp_max_ - s_min);
582 rho_min_relaxed = std::max(rho_min_relaxed, rho_min - rho_relaxation);
583 rho_max_relaxed = std::min(rho_max_relaxed, rho_max + rho_relaxation);
584 s_min_relaxed = std::max(s_min_relaxed, s_min - entropy_relaxation);
586 return relaxed_bounds;
dealii::Tensor< 1, problem_dimension, Number > state_type
Vectors::MultiComponentVectorView< ScalarNumber, n_precomputed_values, dealii::VectorizedArray< ScalarNumber >::size(), dealii::MemorySpace::Host, false > PrecomputedVectorView
typename get_value_type< Number >::type ScalarNumber
static constexpr unsigned int problem_dimension
flux_type flux_contribution_type
std::array< Number, n_precomputed_values > precomputed_type
std::array< Number, n_bounds > Bounds
typename View::ScalarNumber ScalarNumber
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
typename View::state_type state_type
typename View::flux_contribution_type flux_contribution_type
Bounds combine_bounds(const Bounds &bounds_left, const Bounds &bounds_right) const
unsigned int iterations() const
static constexpr unsigned int n_bounds
Bounds bounds(const Number hd_i) const
ScalarNumber newton_tolerance() const
static constexpr auto problem_dimension
ScalarNumber relaxation_factor() const
typename View::PrecomputedVectorView PrecomputedVectorView
typename View::precomputed_type precomputed_type
unsigned int newton_max_iterations() const
Bounds projection_bounds_from_state(const PrecomputedVectorView &pv, const unsigned int i, const state_type &U_i) const
Bounds fully_relax_bounds(const Bounds &bounds, const Number &hd) const
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)
LimiterView(const View &view, const Limiter< ScalarNumber > &limiter)
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)