8#include <compile_time_options.h>
10#include <ryujin/interface/hyperbolic_system.h>
23#include <deal.II/base/memory_space.h>
24#include <deal.II/base/parameter_acceptor.h>
25#include <deal.II/base/tensor.h>
31 namespace EulerBarotropic
35 typename MemorySpace = dealii::MemorySpace::Host>
36 class HyperbolicSystemView;
75 typename Number = double,
76 typename MemorySpace = dealii::MemorySpace::Host>
88 typename MemorySpace = dealii::MemorySpace::Host>
107 template <
typename MemorySpace = dealii::MemorySpace::Host,
109 typename ScalarNumber>
113 const bool skip_constrained_dofs =
true)
const;
125 void update_parameters();
129 std::string barotropic_equation_of_state_;
132 barotropic_equation_of_state_list_;
134 using BarotropicEquationOfState =
136 std::shared_ptr<BarotropicEquationOfState>
137 selected_barotropic_equation_of_state_;
139 template <
int,
typename,
typename>
167 template <
int dim,
typename Number,
typename MemorySpace>
172 std::is_same_v<MemorySpace, dealii::MemorySpace::Host> ||
173 std::is_same_v<MemorySpace, dealii::MemorySpace::Default>,
174 "Unexpected memory space");
194 using state_type = dealii::Tensor<1, problem_dimension, Number>;
200 dealii::Tensor<1, problem_dimension, dealii::Tensor<1, dim, Number>>;
226 std::array<Number, n_initial_precomputed_values>;
228 template <
int n_comp>
257 hyperbolic_system.parameters_.template view<MemorySpace>())
258 , barotropic_equation_of_state_(
259 hyperbolic_system.selected_barotropic_equation_of_state_.get())
274 DEAL_II_ALWAYS_INLINE
inline const std::string &
277 return barotropic_equation_of_state_->name();
312 DEAL_II_ALWAYS_INLINE
inline Number
315 const auto &beos = barotropic_equation_of_state_;
317 if constexpr (std::is_same_v<ScalarNumber, Number>) {
318 return ScalarNumber(beos->specific_internal_energy(rho));
321 for (
unsigned int k = 0; k < Number::size(); ++k) {
322 e[k] =
ScalarNumber(beos->specific_internal_energy(rho[k]));
333 const auto &beos = barotropic_equation_of_state_;
335 if constexpr (std::is_same_v<ScalarNumber, Number>) {
339 for (
unsigned int k = 0; k < Number::size(); ++k) {
350 DEAL_II_ALWAYS_INLINE
inline Number
353 const auto &beos = barotropic_equation_of_state_;
355 if constexpr (std::is_same_v<ScalarNumber, Number>) {
359 for (
unsigned int k = 0; k < Number::size(); ++k) {
400 static DEAL_II_HOST_DEVICE dealii::Tensor<1, dim, Number>
411 const state_type &U,
const Number &specific_internal_energy)
const;
420 const Number &specific_internal_energy,
421 const Number &pressure)
const;
445 template <
int component>
451 const dealii::Tensor<1, dim, Number> &normal)
const;
475 template <
typename Lambda>
479 const dealii::Tensor<1, dim, Number> &normal,
480 const Lambda &get_dirichlet_data)
const;
498 const Number &p)
const;
523 const unsigned int i,
530 const unsigned int *js,
541 const dealii::Tensor<1, dim, Number> &c_ij)
const;
552 const dealii::Tensor<1, dim, Number> &c_ij)
const =
delete;
565 const unsigned int i,
571 const unsigned int *js,
591 template <
typename ST>
606 template <
typename ST>
628 template <
typename Lambda>
630 const state_type &state,
const Lambda &lambda)
const;
643 *
const barotropic_equation_of_state_;
658 "Compressible Euler equations "
659 "(barotropic EOS, optimized barotropic)",
661 {
"rho",
"m_1",
"m_2"},
662 {
"rho",
"m_1",
"m_2",
"m_3"}}},
664 {
"rho",
"v_1",
"v_2"},
665 {
"rho",
"v_1",
"v_2",
"v_3"}}},
666 {{{
"e",
"p",
"a"}, {
"e",
"p",
"a"}, {
"e",
"p",
"a"}}},
669 , parameters_(
"euler_barotropic_hyperbolic_system_parameters",
673 auto ¶meters = *parameters_.view();
675 barotropic_equation_of_state_ =
"isothermal";
676 add_parameter(
"barotropic equation of state",
677 barotropic_equation_of_state_,
678 "The barotropic equation of state. Valid names are given "
679 "by any of the subsections defined below");
681 parameters.reference_density = 1.;
682 add_parameter(
"reference density",
683 parameters.reference_density,
684 "Problem specific density reference");
686 parameters.vacuum_state_relaxation_small = 1.e2;
687 add_parameter(
"vacuum state relaxation small",
688 parameters.vacuum_state_relaxation_small,
689 "Problem specific vacuum relaxation parameter");
691 parameters.vacuum_state_relaxation_large = 1.e4;
692 add_parameter(
"vacuum state relaxation large",
693 parameters.vacuum_state_relaxation_large,
694 "Problem specific vacuum relaxation parameter");
701 barotropic_equation_of_state_list_, subsection);
703 ParameterAcceptor::parse_parameters_call_back.connect(
704 [
this] { update_parameters(); });
710 inline void HyperbolicSystem::update_parameters()
712 bool initialized =
false;
713 for (
auto &it : barotropic_equation_of_state_list_)
716 if (it->name() == barotropic_equation_of_state_) {
717 selected_barotropic_equation_of_state_ = it;
718 problem_name_ =
"Compressible Euler equations (" + it->name() +
719 " EOS, optimized barotropic)";
724 AssertThrow(initialized,
725 dealii::ExcMessage(
"Could not find a barotropic equation "
726 "of state description with name \"" +
727 barotropic_equation_of_state_ +
"\""));
734 template <
typename MemorySpace,
int dim,
typename ScalarNumber>
738 const bool skip_constrained_dofs)
const
740 using HostSpace = dealii::MemorySpace::Host;
747 auto &U = state_vector.
U;
758 constexpr bool transfer =
760 !std::is_same_v<MemorySpace, dealii::MemorySpace::Host>;
762 [[maybe_unused]]
const bool host_resident =
763 U.template is_resident<HostSpace>();
765 if constexpr (transfer) {
766 U.template copy_to_memory_space<HostSpace>();
767 precomputed.template move_to_memory_space<HostSpace>();
771 const auto sparsity_simd_view =
777 .template view<ScalarView::problem_dimension, HostSpace>();
778 const auto precomputed_view =
780 .template view<ScalarView::n_precomputed_values, HostSpace>();
782 const auto hyperbolic_system_views =
783 make_select_view<dim, ScalarNumber, HostSpace>(*
this);
785 const auto body = [=](
auto sentinel,
unsigned int i) {
786 using T =
decltype(sentinel);
790 const unsigned int row_length = sparsity_simd_view.row_length(i);
791 if (skip_constrained_dofs && row_length == 1)
794 const auto view = hyperbolic_system_views.template view<T>();
796 const auto U_i = U_view.template read_tensor<T>(i);
797 const auto rho_i =
view.density(U_i);
800 const auto e_i =
view.beos_specific_internal_energy(rho_i);
801 const auto p_i =
view.beos_pressure(rho_i);
802 const auto a_i =
view.beos_speed_of_sound(rho_i);
804 const precomputed_type prec_i{e_i, p_i, a_i};
805 precomputed_view.template write_tensor<T>(prec_i, i);
808 loop<HostSpace, ScalarNumber>(
809 "hyperbolic_kernel_01b", body, 0, n_internal, n_owned);
812 if constexpr (transfer) {
815 U.template move_to_memory_space<MemorySpace>();
816 precomputed.template move_to_memory_space<MemorySpace>();
821 template <
int dim,
typename Number,
typename MemorySpace>
822 DEAL_II_HOST_DEVICE_ALWAYS_INLINE Number
829 template <
int dim,
typename Number,
typename MemorySpace>
830 DEAL_II_HOST_DEVICE_ALWAYS_INLINE Number
832 const Number &rho)
const
834 constexpr ScalarNumber eps = std::numeric_limits<ScalarNumber>::epsilon();
835 const Number rho_cutoff_large =
836 reference_density() * vacuum_state_relaxation_large() * eps;
838 return ryujin::compare_and_apply_mask<dealii::SIMDComparison::less_than>(
839 std::abs(rho), rho_cutoff_large, Number(0.), rho);
843 template <
int dim,
typename Number,
typename MemorySpace>
844 DEAL_II_HOST_DEVICE_ALWAYS_INLINE dealii::Tensor<1, dim, Number>
848 dealii::Tensor<1, dim, Number> result;
849 for (
unsigned int i = 0; i < dim; ++i)
850 result[i] = U[1 + i];
855 template <
int dim,
typename Number,
typename MemorySpace>
856 DEAL_II_HOST_DEVICE_ALWAYS_INLINE Number
858 const state_type &U,
const Number &specific_internal_energy)
const
860 const auto rho = density(U);
862 const auto m = momentum(U);
864 return rho * specific_internal_energy +
869 template <
int dim,
typename Number,
typename MemorySpace>
870 DEAL_II_HOST_DEVICE_ALWAYS_INLINE
auto
873 const Number &specific_internal_energy,
876 const auto rho = density(U);
878 const auto m = momentum(U);
883 specific_internal_energy + rho_inverse * pressure -
884 ScalarNumber(0.5) * rho_inverse * rho_inverse * m.norm_square();
885 for (
unsigned int i = 0; i < dim; ++i)
886 result[1 + i] = rho_inverse * m[i];
892 template <
int dim,
typename Number,
typename MemorySpace>
893 DEAL_II_HOST_DEVICE_ALWAYS_INLINE
bool
897 const auto rho = density(U);
898 constexpr auto gt = dealii::SIMDComparison::greater_than;
901 ryujin::compare_and_apply_mask<gt>(rho, T(0.), T(0.), T(-1.));
904 if (!(test == Number(0.))) {
905 std::cout << std::fixed << std::setprecision(16);
906 std::cout <<
"Bounds violation: Negative state [rho, e] detected!\n";
907 std::cout <<
"\t\trho: " << rho <<
"\n";
911 return (test == Number(0.));
915 template <
int dim,
typename Number,
typename MemorySpace>
916 template <
int component>
917 DEAL_II_ALWAYS_INLINE
inline auto
924 const dealii::Tensor<1, dim, Number> & )
const
928 AssertThrow(
false, dealii::ExcNotImplemented());
934 template <
int dim,
typename Number,
typename MemorySpace>
935 template <
typename Lambda>
936 DEAL_II_ALWAYS_INLINE
inline auto
938 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];
956 const auto U_dirichlet = get_dirichlet_data();
957 const auto rho_dirichlet = density(U_dirichlet);
958 const auto v_dirichlet = momentum(U_dirichlet) / rho_dirichlet;
959 const auto rho = density(result);
960 for (
unsigned int k = 0; k < dim; ++k)
961 result[k + 1] = rho * v_dirichlet[k];
964 auto m = momentum(U);
965 m -= 1. * (m * normal) * normal;
966 for (
unsigned int k = 0; k < dim; ++k)
967 result[k + 1] = m[k];
970 for (
unsigned int k = 0; k < dim; ++k)
971 result[k + 1] = Number(0.);
986 const auto m = momentum(U);
987 const auto rho = density(U);
993 const auto p = beos_pressure(rho);
994 const auto a = beos_speed_of_sound(rho);
995 const auto vn = m * normal / rho;
999 result = get_dirichlet_data();
1003 if (vn >= -a && vn <= 0.) {
1004 const auto U_dirichlet = get_dirichlet_data();
1005 const auto rho_dirichlet = density(U_dirichlet);
1006 const auto p_dirichlet = beos_pressure(rho_dirichlet);
1008 result = prescribe_riemann_characteristic<2>(
1009 U_dirichlet, p_dirichlet, U, p, normal);
1013 if (vn > 0. && vn <= a) {
1014 const auto U_dirichlet = get_dirichlet_data();
1015 const auto rho_dirichlet = density(U_dirichlet);
1016 const auto p_dirichlet = beos_pressure(rho_dirichlet);
1018 result = prescribe_riemann_characteristic<1>(
1019 U, p, U_dirichlet, p_dirichlet, normal);
1024 AssertThrow(
false, dealii::ExcNotImplemented());
1031 template <
int dim,
typename Number,
typename MemorySpace>
1032 DEAL_II_HOST_DEVICE_ALWAYS_INLINE
auto
1034 const Number &p)
const
1037 const auto rho_inverse =
ScalarNumber(1.) / density(U);
1038 const auto m = momentum(U);
1043 for (
unsigned int i = 0; i < dim; ++i) {
1044 result[1 + i] = m * (m[i] * rho_inverse);
1045 result[1 + i][i] += p;
1052 template <
int dim,
typename Number,
typename MemorySpace>
1053 DEAL_II_HOST_DEVICE_ALWAYS_INLINE
auto
1057 const unsigned int i,
1060 const auto &[e_i, p_i, a_i] =
1061 pv.template read_tensor<Number, precomputed_type>(i);
1066 template <
int dim,
typename Number,
typename MemorySpace>
1067 DEAL_II_HOST_DEVICE_ALWAYS_INLINE
auto
1071 const unsigned int *js,
1074 const auto &[e_j, p_j, a_j] =
1075 pv.template read_tensor<Number, precomputed_type>(js);
1080 template <
int dim,
typename Number,
typename MemorySpace>
1081 DEAL_II_HOST_DEVICE_ALWAYS_INLINE
auto
1085 const dealii::Tensor<1, dim, Number> &c_ij)
const ->
state_type
1091 template <
int dim,
typename Number,
typename MemorySpace>
1092 template <
typename ST>
1093 DEAL_II_HOST_DEVICE_ALWAYS_INLINE
auto
1097 using T =
typename ST::value_type;
1098 static_assert(std::is_same_v<Number, T>,
"template mismatch");
1100 constexpr auto dim2 = ST::dimension - 1;
1101 static_assert(dim >= dim2,
1102 "the space dimension of the argument state must not be "
1103 "larger than the one of the target state");
1106 result[0] = state[0];
1107 for (
unsigned int i = 1; i < dim2 + 1; ++i)
1108 result[i] = state[i];
1114 template <
int dim,
typename Number,
typename MemorySpace>
1115 template <
typename ST>
1116 DEAL_II_HOST_DEVICE_ALWAYS_INLINE
auto
1120 const auto primitive_state = expand_state(initial_state);
1121 return from_primitive_state(primitive_state);
1125 template <
int dim,
typename Number,
typename MemorySpace>
1126 DEAL_II_HOST_DEVICE_ALWAYS_INLINE
auto
1130 const auto rho = density(primitive_state);
1132 auto state = primitive_state;
1134 for (
unsigned int i = 1; i < dim + 1; ++i)
1141 template <
int dim,
typename Number,
typename MemorySpace>
1142 DEAL_II_HOST_DEVICE_ALWAYS_INLINE
auto
1146 const auto rho = density(state);
1147 const auto rho_inverse = Number(1.) / rho;
1149 auto primitive_state = state;
1151 for (
unsigned int i = 1; i < dim + 1; ++i)
1152 primitive_state[i] *= rho_inverse;
1154 return primitive_state;
1158 template <
int dim,
typename Number,
typename MemorySpace>
1159 template <
typename Lambda>
1160 DEAL_II_HOST_DEVICE_ALWAYS_INLINE
auto
1164 auto result = state;
1165 const auto M = lambda(momentum(state));
1166 for (
unsigned int d = 0; d < dim; ++d)
1167 result[1 + d] = M[d];
HyperbolicSystemView(const HyperbolicSystem &hyperbolic_system)
DEAL_II_HOST_DEVICE bool is_admissible(const state_type &U) const
DEAL_II_HOST_DEVICE Number total_energy(const state_type &U, const Number &specific_internal_energy) const
DEAL_II_HOST_DEVICE flux_contribution_type flux_contribution(const PrecomputedVectorView &pv, const InitialPrecomputedVectorView &piv, const unsigned int i, const state_type &U_i) const
DEAL_II_HOST_DEVICE_ALWAYS_INLINE ScalarNumber vacuum_state_relaxation_small() const
static constexpr bool have_covolume_constant
DEAL_II_HOST_DEVICE state_type nodal_source(const PrecomputedVectorView &pv, const unsigned int i, const state_type &U_i, const ScalarNumber tau) const =delete
static constexpr unsigned int problem_dimension
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
DEAL_II_ALWAYS_INLINE Number beos_pressure(const Number &rho) const
static constexpr unsigned int n_initial_precomputed_values
DEAL_II_HOST_DEVICE state_type from_primitive_state(const state_type &primitive_state) const
static DEAL_II_HOST_DEVICE Number density(const state_type &U)
std::array< Number, n_precomputed_values > precomputed_type
static constexpr bool have_energy_equation
dealii::Tensor< 1, problem_dimension, Number > state_type
DEAL_II_HOST_DEVICE state_type from_initial_state(const ST &initial_state) const
typename get_value_type< Number >::type ScalarNumber
static constexpr bool have_high_order_flux
DEAL_II_HOST_DEVICE Number filter_vacuum_density(const Number &rho) const
static constexpr bool have_source_terms
static constexpr unsigned int n_precomputed_values
dealii::Tensor< 1, problem_dimension, dealii::Tensor< 1, dim, Number > > flux_type
DEAL_II_ALWAYS_INLINE Number beos_specific_internal_energy(const Number &rho) const
DEAL_II_HOST_DEVICE state_type total_energy_derivative(const state_type &U, const Number &specific_internal_energy, const Number &pressure) const
DEAL_II_HOST_DEVICE state_type apply_galilei_transform(const state_type &state, const Lambda &lambda) const
DEAL_II_HOST_DEVICE 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_HOST_DEVICE_ALWAYS_INLINE ScalarNumber reference_density() const
static constexpr bool have_gamma
static DEAL_II_HOST_DEVICE dealii::Tensor< 1, dim, Number > momentum(const state_type &U)
DEAL_II_HOST_DEVICE state_type to_primitive_state(const state_type &state) const
DEAL_II_HOST_DEVICE state_type expand_state(const ST &state) const
flux_type flux_contribution_type
DEAL_II_HOST_DEVICE_ALWAYS_INLINE ScalarNumber vacuum_state_relaxation_large() const
DEAL_II_ALWAYS_INLINE Number beos_speed_of_sound(const Number &rho) const
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
DEAL_II_HOST_DEVICE flux_type f(const state_type &U, const Number &p) const
DEAL_II_HOST_DEVICE state_type nodal_source(const PrecomputedVectorView &pv, const unsigned int *js, const state_type &U_j, const ScalarNumber tau) const =delete
DEAL_II_ALWAYS_INLINE const std::string & barotropic_equation_of_state() const
std::array< Number, n_initial_precomputed_values > initial_precomputed_type
DEAL_II_HOST_DEVICE 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
void fill_precomputed_values(const OfflineData< dim, ScalarNumber > &offline_data, StateVector< ScalarNumber > &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)
constexpr bool have_separate_memory_spaces
@ implicit_transfers_host_resident
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
double vacuum_state_relaxation_large
double vacuum_state_relaxation_small
MultiComponentVector< Number > U
MultiComponentVector< Number > precomputed