8#include <compile_time_options.h>
22 namespace EulerBarotropic
25 typename Number = double,
26 typename MemorySpace = dealii::MemorySpace::Host>
34 template <
typename ScalarNumber =
double>
35 class Limiter :
public dealii::ParameterAcceptor
61 const std::string &subsection =
"/Limiter")
62 : ParameterAcceptor(subsection)
63 , parameters_(
"euler_barotropic_limiter_parameters",
65 , hyperbolic_system_(&hyperbolic_system)
68 auto ¶meters = *parameters_.view();
70 parameters.iterations = 2;
71 add_parameter(
"iterations",
72 parameters.iterations,
73 "Number of limiter iterations");
75 parameters.relaxation_factor = 1.;
76 add_parameter(
"relaxation factor",
77 parameters.relaxation_factor,
78 "Factor for scaling the relaxation window with r_i = "
79 "factor * (m_i/|Omega|)^(1.5/d).");
82 ParameterAcceptor::parse_parameters_call_back.connect(
83 [
this] { parameters_.view(); });
95 typename MemorySpace = dealii::MemorySpace::Host>
99 hyperbolic_system_->template view<dim, Number, MemorySpace>(),
118 dealii::ObserverPointer<const HyperbolicSystem> hyperbolic_system_;
120 template <
int,
typename,
typename>
135 template <
int dim,
typename Number,
typename MemorySpace>
140 std::is_same_v<MemorySpace, dealii::MemorySpace::Host> ||
141 std::is_same_v<MemorySpace, dealii::MemorySpace::Default>,
142 "Unexpected memory space");
172 using Bounds = std::array<Number, n_bounds>;
180 , parameters_(limiter.parameters_.template view<MemorySpace>())
187 DEAL_II_HOST_DEVICE_ALWAYS_INLINE
unsigned int iterations()
const
189 return parameters_->iterations;
204 DEAL_II_HOST_DEVICE
Bounds
206 const unsigned int i,
215 const Bounds &bounds_left,
const Bounds &bounds_right)
const;
226 const Number &hd)
const;
253 const unsigned int i,
261 DEAL_II_HOST_DEVICE
void
263 const unsigned int *js,
266 const dealii::Tensor<1, dim, Number> &scaled_c_ij,
272 DEAL_II_HOST_DEVICE
Bounds bounds(
const Number hd_i)
const;
295 DEAL_II_HOST_DEVICE std::tuple<Number, bool>
299 const Number t_min = Number(0.),
300 const Number t_max = Number(1.))
const;
317 Number rho_relaxation_numerator_;
318 Number rho_relaxation_denominator_;
331 template <
int dim,
typename Number,
typename MemorySpace>
332 DEAL_II_HOST_DEVICE_ALWAYS_INLINE
auto
338 const auto rho_i = view_.density(U_i);
339 return { rho_i, rho_i};
343 template <
int dim,
typename Number,
typename MemorySpace>
344 DEAL_II_HOST_DEVICE_ALWAYS_INLINE
auto
348 const auto &[rho_min_l, rho_max_l] = bounds_left;
349 const auto &[rho_min_r, rho_max_r] = bounds_right;
351 return {std::min(rho_min_l, rho_min_r), std::max(rho_max_l, rho_max_r)};
355 template <
int dim,
typename Number,
typename MemorySpace>
356 DEAL_II_HOST_DEVICE_ALWAYS_INLINE
auto
360 auto relaxed_bounds = bounds;
361 auto &[rho_min_relaxed, rho_max_relaxed] = relaxed_bounds;
365 Number r = std::sqrt(hd);
366 if constexpr (dim == 2)
367 r = dealii::Utilities::fixed_power<3>(std::sqrt(r));
368 else if constexpr (dim == 1)
369 r = dealii::Utilities::fixed_power<3>(r);
370 r *= relaxation_factor();
372 constexpr ScalarNumber eps = std::numeric_limits<ScalarNumber>::epsilon();
373 rho_min_relaxed *= std::max(Number(1.) - r, Number(eps));
374 rho_max_relaxed *= (Number(1.) + r);
376 return relaxed_bounds;
380 template <
int dim,
typename Number,
typename MemorySpace>
381 DEAL_II_HOST_DEVICE_ALWAYS_INLINE
void
393 auto &[rho_min, rho_max] = bounds_;
395 rho_min = Number(std::numeric_limits<ScalarNumber>::max());
396 rho_max = Number(0.);
400 rho_relaxation_numerator_ = Number(0.);
401 rho_relaxation_denominator_ = Number(0.);
405 template <
int dim,
typename Number,
typename MemorySpace>
406 DEAL_II_HOST_DEVICE_ALWAYS_INLINE
void
409 const unsigned int * ,
412 const dealii::Tensor<1, dim, Number> &scaled_c_ij,
419 Assert(std::max(affine_shift.norm(), Number(0.)) == Number(0.),
420 dealii::ExcNotImplemented());
423 auto &[rho_min, rho_max] = bounds_;
425 const auto rho_i = view_.density(U_i_);
426 const auto rho_j = view_.density(U_j);
429 const auto U_ij_bar =
434 const auto rho_ij_bar = view_.density(U_ij_bar);
438 rho_min = std::min(rho_min, rho_ij_bar);
439 rho_max = std::max(rho_max, rho_ij_bar);
444 const auto beta_ij = Number(1.);
445 rho_relaxation_numerator_ += beta_ij * (rho_i + rho_j);
446 rho_relaxation_denominator_ += std::abs(beta_ij);
450 template <
int dim,
typename Number,
typename MemorySpace>
451 DEAL_II_HOST_DEVICE_ALWAYS_INLINE
auto
455 const auto &[rho_min, rho_max] = bounds_;
457 auto relaxed_bounds = fully_relax_bounds(bounds_, hd_i);
458 auto &[rho_min_relaxed, rho_max_relaxed] = relaxed_bounds;
462 constexpr ScalarNumber eps = std::numeric_limits<ScalarNumber>::epsilon();
464 const auto rho_relaxation =
466 std::abs(rho_relaxation_numerator_) /
467 (std::abs(rho_relaxation_denominator_) + Number(eps));
469 rho_min_relaxed = std::max(rho_min_relaxed, rho_min - rho_relaxation);
470 rho_max_relaxed = std::min(rho_max_relaxed, rho_max + rho_relaxation);
472 return relaxed_bounds;
476 template <
int dim,
typename Number,
typename MemorySpace>
477 DEAL_II_HOST_DEVICE_ALWAYS_INLINE std::tuple<Number, bool>
483 const Number t_max )
const
488 constexpr ScalarNumber eps = std::numeric_limits<ScalarNumber>::epsilon();
489 const auto large = view_.vacuum_state_relaxation_large();
497 const auto &rho_U = view_.density(U);
498 const auto &rho_P = view_.density(P);
500 const auto &rho_min = std::get<0>(bounds);
501 const auto &rho_max = std::get<1>(bounds);
507 const auto test_min = view_.filter_vacuum_density(
508 std::max(Number(0.), rho_U - relax * rho_max));
509 const auto test_max = view_.filter_vacuum_density(
510 std::max(Number(0.), rho_min - relax * rho_U));
511 if (!(test_min == Number(0.) && test_max == Number(0.))) {
513 std::cout << std::fixed << std::setprecision(16);
514 std::cout <<
"Bounds violation: low-order density (critical)!"
515 <<
"\n\t\trho min: " << rho_min
516 <<
"\n\t\trho min (delta): "
518 <<
"\n\t\trho: " << rho_U
519 <<
"\n\t\trho max (delta): "
521 <<
"\n\t\trho max: " << rho_max <<
"\n"
527 const Number denominator =
530 t_r = ryujin::compare_and_apply_mask<dealii::SIMDComparison::less_than>(
539 (rho_max - rho_U) * denominator,
542 t_r = ryujin::compare_and_apply_mask<dealii::SIMDComparison::less_than>(
551 (rho_U - rho_min) * denominator,
561 t_r = std::min(t_r, t_max);
562 t_r = std::max(t_r, t_min);
564#ifdef DEBUG_EXPENSIVE_BOUNDS_CHECK
568 const auto rho_new = view_.density(U + t_r * P);
569 const auto test_new_min = view_.filter_vacuum_density(
570 std::max(Number(0.), rho_new - relax * rho_max));
571 const auto test_new_max = view_.filter_vacuum_density(
572 std::max(Number(0.), rho_min - relax * rho_new));
573 if (!(test_new_min == Number(0.) && test_new_max == Number(0.))) {
575 std::cout << std::fixed << std::setprecision(16);
576 std::cout <<
"Bounds violation: high-order density!"
577 <<
"\n\t\trho min: " << rho_min
578 <<
"\n\t\trho min (delta): "
580 <<
"\n\t\trho: " << rho_new
581 <<
"\n\t\trho max (delta): "
583 <<
"\n\t\trho max: " << rho_max <<
"\n"
591 return {t_r, success};
VectorView< n_precomputed_values > PrecomputedVectorView
dealii::Tensor< 1, problem_dimension, Number > state_type
typename get_value_type< Number >::type ScalarNumber
flux_type flux_contribution_type
typename View::ScalarNumber ScalarNumber
static constexpr unsigned int n_bounds
DEAL_II_HOST_DEVICE 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
DEAL_II_HOST_DEVICE Bounds fully_relax_bounds(const Bounds &bounds, const Number &hd) const
typename View::PrecomputedVectorView PrecomputedVectorView
typename View::flux_contribution_type flux_contribution_type
typename View::state_type state_type
DEAL_II_HOST_DEVICE_ALWAYS_INLINE ScalarNumber relaxation_factor() const
HyperbolicSystemView< dim, Number, MemorySpace > View
DEAL_II_HOST_DEVICE 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)
DEAL_II_HOST_DEVICE_ALWAYS_INLINE unsigned int iterations() const
DEAL_II_HOST_DEVICE Bounds projection_bounds_from_state(const PrecomputedVectorView &pv, const unsigned int i, const state_type &U_i) const
DEAL_II_HOST_DEVICE Bounds bounds(const Number hd_i) const
LimiterView(const View &view, const Limiter< ScalarNumber > &limiter)
std::array< Number, n_bounds > Bounds
DEAL_II_HOST_DEVICE Bounds combine_bounds(const Bounds &bounds_left, const Bounds &bounds_right) const
DEAL_II_HOST_DEVICE void reset(const PrecomputedVectorView &pv, const unsigned int i, const state_type &U_i, const flux_contribution_type &flux_i)
Limiter(const HyperbolicSystem &hyperbolic_system, const std::string &subsection="/Limiter")
@ implicit_transfers_host_resident
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)
DEAL_II_HOST_DEVICE_ALWAYS_INLINE Number positive_part(const Number number)
DEAL_II_HOST_DEVICE_ALWAYS_INLINE Number negative_part(const Number number)