ryujin 2.5.0 revision 3a6c8d57210175dea14d8116e1fe878f349f8c1c
Loading...
Searching...
No Matches
wave_speed_estimator.h
Go to the documentation of this file.
1//
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3// Copyright (C) 2020 - 2026 by the ryujin authors
4//
5
6#pragma once
7
8#include <ryujin/base/compile_time_options.h>
9#include <ryujin/base/gpu.h>
11#include <ryujin/base/simd.h>
14
15#include <deal.II/base/point.h>
16#include <deal.II/base/tensor.h>
17
18
19namespace ryujin
20{
21 namespace Euler
22 {
23 template <int dim,
24 typename Number = double,
25 typename MemorySpace = dealii::MemorySpace::Host>
26 class WaveSpeedEstimatorView;
27
33 inline constexpr EulerAEOS::NASGRiemannSolverOptions
35 .pinf = false,
36 .safe_division = false,
37 .variable_gamma = false};
38
42 template <typename ScalarNumber>
46
59 template <typename ScalarNumber = double>
60 class WaveSpeedEstimator : protected PGRiemannSolver<ScalarNumber>
61 {
62 public:
67
71 WaveSpeedEstimator(const HyperbolicSystem &hyperbolic_system,
72 const std::string &subsection = "/WaveSpeedEstimator")
73 : PGRiemannSolver<ScalarNumber>(subsection)
74 , hyperbolic_system_(&hyperbolic_system)
75 {
76 /* Transfer all equation of state parameters to the Riemann solver. */
77
78 const auto update_parameters = [this] {
79 const auto view =
80 hyperbolic_system_->template view<1, ScalarNumber>();
81 this->set_gamma(view.gamma());
82 };
83
84 this->parse_parameters_call_back.connect(update_parameters);
85 update_parameters();
86 }
87
95 template <int dim,
96 typename Number,
97 typename MemorySpace = dealii::MemorySpace::Host>
98 auto view() const
99 {
101 hyperbolic_system_->template view<dim, Number, MemorySpace>(),
102 *this};
103 }
104
105 private:
107
111
112 dealii::ObserverPointer<const HyperbolicSystem> hyperbolic_system_;
113
114 template <int, typename, typename>
116
118 };
119
120
129 template <int dim, typename Number, typename MemorySpace>
131 {
132 public:
133 static_assert(
134 std::is_same_v<MemorySpace, dealii::MemorySpace::Host> ||
135 std::is_same_v<MemorySpace, dealii::MemorySpace::Default>,
136 "Unexpected memory space");
137
142
144
146
147 using state_type = typename View::state_type;
148
154 Number,
156 MemorySpace>;
157
162 static constexpr unsigned int riemann_data_size =
164
170
172
174
178
185 : view_(view)
186 , riemann_solver_view_(
187 static_cast<const PGRiemannSolver<ScalarNumber> &>(wse)
188 .template view<Number, MemorySpace>())
189 {
190 }
191
197 DEAL_II_HOST_DEVICE Number
198 compute(const primitive_type &riemann_data_i,
199 const primitive_type &riemann_data_j) const;
200
208 DEAL_II_HOST_DEVICE Number
210 const state_type &U_i,
211 const state_type &U_j,
212 const unsigned int i,
213 const unsigned int *js,
214 const dealii::Tensor<1, dim, Number> &n_ij) const;
215
217
218 protected:
223
231 DEAL_II_HOST_DEVICE primitive_type
233 const dealii::Tensor<1, dim, Number> &n_ij) const;
234
235 private:
237
241
242 const View view_;
243 const RiemannSolverView riemann_solver_view_;
244
246 };
247
248
249 /*
250 * -------------------------------------------------------------------------
251 * Inline definitions
252 * -------------------------------------------------------------------------
253 */
254
255
256 template <int dim, typename Number, typename MemorySpace>
257 DEAL_II_HOST_DEVICE_ALWAYS_INLINE Number
259 const primitive_type &riemann_data_i,
260 const primitive_type &riemann_data_j) const
261 {
262 return riemann_solver_view_.compute(riemann_data_i, riemann_data_j);
263 }
264
265
266 template <int dim, typename Number, typename MemorySpace>
267 DEAL_II_HOST_DEVICE_ALWAYS_INLINE Number
269 const PrecomputedVectorView & /*pv*/,
270 const state_type &U_i,
271 const state_type &U_j,
272 const unsigned int /*i*/,
273 const unsigned int * /*js*/,
274 const dealii::Tensor<1, dim, Number> &n_ij) const
275 {
276 const auto riemann_data_i = riemann_data_from_state(U_i, n_ij);
277 const auto riemann_data_j = riemann_data_from_state(U_j, n_ij);
278
279 return compute(riemann_data_i, riemann_data_j);
280 }
281
282
283 template <int dim, typename Number, typename MemorySpace>
284 DEAL_II_HOST_DEVICE_ALWAYS_INLINE auto
286 const state_type &U, const dealii::Tensor<1, dim, Number> &n_ij) const
288 {
289 const auto rho = view_.density(U);
290 const auto rho_inverse = Number(1.0) / rho;
291
292 const auto m = view_.momentum(U);
293 const auto proj_m = n_ij * m;
294 const auto perp = m - proj_m * n_ij;
295
296 const auto E = view_.total_energy(U) -
297 Number(0.5) * perp.norm_square() * rho_inverse;
298
299 /*
300 * Compute the pressure and speed of sound of the projected
301 * one-dimensional state [rho, proj_m, E]:
302 */
303 const auto gamma = view_.gamma();
304 const auto internal_energy =
305 E - ScalarNumber(0.5) * (proj_m * proj_m) * rho_inverse;
306 const auto p = (gamma - ScalarNumber(1.)) * internal_energy;
307 const auto a = std::sqrt(gamma * p * rho_inverse);
308
309 return {{rho, proj_m * rho_inverse, p, Number(gamma), a}};
310 }
311 } // namespace Euler
312} // namespace ryujin
static constexpr unsigned int riemann_data_size
std::array< Number, riemann_data_size > primitive_type
VectorView< n_precomputed_values > PrecomputedVectorView
dealii::Tensor< 1, problem_dimension, Number > state_type
typename get_value_type< Number >::type ScalarNumber
WaveSpeedEstimatorView(const View &view, const WaveSpeedEstimator< ScalarNumber > &wse)
HyperbolicSystemView< dim, Number, MemorySpace > View
typename View::PrecomputedVectorView PrecomputedVectorView
DEAL_II_HOST_DEVICE primitive_type riemann_data_from_state(const state_type &U, const dealii::Tensor< 1, dim, Number > &n_ij) const
DEAL_II_HOST_DEVICE Number compute(const primitive_type &riemann_data_i, const primitive_type &riemann_data_j) const
EulerAEOS::NASGRiemannSolverView< Number, polytropic_gas_riemann_solver_options, MemorySpace > RiemannSolverView
static constexpr unsigned int riemann_data_size
typename RiemannSolverView::primitive_type primitive_type
WaveSpeedEstimator(const HyperbolicSystem &hyperbolic_system, const std::string &subsection="/WaveSpeedEstimator")
constexpr EulerAEOS::NASGRiemannSolverOptions polytropic_gas_riemann_solver_options