10#include <compile_time_options.h>
21 namespace ShallowWater
23 using namespace dealii;
25 template <
int dim,
typename Number>
26 DEAL_II_ALWAYS_INLINE
inline Number
28 const Number &h)
const
30 const auto view = hyperbolic_system.view<dim, Number>();
33 const auto &[h_Z, u_Z, a_Z] = riemann_data_Z;
35 const auto left_value =
ScalarNumber(2.) * (std::sqrt(gravity * h) - a_Z);
37 const Number radicand =
39 const Number right_value = (h - h_Z) * std::sqrt(radicand);
41 return dealii::compare_and_apply_mask<
42 dealii::SIMDComparison::less_than_or_equal>(
43 h, h_Z, left_value, right_value);
47 template <
int dim,
typename Number>
48 DEAL_II_ALWAYS_INLINE
inline Number
51 const Number &h)
const
53 const Number &u_i = riemann_data_i[1];
54 const Number &u_j = riemann_data_j[1];
56#ifdef DEBUG_RIEMANN_SOLVER
57 std::cout <<
"f_L --> " << f(riemann_data_i, h) << std::endl;
58 std::cout <<
"f_R --> " << f(riemann_data_j, h) << std::endl;
60 return f(riemann_data_i, h) + f(riemann_data_j, h) + u_j - u_i;
64 template <
int dim,
typename Number>
65 DEAL_II_ALWAYS_INLINE
inline Number
69 const auto &[h, u, a] = riemann_data;
74 return u - a * std::sqrt((
ScalarNumber(1.) + half_factor) *
79 template <
int dim,
typename Number>
80 DEAL_II_ALWAYS_INLINE
inline Number
82 const Number h_star)
const
84 const auto &[h, u, a] = riemann_data;
89 return u + a * std::sqrt((
ScalarNumber(1.) + half_factor) *
94 template <
int dim,
typename Number>
95 DEAL_II_ALWAYS_INLINE
inline Number
99 const Number h_star)
const
101 const Number lambda1 = lambda1_minus(riemann_data_i, h_star);
102 const Number lambda3 = lambda3_plus(riemann_data_j, h_star);
108 template <
int dim,
typename Number>
109 DEAL_II_ALWAYS_INLINE
inline Number
114 const auto view = hyperbolic_system.view<dim, Number>();
116 const auto gravity_inverse =
ScalarNumber(1.) / gravity;
118 const auto &[h_i, u_i, a_i] = riemann_data_i;
119 const auto &[h_j, u_j, a_j] = riemann_data_j;
121 const Number h_min = std::min(h_i, h_j);
122 const Number h_max = std::max(h_i, h_j);
124#ifdef DEBUG_RIEMANN_SOLVER
125 std::cout << h_min <<
" <- h_min/max -> " << h_max << std::endl;
128 const Number a_min = std::sqrt(gravity * h_min);
129 const Number a_max = std::sqrt(gravity * h_max);
131#ifdef DEBUG_RIEMANN_SOLVER
132 std::cout << a_min <<
" <- a_min/max -> " << a_max << std::endl;
138 const Number x0 = Number(9.) -
ScalarNumber(4.) * sqrt_two;
140 const Number phi_value_min =
141 phi(riemann_data_i, riemann_data_j, x0 * h_min);
142#ifdef DEBUG_RIEMANN_SOLVER
143 std::cout <<
"phi_value_min ->" << phi_value_min << std::endl;
146 const Number phi_value_max =
147 phi(riemann_data_i, riemann_data_j, x0 * h_max);
148#ifdef DEBUG_RIEMANN_SOLVER
149 std::cout <<
"phi_value_max ->" << phi_value_max << std::endl;
159 const Number h_star_left =
162#ifdef DEBUG_RIEMANN_SOLVER
163 std::cout <<
"left: " << h_star_left << std::endl;
168 tmp = Number(1.) + sqrt_two * (u_i - u_j) / (a_min + a_max);
169 const Number h_star_middle = std::sqrt(h_min * h_max) * tmp;
171#ifdef DEBUG_RIEMANN_SOLVER
172 std::cout <<
"middle: " << h_star_middle << std::endl;
177 const auto left_radicand =
181 const auto right_radicand =
182 sqrt_two * std::sqrt(gravity_inverse * h_min) * (u_i - u_j);
184 tmp = std::sqrt(
positive_part(left_radicand + right_radicand));
185 tmp -= sqrt_two * std::sqrt(h_min);
187 const Number h_star_right = tmp * tmp;
189#ifdef DEBUG_RIEMANN_SOLVER
190 std::cout <<
"right: " << h_star_right << std::endl;
195 Number h_star = dealii::compare_and_apply_mask<
196 dealii::SIMDComparison::less_than_or_equal>(
197 Number(0.), phi_value_min, h_star_left, h_star_right);
200 dealii::compare_and_apply_mask<dealii::SIMDComparison::less_than>(
201 phi_value_max, Number(0.), h_star_middle, h_star_right);
207 template <
int dim,
typename Number>
208 DEAL_II_ALWAYS_INLINE
inline auto
210 const state_type &U,
const dealii::Tensor<1, dim, Number> &n_ij)
const
213 const auto view = hyperbolic_system.view<dim, Number>();
215 const Number h = view.water_depth_sharp(U);
216 const Number gravity = view.gravity();
218 const auto velocity = view.momentum(U) / h;
219 const auto projected_velocity = n_ij * velocity;
220 const auto a = std::sqrt(h * gravity);
222 return {{h, projected_velocity, a}};
226 template <
int dim,
typename Number>
231 const Number h_star = compute_h_star(riemann_data_i, riemann_data_j);
233 const Number lambda_max =
234 compute_lambda(riemann_data_i, riemann_data_j, h_star);
240 template <
int dim,
typename Number>
245 const unsigned int * ,
246 const dealii::Tensor<1, dim, Number> &n_ij)
const
248 const auto riemann_data_i = riemann_data_from_state(U_i, n_ij);
249 const auto riemann_data_j = riemann_data_from_state(U_j, n_ij);
250 return compute(riemann_data_i, riemann_data_j);
Number phi(const primitive_type &riemann_data_i, const primitive_type &riemann_data_j, const Number &h) const
primitive_type riemann_data_from_state(const state_type &U, const dealii::Tensor< 1, dim, Number > &n_ij) const
typename std::array< Number, riemann_data_size > primitive_type
typename View::ScalarNumber ScalarNumber
Number lambda3_plus(const primitive_type &riemann_data, const Number h_star) const
Number lambda1_minus(const primitive_type &riemann_data, const Number h_star) const
Number compute_lambda(const primitive_type &riemann_data_i, const primitive_type &riemann_data_j, const Number h_star) const
Number compute_h_star(const primitive_type &riemann_data_i, const primitive_type &riemann_data_j) const
typename View::state_type state_type
Number compute(const primitive_type &riemann_data_i, const primitive_type &riemann_data_j) const
Number f(const primitive_type &primitive_state, const Number &h_star) const
DEAL_II_ALWAYS_INLINE Number negative_part(const Number number)
DEAL_II_ALWAYS_INLINE Number positive_part(const Number number)