11#include <deal.II/base/config.h>
19#include <deal.II/base/parameter_acceptor.h>
20#include <deal.II/base/tensor.h>
26 namespace ShallowWater
28 template <
int dim,
typename Number>
29 class HyperbolicSystemView;
46 static inline const std::string
problem_name =
"Shallow water equations";
59 template <
int dim,
typename Number>
71 double manning_friction_coefficient_;
73 double reference_water_depth_;
74 double dry_state_relaxation_small_;
75 double dry_state_relaxation_large_;
77 template <
int dim,
typename Number>
99 template <
int dim,
typename Number>
108 : hyperbolic_system_(hyperbolic_system)
115 template <
int dim2,
typename Number2>
133 return hyperbolic_system_.gravity_;
139 return hyperbolic_system_.manning_friction_coefficient_;
144 return hyperbolic_system_.reference_water_depth_;
150 return hyperbolic_system_.dry_state_relaxation_small_;
156 return hyperbolic_system_.dry_state_relaxation_large_;
183 using state_type = dealii::Tensor<1, problem_dimension, Number>;
189 dealii::Tensor<1, problem_dimension, dealii::Tensor<1, dim, Number>>;
201 []() -> std::array<std::string, problem_dimension> {
202 if constexpr (dim == 1)
204 else if constexpr (dim == 2)
205 return {
"h",
"m_1",
"m_2"};
206 else if constexpr (dim == 3)
207 return {
"h",
"m_1",
"m_2",
"m_3"};
216 []() -> std::array<std::string, problem_dimension> {
217 if constexpr (dim == 1)
219 else if constexpr (dim == 2)
220 return {
"h",
"v_1",
"v_2"};
221 else if constexpr (dim == 3)
222 return {
"h",
"v_1",
"v_2",
"v_3"};
240 std::array<std::string, n_precomputed_values>{
"eta_m",
"h_star"};
251 std::array<Number, n_initial_precomputed_values>;
257 std::array<std::string, n_initial_precomputed_values>{
"bathymetry"};
263 StateVector<ScalarNumber, problem_dimension, n_precomputed_values>;
300 template <
typename DISPATCH,
typename SPARSITY>
302 const DISPATCH &dispatch_check,
303 const SPARSITY &sparsity_simd,
306 unsigned int right)
const;
415 template <
int component>
419 const dealii::Tensor<1, dim, Number> &normal)
const;
424 template <
typename Lambda>
428 const dealii::Tensor<1, dim, Number> &normal,
429 const Lambda &get_dirichlet_data)
const;
465 const Number &Z_left,
466 const Number &Z_right)
const;
473 std::array<state_type, 2>
500 const unsigned int i,
506 const unsigned int *js,
517 const dealii::Tensor<1, dim, Number> &c_ij)
const;
532 const dealii::Tensor<1, dim, Number> &c_ij)
const;
541 const dealii::Tensor<1, dim, Number> &c_ij,
542 const Number &d_ij)
const;
559 const Number &h_star,
563 const unsigned int i,
568 const unsigned int *js,
589 template <
typename ST>
603 template <
typename ST>
622 template <
typename Lambda>
624 const Lambda &lambda)
const;
637 : ParameterAcceptor(subsection)
640 add_parameter(
"gravity", gravity_,
"Gravitational constant [m/s^2]");
642 manning_friction_coefficient_ = 0.;
643 add_parameter(
"manning friction coefficient",
644 manning_friction_coefficient_,
645 "Roughness coefficient for friction source");
647 reference_water_depth_ = 1.;
648 add_parameter(
"reference water depth",
649 reference_water_depth_,
650 "Problem specific water depth reference");
652 dry_state_relaxation_small_ = 1.e2;
653 add_parameter(
"dry state relaxation small",
654 dry_state_relaxation_small_,
655 "Problem specific dry-state relaxation parameter");
657 dry_state_relaxation_large_ = 1.e4;
658 add_parameter(
"dry state relaxation large",
659 dry_state_relaxation_large_,
660 "Problem specific dry-state relaxation parameter");
664 template <
int dim,
typename Number>
665 template <
typename DISPATCH,
typename SPARSITY>
666 DEAL_II_ALWAYS_INLINE
inline void
668 unsigned int cycle [[maybe_unused]],
669 const DISPATCH &dispatch_check,
670 const SPARSITY &sparsity_simd,
673 unsigned int right)
const
675 Assert(cycle == 0, dealii::ExcInternalError());
677 const auto &U = std::get<0>(state_vector);
678 auto &precomputed = std::get<1>(state_vector);
682 unsigned int stride_size = get_stride_size<Number>;
685 for (
unsigned int i = left; i < right; i += stride_size) {
688 const unsigned int row_length = sparsity_simd.row_length(i);
694 const auto U_i = U.template get_tensor<Number>(i);
696 const auto eta_m = mathematical_entropy(U_i);
698 const auto h_sharp = water_depth_sharp(U_i);
702 precomputed.template write_tensor<Number>(prec_i, i);
707 template <
int dim,
typename Number>
708 DEAL_II_ALWAYS_INLINE
inline Number
715 template <
int dim,
typename Number>
716 DEAL_II_ALWAYS_INLINE
inline Number
720 constexpr ScalarNumber eps = std::numeric_limits<ScalarNumber>::epsilon();
722 const Number h_cutoff_mollified =
723 reference_water_depth() * dry_state_relaxation_large() * Number(eps);
725 const Number h = water_depth(U);
727 const Number h_max = std::max(h, h_cutoff_mollified);
728 const Number denom = h * h + h_max * h_max;
733 template <
int dim,
typename Number>
734 DEAL_II_ALWAYS_INLINE
inline Number
738 constexpr ScalarNumber eps = std::numeric_limits<ScalarNumber>::epsilon();
740 const Number h_cutoff_small =
741 reference_water_depth() * dry_state_relaxation_small() * Number(eps);
743 const Number h = water_depth(U);
744 const Number h_max = std::max(h, h_cutoff_small);
749 template <
int dim,
typename Number>
750 DEAL_II_ALWAYS_INLINE
inline Number
758 template <
int dim,
typename Number>
759 DEAL_II_ALWAYS_INLINE
inline Number
761 const Number &h)
const
764 constexpr ScalarNumber eps = std::numeric_limits<ScalarNumber>::epsilon();
766 const Number h_cutoff_large =
767 reference_water_depth() * dry_state_relaxation_large() * Number(eps);
769 return dealii::compare_and_apply_mask<dealii::SIMDComparison::less_than>(
770 std::abs(h), h_cutoff_large, Number(0.), h);
774 template <
int dim,
typename Number>
775 DEAL_II_ALWAYS_INLINE
inline dealii::Tensor<1, dim, Number>
778 dealii::Tensor<1, dim, Number> result;
780 for (
unsigned int i = 0; i < dim; ++i)
781 result[i] = U[1 + i];
786 template <
int dim,
typename Number>
787 DEAL_II_ALWAYS_INLINE
inline Number
790 const auto h = water_depth(U);
791 const auto vel = momentum(U) * inverse_water_depth_sharp(U);
798 template <
int dim,
typename Number>
799 DEAL_II_ALWAYS_INLINE
inline Number
802 const Number h_sqd = U[0] * U[0];
809 template <
int dim,
typename Number>
810 DEAL_II_ALWAYS_INLINE
inline Number
814 return std::sqrt(gravity() * U[0]);
818 template <
int dim,
typename Number>
819 DEAL_II_ALWAYS_INLINE
inline Number
823 const auto p = pressure(U);
824 const auto k_e = kinetic_energy(U);
829 template <
int dim,
typename Number>
830 DEAL_II_ALWAYS_INLINE
inline auto
847 const Number &h = U[0];
848 const auto vel = momentum(U) * inverse_water_depth_sharp(U);
851 result[0] = gravity() * h -
ScalarNumber(0.5) * vel.norm_square();
854 for (
unsigned int i = 0; i < dim; ++i) {
855 result[1 + i] = vel[i];
862 template <
int dim,
typename Number>
863 DEAL_II_ALWAYS_INLINE
inline bool
866 const auto h = filter_dry_water_depth(water_depth(U));
868 constexpr auto gte = dealii::SIMDComparison::greater_than_or_equal;
869 const auto test = dealii::compare_and_apply_mask<gte>(
870 h, Number(0.), Number(0.), Number(-1.));
873 if (!(test == Number(0.))) {
874 std::cout << std::fixed << std::setprecision(16);
875 std::cout <<
"Bounds violation: Negative state [h] detected!\n";
876 std::cout <<
"\t\th: " << h <<
"\n" << std::endl;
881 return (test == Number(0.));
885 template <
int dim,
typename Number>
886 template <
int component>
887 DEAL_II_ALWAYS_INLINE
inline auto
891 const dealii::Tensor<1, dim, Number> &normal)
const ->
state_type
894 static_assert(component == 1 || component == 2,
895 "component has to be 1 or 2");
899 const auto m = momentum(U);
900 const auto a = speed_of_sound(U);
901 const auto vn = m * normal * inverse_water_depth_sharp(U);
903 const auto m_bar = momentum(U_bar);
904 const auto a_bar = speed_of_sound(U_bar);
905 const auto vn_bar = m_bar * normal * inverse_water_depth_sharp(U_bar);
909 const auto R_1 = component == 1 ? vn_bar -
ScalarNumber(2.) * a_bar
914 const auto R_2 = component == 2 ? vn_bar +
ScalarNumber(2.) * a_bar
917 const auto vperp = m * inverse_water_depth_sharp(U) - vn * normal;
922 ryujin::fixed_power<2>((R_2 - R_1) /
ScalarNumber(4.)) / gravity();
926 for (
unsigned int d = 0; d < dim; ++d) {
927 U_new[1 + d] = h_new * (vn_new * normal + vperp)[d];
934 template <
int dim,
typename Number>
935 template <
typename Lambda>
936 DEAL_II_ALWAYS_INLINE
inline auto
938 const dealii::types::boundary_id
id,
940 const dealii::Tensor<1, dim, Number> &normal,
941 const Lambda &get_dirichlet_data)
const ->
state_type
946 result = get_dirichlet_data();
950 auto m_dirichlet = momentum(get_dirichlet_data());
951 for (
unsigned int k = 0; k < dim; ++k)
952 result[k + 1] = m_dirichlet[k];
955 auto m = momentum(U);
956 m -= 1. * (m * normal) * normal;
957 for (
unsigned int k = 0; k < dim; ++k)
958 result[k + 1] = m[k];
961 for (
unsigned int k = 0; k < dim; ++k)
962 result[k + 1] = Number(0.);
977 const auto m = momentum(U);
978 const auto h_inverse = inverse_water_depth_sharp(U);
979 const auto a = speed_of_sound(U);
980 const auto vn = m * normal * h_inverse;
984 result = get_dirichlet_data();
988 if (vn >= -a && vn <= 0.) {
989 const auto U_dirichlet = get_dirichlet_data();
990 result = prescribe_riemann_characteristic<2>(U_dirichlet, U, normal);
994 if (vn > 0. && vn <= a) {
995 const auto U_dirichlet = get_dirichlet_data();
996 result = prescribe_riemann_characteristic<1>(U, U_dirichlet, normal);
1002 AssertThrow(
false, dealii::ExcNotImplemented());
1009 template <
int dim,
typename Number>
1010 DEAL_II_ALWAYS_INLINE
inline auto
1013 const auto h_inverse = inverse_water_depth_sharp(U);
1014 const auto m = momentum(U);
1015 const auto p = pressure(U);
1019 result[0] = (m * h_inverse) * U[0];
1020 for (
unsigned int i = 0; i < dim; ++i) {
1021 result[1 + i] = (m * h_inverse) * m[i];
1022 result[1 + i][i] += p;
1028 template <
int dim,
typename Number>
1029 DEAL_II_ALWAYS_INLINE
inline auto
1032 const auto h_inverse = inverse_water_depth_sharp(U);
1033 const auto m = momentum(U);
1037 result[0] = (m * h_inverse) * U[0];
1038 for (
unsigned int i = 0; i < dim; ++i) {
1039 result[1 + i] = (m * h_inverse) * m[i];
1045 template <
int dim,
typename Number>
1046 DEAL_II_ALWAYS_INLINE
inline auto
1048 const Number &Z_left,
1049 const Number &Z_right)
const
1052 const Number Z_max = std::max(Z_left, Z_right);
1053 const Number h = water_depth(U);
1054 const Number H_star = std::max(Number(0.), h + Z_left - Z_max);
1056 return U * H_star * inverse_water_depth_mollified(U);
1060 template <
int dim,
typename Number>
1061 DEAL_II_ALWAYS_INLINE
inline auto
1066 const auto &[U_i, Z_i] = flux_i;
1067 const auto &[U_j, Z_j] = flux_j;
1069 const auto U_star_ij = star_state(U_i, Z_i, Z_j);
1070 const auto U_star_ji = star_state(U_j, Z_j, Z_i);
1072 return {U_star_ij, U_star_ji};
1076 template <
int dim,
typename Number>
1077 DEAL_II_ALWAYS_INLINE
inline auto
1081 const unsigned int i,
1084 const auto Z_i = piv.template get_tensor<Number>(i)[0];
1089 template <
int dim,
typename Number>
1090 DEAL_II_ALWAYS_INLINE
inline auto
1094 const unsigned int *js,
1097 const auto Z_j = piv.template get_tensor<Number>(js)[0];
1102 template <
int dim,
typename Number>
1103 DEAL_II_ALWAYS_INLINE
inline auto
1107 const dealii::Tensor<1, dim, Number> &c_ij)
const ->
state_type
1109 const auto &[U_i, Z_i] = flux_i;
1110 const auto &[U_star_ij, U_star_ji] = equilibrated_states(flux_i, flux_j);
1112 const auto H_i = water_depth(U_i);
1113 const auto H_star_ij = water_depth(U_star_ij);
1114 const auto H_star_ji = water_depth(U_star_ji);
1116 const auto g_i = g(U_star_ij);
1117 const auto g_j = g(U_star_ji);
1119 auto result = -
add(g_i, g_j);
1122 (
ScalarNumber(0.5) * (H_star_ji * H_star_ji - H_star_ij * H_star_ij) +
1126 for (
unsigned int i = 0; i < dim; ++i) {
1127 result[1 + i][i] -= factor;
1134 template <
int dim,
typename Number>
1135 DEAL_II_ALWAYS_INLINE
inline auto
1139 const dealii::Tensor<1, dim, Number> &c_ij)
const ->
state_type
1141 const auto &[U_i, Z_i] = flux_i;
1142 const auto &[U_j, Z_j] = flux_j;
1144 const auto H_i = water_depth(U_i);
1145 const auto H_j = water_depth(U_j);
1147 const auto g_i = g(U_i);
1148 const auto g_j = g(U_j);
1150 auto result = -
add(g_i, g_j);
1152 const auto factor = gravity() * H_i * (H_j + Z_j - Z_i);
1153 for (
unsigned int i = 0; i < dim; ++i) {
1154 result[1 + i][i] -= factor;
1161 template <
int dim,
typename Number>
1162 DEAL_II_ALWAYS_INLINE
inline auto
1166 const dealii::Tensor<1, dim, Number> &c_ij,
1169 const auto &[U_i, Z_i] = flux_i;
1170 const auto &[U_j, Z_j] = flux_j;
1171 const auto U_star_ij = star_state(U_i, Z_i, Z_j);
1173 const auto h_inverse = inverse_water_depth_sharp(U_i);
1174 const auto m = momentum(U_i);
1175 const auto factor =
ScalarNumber(2.) * (d_ij + h_inverse * (m * c_ij));
1177 return -factor * (U_star_ij - U_i);
1181 template <
int dim,
typename Number>
1182 DEAL_II_ALWAYS_INLINE
inline auto
1189 const auto g = gravity();
1190 const auto n = manning_friction_coefficient();
1192 const auto h_inverse = inverse_water_depth_mollified(U);
1194 const auto m = momentum(U);
1195 const auto v_norm = (m * h_inverse).norm();
1196 const auto factor =
ScalarNumber(2.) * g * n * n * v_norm;
1198 const auto denominator = h_star + std::max(h_star, tau * factor);
1199 const auto denominator_inverse =
ScalarNumber(1.) / denominator;
1201 for (
unsigned int d = 0; d < dim; ++d)
1202 result[d + 1] = -factor * denominator_inverse * m[d];
1208 template <
int dim,
typename Number>
1209 DEAL_II_ALWAYS_INLINE
inline auto
1212 const unsigned int i,
1216 const auto &[eta_m, h_star] =
1217 pv.template get_tensor<Number, precomputed_type>(i);
1219 return manning_friction(U_i, h_star, tau);
1223 template <
int dim,
typename Number>
1224 DEAL_II_ALWAYS_INLINE
inline auto
1227 const unsigned int *js,
1231 const auto &[eta_m, h_star] =
1232 pv.template get_tensor<Number, precomputed_type>(js);
1234 return manning_friction(U_j, h_star, tau);
1238 template <
int dim,
typename Number>
1239 template <
typename ST>
1240 DEAL_II_ALWAYS_INLINE
inline auto
1244 using T =
typename ST::value_type;
1245 static_assert(std::is_same_v<Number, T>,
"template mismatch");
1247 constexpr auto dim2 = ST::dimension - 1;
1248 static_assert(dim >= dim2,
1249 "the space dimension of the argument state must not be "
1250 "larger than the one of the target state");
1253 result[0] = state[0];
1254 for (
unsigned int i = 1; i < dim2 + 1; ++i)
1255 result[i] = state[i];
1260 template <
int dim,
typename Number>
1261 template <
typename ST>
1262 DEAL_II_ALWAYS_INLINE
inline auto
1266 const auto primitive_state = expand_state(initial_state);
1267 return from_primitive_state(primitive_state);
1271 template <
int dim,
typename Number>
1272 DEAL_II_ALWAYS_INLINE
inline auto
1276 const auto &h = primitive_state[0];
1278 auto state = primitive_state;
1280 for (
unsigned int i = 1; i < dim + 1; ++i)
1287 template <
int dim,
typename Number>
1288 DEAL_II_ALWAYS_INLINE
inline auto
1292 const auto h_inverse = inverse_water_depth_sharp(state);
1294 auto primitive_state = state;
1296 for (
unsigned int i = 1; i < dim + 1; ++i)
1297 primitive_state[i] *= h_inverse;
1299 return primitive_state;
1303 template <
int dim,
typename Number>
1304 template <
typename Lambda>
1305 DEAL_II_ALWAYS_INLINE
inline auto
1309 auto result = state;
1310 auto M = lambda(momentum(state));
1311 for (
unsigned int d = 0; d < dim; ++d)
1312 result[1 + d] = M[d];
typename get_value_type< Number >::type ScalarNumber
dealii::Tensor< 1, problem_dimension, Number > state_type
std::array< Number, n_precomputed_values > precomputed_type
Vectors::StateVector< ScalarNumber, problem_dimension, n_precomputed_values > StateVector
dealii::Tensor< 1, problem_dimension, dealii::Tensor< 1, dim, Number > > flux_type
Number pressure(const state_type &U) const
state_type flux_divergence(const flux_contribution_type &flux_i, const flux_contribution_type &flux_j, const dealii::Tensor< 1, dim, Number > &c_ij) const
DEAL_II_ALWAYS_INLINE ScalarNumber gravity() const
bool is_admissible(const state_type &U) const
static const auto precomputed_names
static const auto initial_precomputed_names
state_type mathematical_entropy_derivative(const state_type &U) const
typename get_value_type< Number >::type ScalarNumber
static Number water_depth(const state_type &U)
DEAL_II_ALWAYS_INLINE ScalarNumber dry_state_relaxation_large() const
void precomputation_loop(unsigned int cycle, const DISPATCH &dispatch_check, const SPARSITY &sparsity_simd, StateVector &state_vector, unsigned int left, unsigned int right) const
static constexpr unsigned int n_initial_precomputed_values
state_type high_order_flux_divergence(const flux_contribution_type &flux_i, const flux_contribution_type &flux_j, const dealii::Tensor< 1, dim, Number > &c_ij) const
DEAL_II_ALWAYS_INLINE ScalarNumber dry_state_relaxation_small() const
Number inverse_water_depth_mollified(const state_type &U) const
static const auto component_names
Number water_depth_sharp(const state_type &U) const
Vectors::StateVector< ScalarNumber, problem_dimension, n_precomputed_values > StateVector
state_type nodal_source(const PrecomputedVector &pv, const unsigned int i, const state_type &U_i, const ScalarNumber tau) const
static constexpr unsigned int n_precomputed_values
static constexpr bool have_high_order_flux
Number inverse_water_depth_sharp(const state_type &U) const
Number kinetic_energy(const state_type &U) const
Number filter_dry_water_depth(const Number &h) const
static constexpr bool have_source_terms
state_type from_primitive_state(const state_type &primitive_state) const
state_type manning_friction(const state_type &U, const Number &h_star, const ScalarNumber tau) const
state_type expand_state(const ST &state) const
std::array< Number, n_initial_precomputed_values > initial_precomputed_type
DEAL_II_ALWAYS_INLINE ScalarNumber manning_friction_coefficient() const
Number speed_of_sound(const state_type &U) const
state_type star_state(const state_type &U, const Number &Z_left, const Number &Z_right) const
dealii::Tensor< 1, problem_dimension, Number > state_type
static dealii::Tensor< 1, dim, Number > momentum(const state_type &U)
state_type affine_shift(const flux_contribution_type &flux_i, const flux_contribution_type &flux_j, const dealii::Tensor< 1, dim, Number > &c_ij, const Number &d_ij) const
std::array< Number, n_precomputed_values > precomputed_type
state_type to_primitive_state(const state_type &state) const
state_type from_initial_state(const ST &initial_state) const
static const auto primitive_component_names
static constexpr unsigned int problem_dimension
flux_contribution_type flux_contribution(const PrecomputedVector &pv, const InitialPrecomputedVector &piv, const unsigned int i, const state_type &U_i) const
static constexpr unsigned int n_precomputation_cycles
flux_type g(const state_type &U) const
Number mathematical_entropy(const state_type &U) const
HyperbolicSystemView(const HyperbolicSystem &hyperbolic_system)
state_type apply_boundary_conditions(const dealii::types::boundary_id id, const state_type &U, const dealii::Tensor< 1, dim, Number > &normal, const Lambda &get_dirichlet_data) const
std::array< state_type, 2 > equilibrated_states(const flux_contribution_type &, const flux_contribution_type &) const
std::tuple< state_type, Number > flux_contribution_type
flux_type f(const state_type &U) const
state_type prescribe_riemann_characteristic(const state_type &U, const state_type &U_bar, const dealii::Tensor< 1, dim, Number > &normal) const
state_type apply_galilei_transform(const state_type &state, const Lambda &lambda) const
DEAL_II_ALWAYS_INLINE ScalarNumber reference_water_depth() const
HyperbolicSystem(const std::string &subsection="/HyperbolicSystem")
static const std::string problem_name
T pow(const T x, const T b)
DEAL_II_ALWAYS_INLINE Number positive_part(const Number number)
DEAL_II_ALWAYS_INLINE FT add(const FT &flux_left_ij, const FT &flux_right_ij)
DEAL_II_ALWAYS_INLINE dealii::Tensor< 1, problem_dim, T > contract(const FT &flux_ij, const TT &c_ij)