296 const dealii::Tensor<1, dim, Number> &n_ij)
const
299 const Number f_i = view_.construct_flux_tensor(prec_i) * n_ij;
300 const Number f_j = view_.construct_flux_tensor(prec_j) * n_ij;
301 const Number df_i = view_.construct_flux_gradient_tensor(prec_i) * n_ij;
302 const Number df_j = view_.construct_flux_gradient_tensor(prec_j) * n_ij;
304 const auto h2 = Number(2. * view_.derivative_approximation_delta());
306#ifdef DEBUG_WAVE_SPEED_ESTIMATOR
307 std::cout <<
"\nu_i = " << u_i << std::endl;
308 std::cout <<
"u_j = " << u_j << std::endl;
309 std::cout <<
"f_i = " << f_i << std::endl;
310 std::cout <<
"f_j = " << f_j << std::endl;
311 std::cout <<
"df_i = " << df_i << std::endl;
312 std::cout <<
"df_j = " << df_j << std::endl;
330 auto lambda_max = std::abs(f_i - f_j) / std::max(std::abs(u_i - u_j), h2);
331#ifdef DEBUG_WAVE_SPEED_ESTIMATOR
332 std::cout <<
" Roe average = " << lambda_max << std::endl;
335 constexpr auto gte = dealii::SIMDComparison::greater_than_or_equal;
337 if (use_greedy_wavespeed()) {
343 lambda_max = ryujin::compare_and_apply_mask<gte>(
349#ifdef DEBUG_WAVE_SPEED_ESTIMATOR
350 std::cout <<
" interpolated = "
351 << std::abs(
ScalarNumber(0.5) * (df_i + df_j)) << std::endl;
362 lambda_max = std::max(lambda_max, std::abs(df_i));
363 lambda_max = std::max(lambda_max, std::abs(df_j));
364#ifdef DEBUG_WAVE_SPEED_ESTIMATOR
365 std::cout <<
" left derivative = " << std::abs(df_i) << std::endl;
366 std::cout <<
" right derivative = " << std::abs(df_j) << std::endl;
376 if constexpr (std::is_same_v<MemorySpace, dealii::MemorySpace::Host>) {
381 thread_local static const auto draw = []() {
382 static std::random_device random_device;
383 static auto generator = std::default_random_engine(random_device());
384 static std::uniform_real_distribution<ScalarNumber> dist(0., 1.);
386 if constexpr (std::is_same_v<ScalarNumber, Number>) {
390 return dist(generator);
397 for (
unsigned int s = 0; s < Number::size(); ++s)
398 result[s] = dist(generator);
407 const auto enforce_entropy = [&](
const Number &k) {
408 const Number f_k = view_.flux_function(k) * n_ij;
410#ifdef DEBUG_WAVE_SPEED_ESTIMATOR
411 std::cout <<
"k = " << k << std::endl;
412 std::cout <<
"f_k = " << f_k << std::endl;
415 const Number eta_i = view_.kruzkov_entropy(k, u_i);
417 view_.kruzkov_entropy_derivative(k, u_i) * (f_i - f_k);
419 const Number eta_j = view_.kruzkov_entropy(k, u_j);
421 view_.kruzkov_entropy_derivative(k, u_j) * (f_j - f_k);
424 const Number b = f_j - f_i;
425 const Number c = eta_i + eta_j;
426 const Number d = q_j - q_i;
437 const Number lambda_left = std::abs(d + b) / (std::abs(c + a) + h2);
438 const Number lambda_right = std::abs(d - b) / (std::abs(c - a) + h2);
440#ifdef DEBUG_WAVE_SPEED_ESTIMATOR
441 std::cout <<
" left wavespeed = " << lambda_left << std::endl;
442 std::cout <<
" right wavespeed = " << lambda_right << std::endl;
444 lambda_max = std::max(lambda_max, lambda_left);
445 lambda_max = std::max(lambda_max, lambda_right);
449 if (use_averaged_entropy()) {
454 const unsigned int n_entropies = random_entropies();
455 for (
unsigned int i = 0; i < n_entropies; ++i) {
456 const Number factor = draw();
457 const Number k = factor * u_i + (Number(1.) - factor) * u_j;
462#ifdef DEBUG_WAVE_SPEED_ESTIMATOR
463 std::cout <<
"-> lambda_max = " << lambda_max << std::endl;