/home/runner/work/DiFfRG_current/DiFfRG_current/DiFfRG/include/DiFfRG/discretization/FV/limiter/minmod_limiter.hh Source File#

DiFfRG: /home/runner/work/DiFfRG_current/DiFfRG_current/DiFfRG/include/DiFfRG/discretization/FV/limiter/minmod_limiter.hh Source File
DiFfRG
Discretization Framework for functional Renormalization Group flows
minmod_limiter.hh
Go to the documentation of this file.
1#pragma once
2
3// DiFfRG
5
6// standard library
7#include <algorithm>
8#include <cmath>
9#include <cstddef>
10
11// autodiff
12#include <autodiff/forward/real/real.hpp>
13
14namespace DiFfRG
15{
16 namespace def
17 {
36 {
37 template <typename NumberType> static NumberType abs_with_zero_tie_derivative(const NumberType &value)
38 {
39 using std::abs;
40 return abs(value);
41 }
42
43 template <size_t order, typename NumberType>
44 static autodiff::Real<order, NumberType>
45 abs_with_zero_tie_derivative(const autodiff::Real<order, NumberType> &value)
46 {
47 using std::abs;
48 if (std::abs(value.val()) < 1.0e-8) return autodiff::Real<order, NumberType>(0.0);
49 return abs(value);
50 }
51
52 public:
53 template <typename NumberType> static NumberType slope_limit(const NumberType &du_1, const NumberType &du_2)
54 {
55 // Use the algebraic identity min(a,b) = 0.5*(a+b-|a-b|) instead of std::min so that
56 // AD follows the active branch away from ties without introducing a std::min discontinuity.
57 using std::abs;
58 const auto a1 = abs(du_1), a2 = abs(du_2);
59 const auto min_a = NumberType(0.5) * (a1 + a2 - abs_with_zero_tie_derivative(a1 - a2));
60 return NumberType(0.5) * (limiter_utils::sgn(du_1) + limiter_utils::sgn(du_2)) * min_a;
61 }
62 };
63 static_assert(HasSlopeLimiter<MinModLimiter>);
64
65 } // namespace def
66} // namespace DiFfRG
MinMod slope limiter.
Definition minmod_limiter.hh:36
static NumberType abs_with_zero_tie_derivative(const NumberType &value)
Definition minmod_limiter.hh:37
static autodiff::Real< order, NumberType > abs_with_zero_tie_derivative(const autodiff::Real< order, NumberType > &value)
Definition minmod_limiter.hh:45
static NumberType slope_limit(const NumberType &du_1, const NumberType &du_2)
Definition minmod_limiter.hh:53
int sgn(T val)
Signum helper: returns -1, 0 or +1.
Definition abstract_limiter.hh:43
Definition complex_math.hh:10