8#include <compile_time_options.h>
20 namespace ScalarConservation
22 template <
int dim,
typename Number>
28 const dealii::Tensor<1, dim, Number> &n_ij)
const
30 const auto &view = hyperbolic_system.view<dim, Number>();
33 const Number f_i = view.construct_flux_tensor(prec_i) * n_ij;
34 const Number f_j = view.construct_flux_tensor(prec_j) * n_ij;
35 const Number df_i = view.construct_flux_gradient_tensor(prec_i) * n_ij;
36 const Number df_j = view.construct_flux_gradient_tensor(prec_j) * n_ij;
38 const auto h2 = Number(2. * view.derivative_approximation_delta());
40#ifdef DEBUG_RIEMANN_SOLVER
41 std::cout <<
"\nu_i = " << u_i << std::endl;
42 std::cout <<
"u_j = " << u_j << std::endl;
43 std::cout <<
"f_i = " << f_i << std::endl;
44 std::cout <<
"f_j = " << f_j << std::endl;
45 std::cout <<
"df_i = " << df_i << std::endl;
46 std::cout <<
"df_j = " << df_j << std::endl;
64 auto lambda_max = std::abs(f_i - f_j) / std::max(std::abs(u_i - u_j), h2);
65#ifdef DEBUG_RIEMANN_SOLVER
66 std::cout <<
" Roe average = " << lambda_max << std::endl;
69 constexpr auto gte = dealii::SIMDComparison::greater_than_or_equal;
71 if (parameters.use_greedy_wavespeed()) {
77 lambda_max = dealii::compare_and_apply_mask<gte>(
83#ifdef DEBUG_RIEMANN_SOLVER
84 std::cout <<
" interpolated = "
85 << std::abs(
ScalarNumber(0.5) * (df_i + df_j)) << std::endl;
96 lambda_max = std::max(lambda_max, std::abs(df_i));
97 lambda_max = std::max(lambda_max, std::abs(df_j));
98#ifdef DEBUG_RIEMANN_SOLVER
99 std::cout <<
" left derivative = " << std::abs(df_i) << std::endl;
100 std::cout <<
" right derivative = " << std::abs(df_j) << std::endl;
108 thread_local static const auto draw = []() {
109 static std::random_device random_device;
110 static auto generator = std::default_random_engine(random_device());
111 static std::uniform_real_distribution<ScalarNumber> dist(0., 1.);
113 if constexpr (std::is_same_v<ScalarNumber, Number>) {
117 return dist(generator);
124 for (
unsigned int s = 0; s < Number::size(); ++s)
125 result[s] = dist(generator);
134 const auto enforce_entropy = [&](
const Number &k) {
135 const Number f_k = view.flux_function(k) * n_ij;
137#ifdef DEBUG_RIEMANN_SOLVER
138 std::cout <<
"k = " << k << std::endl;
139 std::cout <<
"f_k = " << f_k << std::endl;
142 const Number eta_i = view.kruzkov_entropy(k, u_i);
144 view.kruzkov_entropy_derivative(k, u_i) * (f_i - f_k);
146 const Number eta_j = view.kruzkov_entropy(k, u_j);
148 view.kruzkov_entropy_derivative(k, u_j) * (f_j - f_k);
151 const Number b = f_j - f_i;
152 const Number c = eta_i + eta_j;
153 const Number d = q_j - q_i;
164 const Number lambda_left = std::abs(d + b) / (std::abs(c + a) + h2);
165 const Number lambda_right = std::abs(d - b) / (std::abs(c - a) + h2);
167#ifdef DEBUG_RIEMANN_SOLVER
168 std::cout <<
" left wavespeed = " << lambda_left << std::endl;
169 std::cout <<
" right wavespeed = " << lambda_right << std::endl;
171 lambda_max = std::max(lambda_max, lambda_left);
172 lambda_max = std::max(lambda_max, lambda_right);
176 if (parameters.use_averaged_entropy()) {
177 const Number k = ScalarNumber(0.5) * (u_i + u_j);
181 const unsigned int n_entropies = parameters.random_entropies();
182 for (
unsigned int i = 0; i < n_entropies; ++i) {
183 const Number factor = draw();
184 const Number k = factor * u_i + (Number(1.) - factor) * u_j;
188#ifdef DEBUG_RIEMANN_SOLVER
189 std::cout <<
"-> lambda_max = " << lambda_max << std::endl;
195 template <
int dim,
typename Number>
199 const unsigned int i,
200 const unsigned int *js,
201 const dealii::Tensor<1, dim, Number> &n_ij)
const
203 const auto view = hyperbolic_system.view<dim, Number>();
207 const auto u_i = view.state(U_i);
208 const auto u_j = view.state(U_j);
210 const auto &pv = precomputed_values;
211 const auto prec_i = pv.template get_tensor<Number, pst>(i);
212 const auto prec_j = pv.template get_tensor<Number, pst>(js);
214 return compute(u_i, u_j, prec_i, prec_j, n_ij);
std::array< Number, n_precomputed_values > precomputed_type
typename View::state_type state_type
typename View::ScalarNumber ScalarNumber
Number compute(const Number &u_i, const Number &u_j, const precomputed_type &prec_i, const precomputed_type &prec_j, const dealii::Tensor< 1, dim, Number > &n_ij) const
typename View::precomputed_type precomputed_type