28 const dealii::Tensor<1, dim, Number> &n_ij)
const
31 const Number f_i = view_.construct_flux_tensor(prec_i) * n_ij;
32 const Number f_j = view_.construct_flux_tensor(prec_j) * n_ij;
33 const Number df_i = view_.construct_flux_gradient_tensor(prec_i) * n_ij;
34 const Number df_j = view_.construct_flux_gradient_tensor(prec_j) * n_ij;
36 const auto h2 = Number(2. * view_.derivative_approximation_delta());
38#ifdef DEBUG_WAVE_SPEED_ESTIMATOR
39 std::cout <<
"\nu_i = " << u_i << std::endl;
40 std::cout <<
"u_j = " << u_j << std::endl;
41 std::cout <<
"f_i = " << f_i << std::endl;
42 std::cout <<
"f_j = " << f_j << std::endl;
43 std::cout <<
"df_i = " << df_i << std::endl;
44 std::cout <<
"df_j = " << df_j << std::endl;
62 auto lambda_max = std::abs(f_i - f_j) / std::max(std::abs(u_i - u_j), h2);
63#ifdef DEBUG_WAVE_SPEED_ESTIMATOR
64 std::cout <<
" Roe average = " << lambda_max << std::endl;
67 constexpr auto gte = dealii::SIMDComparison::greater_than_or_equal;
69 if (wave_speed_estimator_.use_greedy_wavespeed()) {
75 lambda_max = dealii::compare_and_apply_mask<gte>(
81#ifdef DEBUG_WAVE_SPEED_ESTIMATOR
82 std::cout <<
" interpolated = "
83 << std::abs(
ScalarNumber(0.5) * (df_i + df_j)) << std::endl;
94 lambda_max = std::max(lambda_max, std::abs(df_i));
95 lambda_max = std::max(lambda_max, std::abs(df_j));
96#ifdef DEBUG_WAVE_SPEED_ESTIMATOR
97 std::cout <<
" left derivative = " << std::abs(df_i) << std::endl;
98 std::cout <<
" right derivative = " << std::abs(df_j) << std::endl;
106 thread_local static const auto draw = []() {
107 static std::random_device random_device;
108 static auto generator = std::default_random_engine(random_device());
109 static std::uniform_real_distribution<ScalarNumber> dist(0., 1.);
111 if constexpr (std::is_same_v<ScalarNumber, Number>) {
115 return dist(generator);
122 for (
unsigned int s = 0; s < Number::size(); ++s)
123 result[s] = dist(generator);
132 const auto enforce_entropy = [&](
const Number &k) {
133 const Number f_k = view_.flux_function(k) * n_ij;
135#ifdef DEBUG_WAVE_SPEED_ESTIMATOR
136 std::cout <<
"k = " << k << std::endl;
137 std::cout <<
"f_k = " << f_k << std::endl;
140 const Number eta_i = view_.kruzkov_entropy(k, u_i);
142 view_.kruzkov_entropy_derivative(k, u_i) * (f_i - f_k);
144 const Number eta_j = view_.kruzkov_entropy(k, u_j);
146 view_.kruzkov_entropy_derivative(k, u_j) * (f_j - f_k);
149 const Number b = f_j - f_i;
150 const Number c = eta_i + eta_j;
151 const Number d = q_j - q_i;
162 const Number lambda_left = std::abs(d + b) / (std::abs(c + a) + h2);
163 const Number lambda_right = std::abs(d - b) / (std::abs(c - a) + h2);
165#ifdef DEBUG_WAVE_SPEED_ESTIMATOR
166 std::cout <<
" left wavespeed = " << lambda_left << std::endl;
167 std::cout <<
" right wavespeed = " << lambda_right << std::endl;
169 lambda_max = std::max(lambda_max, lambda_left);
170 lambda_max = std::max(lambda_max, lambda_right);
174 if (wave_speed_estimator_.use_averaged_entropy()) {
179 const unsigned int n_entropies = wave_speed_estimator_.random_entropies();
180 for (
unsigned int i = 0; i < n_entropies; ++i) {
181 const Number factor = draw();
182 const Number k = factor * u_i + (Number(1.) - factor) * u_j;
186#ifdef DEBUG_WAVE_SPEED_ESTIMATOR
187 std::cout <<
"-> lambda_max = " << lambda_max << std::endl;