8#include <compile_time_options.h>
20#include <deal.II/base/parameter_acceptor.h>
21#include <deal.II/base/tensor.h>
27 namespace EulerBarotropic
37 template <
typename Number>
38 DEAL_II_ALWAYS_INLINE
inline Number
safe_division(
const Number &numerator,
39 const Number &denominator)
42 constexpr ScalarNumber
min = std::numeric_limits<ScalarNumber>::min();
44 return std::max(numerator, Number(0.)) /
45 std::max(denominator, Number(
min));
49 template <
int dim,
typename Number>
72 "Compressible Euler equations (barotropic EOS, optimized barotropic)";
83 template <
int dim,
typename Number =
double>
92 template <
int dim,
typename Number>
106 template <
int dim,
typename ScalarNumber>
111 const bool skip_constrained_dofs =
true)
const;
119 std::string barotropic_equation_of_state_;
121 double reference_density_;
122 double vacuum_state_relaxation_small_;
123 double vacuum_state_relaxation_large_;
132 barotropic_equation_of_state_list_;
134 using BarotropicEquationOfState =
136 std::shared_ptr<BarotropicEquationOfState>
137 selected_barotropic_equation_of_state_;
139 template <
int dim,
typename Number>
164 template <
int dim,
typename Number>
186 using state_type = dealii::Tensor<1, problem_dimension, Number>;
192 dealii::Tensor<1, problem_dimension, dealii::Tensor<1, dim, Number>>;
204 []() -> std::array<std::string, problem_dimension> {
205 if constexpr (dim == 1)
207 else if constexpr (dim == 2)
208 return {
"rho",
"m_1",
"m_2"};
209 else if constexpr (dim == 3)
210 return {
"rho",
"m_1",
"m_2",
"m_3"};
219 []() -> std::array<std::string, problem_dimension> {
220 if constexpr (dim == 1)
222 else if constexpr (dim == 2)
223 return {
"rho",
"v_1",
"v_2"};
224 else if constexpr (dim == 3)
225 return {
"rho",
"v_1",
"v_2",
"v_3"};
243 std::array<std::string, n_precomputed_values>{{
"e",
"p",
"a"}};
254 std::array<Number, n_initial_precomputed_values>;
260 std::array<std::string, n_initial_precomputed_values>{};
266 StateVector<ScalarNumber, problem_dimension, n_precomputed_values>;
287 dealii::VectorizedArray<ScalarNumber>::size(),
288 dealii::MemorySpace::Host,
306 dealii::VectorizedArray<ScalarNumber>::size(),
307 dealii::MemorySpace::Host,
321 : hyperbolic_system_(hyperbolic_system)
331 DEAL_II_ALWAYS_INLINE
inline const std::string &
334 return hyperbolic_system_.barotropic_equation_of_state_;
339 return hyperbolic_system_.reference_density_;
345 return hyperbolic_system_.vacuum_state_relaxation_small_;
351 return hyperbolic_system_.vacuum_state_relaxation_large_;
364 DEAL_II_ALWAYS_INLINE
inline Number
368 hyperbolic_system_.selected_barotropic_equation_of_state_;
370 if constexpr (std::is_same_v<ScalarNumber, Number>) {
371 return ScalarNumber(beos->specific_internal_energy(rho));
374 for (
unsigned int k = 0; k < Number::size(); ++k) {
375 e[k] =
ScalarNumber(beos->specific_internal_energy(rho[k]));
387 hyperbolic_system_.selected_barotropic_equation_of_state_;
389 if constexpr (std::is_same_v<ScalarNumber, Number>) {
393 for (
unsigned int k = 0; k < Number::size(); ++k) {
404 DEAL_II_ALWAYS_INLINE
inline Number
408 hyperbolic_system_.selected_barotropic_equation_of_state_;
410 if constexpr (std::is_same_v<ScalarNumber, Number>) {
414 for (
unsigned int k = 0; k < Number::size(); ++k) {
465 const Number &specific_internal_energy)
const;
473 const Number &specific_internal_energy,
474 const Number &pressure)
const;
495 template <
int component>
501 const dealii::Tensor<1, dim, Number> &normal)
const;
521 template <
typename Lambda>
525 const dealii::Tensor<1, dim, Number> &normal,
526 const Lambda &get_dirichlet_data)
const;
567 const unsigned int i,
573 const unsigned int *js,
583 const dealii::Tensor<1, dim, Number> &c_ij)
const;
593 const dealii::Tensor<1, dim, Number> &c_ij)
const =
delete;
605 const unsigned int i,
610 const unsigned int *js,
630 template <
typename ST>
645 template <
typename ST>
664 template <
typename Lambda>
666 const Lambda &lambda)
const;
689 const std::string &subsection )
690 : ParameterAcceptor(subsection)
692 barotropic_equation_of_state_ =
"isothermal";
693 add_parameter(
"barotropic equation of state",
694 barotropic_equation_of_state_,
695 "The barotropic equation of state. Valid names are given "
696 "by any of the subsections defined below");
698 reference_density_ = 1.;
699 add_parameter(
"reference density",
701 "Problem specific density reference");
703 vacuum_state_relaxation_small_ = 1.e2;
704 add_parameter(
"vacuum state relaxation small",
705 vacuum_state_relaxation_small_,
706 "Problem specific vacuum relaxation parameter");
708 vacuum_state_relaxation_large_ = 1.e4;
709 add_parameter(
"vacuum state relaxation large",
710 vacuum_state_relaxation_large_,
711 "Problem specific vacuum relaxation parameter");
718 barotropic_equation_of_state_list_, subsection);
720 const auto populate_functions = [
this]() {
721 bool initialized =
false;
722 for (
auto &it : barotropic_equation_of_state_list_)
725 if (it->name() == barotropic_equation_of_state_) {
726 selected_barotropic_equation_of_state_ = it;
727 problem_name =
"Compressible Euler equations (" + it->name() +
728 " EOS, optimized barotropic)";
733 AssertThrow(initialized,
734 dealii::ExcMessage(
"Could not find a barotropic equation "
735 "of state description with name \"" +
736 barotropic_equation_of_state_ +
"\""));
739 ParameterAcceptor::parse_parameters_call_back.connect(populate_functions);
740 populate_functions();
744 template <
int dim,
typename ScalarNumber>
749 const bool skip_constrained_dofs)
const
753 const auto sparsity_simd_view =
755 using VA = dealii::VectorizedArray<ScalarNumber>;
757 const auto U_view = std::get<0>(state_vector).view();
758 const auto precomputed_view = std::get<1>(state_vector).view();
760 const auto body = [&](
auto sentinel,
unsigned int i) {
761 using T =
decltype(sentinel);
765 const unsigned int row_length = sparsity_simd_view.row_length(i);
766 if (skip_constrained_dofs && row_length == 1)
769 const auto U_i = U_view.template read_tensor<T>(i);
770 const auto view = this->view<dim, T>();
771 const auto rho_i =
view.density(U_i);
773 const auto e_i =
view.beos_specific_internal_energy(rho_i);
774 const auto p_i =
view.beos_pressure(rho_i);
775 const auto a_i =
view.beos_speed_of_sound(rho_i);
777 const precomputed_type prec_i{e_i, p_i, a_i};
778 precomputed_view.template write_tensor<T>(prec_i, i);
781 cpu_simd_loop<ScalarNumber>(
"time_step_1", body, 0, n_internal, n_owned);
785 template <
int dim,
typename Number>
786 DEAL_II_ALWAYS_INLINE
inline Number
793 template <
int dim,
typename Number>
794 DEAL_II_ALWAYS_INLINE
inline Number
796 const Number &rho)
const
798 constexpr ScalarNumber eps = std::numeric_limits<ScalarNumber>::epsilon();
799 const Number rho_cutoff_large =
800 reference_density() * vacuum_state_relaxation_large() * eps;
802 return dealii::compare_and_apply_mask<dealii::SIMDComparison::less_than>(
803 std::abs(rho), rho_cutoff_large, Number(0.), rho);
807 template <
int dim,
typename Number>
808 DEAL_II_ALWAYS_INLINE
inline dealii::Tensor<1, dim, Number>
811 dealii::Tensor<1, dim, Number> result;
812 for (
unsigned int i = 0; i < dim; ++i)
813 result[i] = U[1 + i];
818 template <
int dim,
typename Number>
819 DEAL_II_ALWAYS_INLINE
inline Number
821 const state_type &U,
const Number &specific_internal_energy)
const
823 const auto rho = density(U);
825 const auto m = momentum(U);
827 return rho * specific_internal_energy +
832 template <
int dim,
typename Number>
833 DEAL_II_ALWAYS_INLINE
inline auto
836 const Number &specific_internal_energy,
839 const auto rho = density(U);
841 const auto m = momentum(U);
846 specific_internal_energy + rho_inverse * pressure -
847 ScalarNumber(0.5) * rho_inverse * rho_inverse * m.norm_square();
848 for (
unsigned int i = 0; i < dim; ++i)
849 result[1 + i] = rho_inverse * m[i];
855 template <
int dim,
typename Number>
856 DEAL_II_ALWAYS_INLINE
inline bool
859 const auto rho = density(U);
860 constexpr auto gt = dealii::SIMDComparison::greater_than;
863 dealii::compare_and_apply_mask<gt>(rho, T(0.), T(0.), T(-1.));
866 if (!(test == Number(0.))) {
867 std::cout << std::fixed << std::setprecision(16);
868 std::cout <<
"Bounds violation: Negative state [rho, e] detected!\n";
869 std::cout <<
"\t\trho: " << rho <<
"\n";
873 return (test == Number(0.));
877 template <
int dim,
typename Number>
878 template <
int component>
879 DEAL_II_ALWAYS_INLINE
inline auto
885 const dealii::Tensor<1, dim, Number> & )
const ->
state_type
888 AssertThrow(
false, dealii::ExcNotImplemented());
894 template <
int dim,
typename Number>
895 template <
typename Lambda>
896 DEAL_II_ALWAYS_INLINE
inline auto
898 dealii::types::boundary_id
id,
900 const dealii::Tensor<1, dim, Number> &normal,
901 const Lambda &get_dirichlet_data)
const ->
state_type
906 result = get_dirichlet_data();
910 auto m_dirichlet = momentum(get_dirichlet_data());
911 for (
unsigned int k = 0; k < dim; ++k)
912 result[k + 1] = m_dirichlet[k];
916 const auto U_dirichlet = get_dirichlet_data();
917 const auto rho_dirichlet = density(U_dirichlet);
918 const auto v_dirichlet = momentum(U_dirichlet) / rho_dirichlet;
919 const auto rho = density(result);
920 for (
unsigned int k = 0; k < dim; ++k)
921 result[k + 1] = rho * v_dirichlet[k];
924 auto m = momentum(U);
925 m -= 1. * (m * normal) * normal;
926 for (
unsigned int k = 0; k < dim; ++k)
927 result[k + 1] = m[k];
930 for (
unsigned int k = 0; k < dim; ++k)
931 result[k + 1] = Number(0.);
946 const auto m = momentum(U);
947 const auto rho = density(U);
953 const auto p = beos_pressure(rho);
954 const auto a = beos_speed_of_sound(rho);
955 const auto vn = m * normal / rho;
959 result = get_dirichlet_data();
963 if (vn >= -a && vn <= 0.) {
964 const auto U_dirichlet = get_dirichlet_data();
965 const auto rho_dirichlet = density(U_dirichlet);
966 const auto p_dirichlet = beos_pressure(rho_dirichlet);
968 result = prescribe_riemann_characteristic<2>(
969 U_dirichlet, p_dirichlet, U, p, normal);
973 if (vn > 0. && vn <= a) {
974 const auto U_dirichlet = get_dirichlet_data();
975 const auto rho_dirichlet = density(U_dirichlet);
976 const auto p_dirichlet = beos_pressure(rho_dirichlet);
978 result = prescribe_riemann_characteristic<1>(
979 U, p, U_dirichlet, p_dirichlet, normal);
984 AssertThrow(
false, dealii::ExcNotImplemented());
991 template <
int dim,
typename Number>
992 DEAL_II_ALWAYS_INLINE
inline auto
997 const auto m = momentum(U);
1002 for (
unsigned int i = 0; i < dim; ++i) {
1003 result[1 + i] = m * (m[i] * rho_inverse);
1004 result[1 + i][i] += p;
1011 template <
int dim,
typename Number>
1012 DEAL_II_ALWAYS_INLINE
inline auto
1016 const unsigned int i,
1019 const auto &[e_i, p_i, a_i] =
1020 pv.template read_tensor<Number, precomputed_type>(i);
1025 template <
int dim,
typename Number>
1026 DEAL_II_ALWAYS_INLINE
inline auto
1030 const unsigned int *js,
1033 const auto &[e_j, p_j, a_j] =
1034 pv.template read_tensor<Number, precomputed_type>(js);
1039 template <
int dim,
typename Number>
1040 DEAL_II_ALWAYS_INLINE
inline auto
1044 const dealii::Tensor<1, dim, Number> &c_ij)
const ->
state_type
1050 template <
int dim,
typename Number>
1051 template <
typename ST>
1055 using T =
typename ST::value_type;
1056 static_assert(std::is_same_v<Number, T>,
"template mismatch");
1058 constexpr auto dim2 = ST::dimension - 1;
1059 static_assert(dim >= dim2,
1060 "the space dimension of the argument state must not be "
1061 "larger than the one of the target state");
1064 result[0] = state[0];
1065 for (
unsigned int i = 1; i < dim2 + 1; ++i)
1066 result[i] = state[i];
1072 template <
int dim,
typename Number>
1073 template <
typename ST>
1074 DEAL_II_ALWAYS_INLINE
inline auto
1078 const auto primitive_state = expand_state(initial_state);
1079 return from_primitive_state(primitive_state);
1083 template <
int dim,
typename Number>
1084 DEAL_II_ALWAYS_INLINE
inline auto
1088 const auto rho = density(primitive_state);
1090 auto state = primitive_state;
1092 for (
unsigned int i = 1; i < dim + 1; ++i)
1099 template <
int dim,
typename Number>
1100 DEAL_II_ALWAYS_INLINE
inline auto
1104 const auto rho = density(state);
1105 const auto rho_inverse = Number(1.) / rho;
1107 auto primitive_state = state;
1109 for (
unsigned int i = 1; i < dim + 1; ++i)
1110 primitive_state[i] *= rho_inverse;
1112 return primitive_state;
1116 template <
int dim,
typename Number>
1117 template <
typename Lambda>
1121 auto result = state;
1122 const auto M = lambda(momentum(state));
1123 for (
unsigned int d = 0; d < dim; ++d)
1124 result[1 + d] = M[d];
state_type from_primitive_state(const state_type &primitive_state) const
flux_type flux_contribution_type
std::array< Number, n_precomputed_values > precomputed_type
static const auto precomputed_names
DEAL_II_ALWAYS_INLINE Number beos_speed_of_sound(const Number &rho) const
dealii::Tensor< 1, problem_dimension, dealii::Tensor< 1, dim, Number > > flux_type
dealii::Tensor< 1, problem_dimension, Number > state_type
DEAL_II_ALWAYS_INLINE const std::string & barotropic_equation_of_state() const
static const auto primitive_component_names
state_type apply_galilei_transform(const state_type &state, const Lambda &lambda) const
static constexpr unsigned int problem_dimension
Vectors::StateVector< ScalarNumber, problem_dimension, n_precomputed_values > StateVector
DEAL_II_ALWAYS_INLINE Number beos_pressure(const Number &rho) const
typename get_value_type< Number >::type ScalarNumber
static constexpr bool have_high_order_flux
state_type nodal_source(const PrecomputedVectorView &pv, const unsigned int *js, const state_type &U_j, const ScalarNumber tau) const =delete
state_type prescribe_riemann_characteristic(const state_type &U, const Number &p, const state_type &U_bar, const Number &p_bar, const dealii::Tensor< 1, dim, Number > &normal) const
std::array< Number, n_initial_precomputed_values > initial_precomputed_type
DEAL_II_ALWAYS_INLINE Number beos_specific_internal_energy(const Number &rho) const
static Number density(const state_type &U)
HyperbolicSystemView(const HyperbolicSystem &hyperbolic_system)
Number filter_vacuum_density(const Number &rho) const
flux_type f(const state_type &U, const Number &p) const
state_type total_energy_derivative(const state_type &U, const Number &specific_internal_energy, const Number &pressure) const
DEAL_II_ALWAYS_INLINE ScalarNumber vacuum_state_relaxation_large() const
DEAL_II_ALWAYS_INLINE ScalarNumber vacuum_state_relaxation_small() const
DEAL_II_ALWAYS_INLINE ScalarNumber reference_density() const
state_type expand_state(const ST &state) const
static constexpr unsigned int n_initial_precomputed_values
static constexpr bool have_energy_equation
flux_contribution_type flux_contribution(const PrecomputedVectorView &pv, const InitialPrecomputedVectorView &piv, const unsigned int i, const state_type &U_i) const
static constexpr bool have_covolume_constant
static const auto initial_precomputed_names
static constexpr bool have_gamma
static constexpr unsigned int n_precomputed_values
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
state_type nodal_source(const PrecomputedVectorView &pv, const unsigned int i, const state_type &U_i, const ScalarNumber tau) const =delete
state_type from_initial_state(const ST &initial_state) const
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 =delete
state_type to_primitive_state(const state_type &state) const
Number total_energy(const state_type &U, const Number &specific_internal_energy) const
static const auto component_names
static constexpr bool have_source_terms
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
bool is_admissible(const state_type &U) const
static dealii::Tensor< 1, dim, Number > momentum(const state_type &U)
static std::string problem_name
void fill_precomputed_values(const OfflineData< dim, ScalarNumber > &offline_data, typename HyperbolicSystemView< dim, ScalarNumber >::StateVector &state_vector, const bool skip_constrained_dofs=true) const
HyperbolicSystem(const std::string &subsection="/HyperbolicSystem")
dealii::Tensor< 1, problem_dimension, Number > state_type
const auto & n_locally_owned() const
const auto & sparsity_pattern_simd() const
const auto & n_locally_internal() const
void populate_equation_of_state_list(equation_of_state_list_type &equation_of_state_list, const std::string &subsection)
DEAL_II_HOST_DEVICE_ALWAYS_INLINE dealii::Tensor< 1, problem_dim, T > contract(const FT &flux_ij, const TT &c_ij)
DEAL_II_HOST_DEVICE_ALWAYS_INLINE FT add(const FT &flux_left_ij, const FT &flux_right_ij)
std::set< std::shared_ptr< BarotropicEquationOfState > > equation_of_state_list_type
DEAL_II_ALWAYS_INLINE Number safe_division(const Number &numerator, const Number &denominator)