ryujin 2.5.0 revision c64172211cf21344cb9b9b0f3a1266aa6400d392
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
18namespace ryujin
19{
20 namespace EulerAEOS
21 {
22 template <int dim,
23 typename Number = double,
24 typename MemorySpace = dealii::MemorySpace::Host>
25 class WaveSpeedEstimatorView;
26
36 template <typename ScalarNumber = double>
37 class WaveSpeedEstimator : protected NASGRiemannSolver<ScalarNumber>
38 {
39 public:
44
48 WaveSpeedEstimator(const HyperbolicSystem &hyperbolic_system,
49 const std::string &subsection = "/WaveSpeedEstimator")
50 : NASGRiemannSolver<ScalarNumber>(subsection)
51 , hyperbolic_system_(&hyperbolic_system)
52 {
53 /* Transfer all equation of state parameters to the Riemann solver. */
54
55 const auto update_parameters = [this] {
56 const auto view =
57 hyperbolic_system_->template view<1, ScalarNumber>();
58 this->set_equation_of_state(view.eos_covolume_constant(),
59 view.eos_interpolation_pinfty(),
60 view.compute_strict_bounds());
61 };
62
63 this->parse_parameters_call_back.connect(update_parameters);
64 update_parameters();
65 }
66
74 template <int dim,
75 typename Number,
76 typename MemorySpace = dealii::MemorySpace::Host>
77 auto view() const
78 {
80 hyperbolic_system_->template view<dim, Number, MemorySpace>(),
81 *this};
82 }
83
84 private:
86
90
91 dealii::ObserverPointer<const HyperbolicSystem> hyperbolic_system_;
92
93 template <int, typename, typename>
95
97 };
98
99
108 template <int dim, typename Number, typename MemorySpace>
110 {
111 public:
112 static_assert(
113 std::is_same_v<MemorySpace, dealii::MemorySpace::Host> ||
114 std::is_same_v<MemorySpace, dealii::MemorySpace::Default>,
115 "Unexpected memory space");
116
121
123
125
126 using state_type = typename View::state_type;
127
129
137 MemorySpace>;
138
143 static constexpr unsigned int riemann_data_size =
145
151
153
155
157
161
168 : view_(view)
169 , riemann_solver_view_(
170 static_cast<const NASGRiemannSolver<ScalarNumber> &>(wse)
171 .template view<Number, MemorySpace>())
172 {
173 }
174
180 DEAL_II_HOST_DEVICE Number
181 compute(const primitive_type &riemann_data_i,
182 const primitive_type &riemann_data_j) const;
183
189 DEAL_II_HOST_DEVICE Number
191 const unsigned int i,
192 const unsigned int *js,
193 const state_type &U_i,
194 const state_type &U_j,
195 const flux_contribution_type &flux_i,
196 const flux_contribution_type &flux_j,
197 const dealii::Tensor<1, dim, Number> &n_ij) const;
198
200
201 protected:
206
214 DEAL_II_HOST_DEVICE primitive_type
216 const Number &p,
217 const dealii::Tensor<1, dim, Number> &n_ij) const;
218
219 private:
221
225
226 const View view_;
227 const RiemannSolverView riemann_solver_view_;
228
230 };
231
232
233 /*
234 * -------------------------------------------------------------------------
235 * Inline definitions
236 * -------------------------------------------------------------------------
237 */
238
239
240 template <int dim, typename Number, typename MemorySpace>
241 DEAL_II_HOST_DEVICE_ALWAYS_INLINE Number
243 const primitive_type &riemann_data_i,
244 const primitive_type &riemann_data_j) const
245 {
246 return riemann_solver_view_.compute(riemann_data_i, riemann_data_j);
247 }
248
249
250 template <int dim, typename Number, typename MemorySpace>
251 DEAL_II_HOST_DEVICE_ALWAYS_INLINE Number
253 const PrecomputedVectorView &pv,
254 const unsigned int i,
255 const unsigned int *js,
256 const state_type &U_i,
257 const state_type &U_j,
258 const flux_contribution_type & /*flux_i*/,
259 const flux_contribution_type & /*flux_j*/,
260 const dealii::Tensor<1, dim, Number> &n_ij) const
261 {
262 const auto &[p_i, unused_i, s_i, eta_i] =
263 pv.template read_tensor<Number, precomputed_type>(i);
264
265 const auto &[p_j, unused_j, s_j, eta_j] =
266 pv.template read_tensor<Number, precomputed_type>(js);
267
268 const auto riemann_data_i = riemann_data_from_state(U_i, p_i, n_ij);
269 const auto riemann_data_j = riemann_data_from_state(U_j, p_j, n_ij);
270
271 return compute(riemann_data_i, riemann_data_j);
272 }
273
274
275 template <int dim, typename Number, typename MemorySpace>
276 DEAL_II_HOST_DEVICE_ALWAYS_INLINE auto
278 const state_type &U,
279 const Number &p,
280 const dealii::Tensor<1, dim, Number> &n_ij) const -> primitive_type
281 {
282 const auto rho = view_.density(U);
283 const auto rho_inverse = ScalarNumber(1.0) / rho;
284
285 const auto m = view_.momentum(U);
286 const auto proj_m = n_ij * m;
287
288 const auto gamma = view_.surrogate_gamma(U, p);
289
290 const auto covolume_b = view_.eos_covolume_constant();
291 const auto pinf = view_.eos_interpolation_pinfty();
292 const auto x = Number(1.) - covolume_b * rho;
293 const auto a = std::sqrt(gamma * (p + pinf) / (rho * x));
294
295#ifdef DEBUG_EXPENSIVE_BOUNDS_CHECK
297 Number(p + pinf),
298 [](auto val) { return val >= ScalarNumber(0.); },
299 dealii::ExcMessage("Internal error: p + pinf < 0."));
300
302 x,
303 [](auto val) { return val > ScalarNumber(0.); },
304 dealii::ExcMessage("Internal error: 1. - b * rho <= 0."));
305
307 gamma,
308 [](auto val) { return val >= ScalarNumber(1.); },
309 dealii::ExcMessage("Internal error: gamma < 1."));
310#endif
311
312 return {{rho, proj_m * rho_inverse, p, gamma, a}};
313 }
314 } // namespace EulerAEOS
315} // namespace ryujin
dealii::Tensor< 1, problem_dimension, Number > state_type
typename get_value_type< Number >::type ScalarNumber
VectorView< n_precomputed_values > PrecomputedVectorView
std::array< Number, n_precomputed_values > precomputed_type
static constexpr unsigned int riemann_data_size
std::array< Number, riemann_data_size > primitive_type
void set_equation_of_state(const double covolume_b, const double pinf, const bool compute_expensive_bounds)
typename View::flux_contribution_type flux_contribution_type
NASGRiemannSolverView< Number, NASGRiemannSolverOptions{}, MemorySpace > RiemannSolverView
typename View::precomputed_type precomputed_type
typename View::PrecomputedVectorView PrecomputedVectorView
HyperbolicSystemView< dim, Number, MemorySpace > View
DEAL_II_HOST_DEVICE Number compute(const primitive_type &riemann_data_i, const primitive_type &riemann_data_j) const
WaveSpeedEstimatorView(const View &view, const WaveSpeedEstimator< ScalarNumber > &wse)
DEAL_II_HOST_DEVICE primitive_type riemann_data_from_state(const state_type &U, const Number &p, const dealii::Tensor< 1, dim, Number > &n_ij) const
typename RiemannSolverView::primitive_type primitive_type
static constexpr unsigned int riemann_data_size
WaveSpeedEstimator(const HyperbolicSystem &hyperbolic_system, const std::string &subsection="/WaveSpeedEstimator")
#define AssertThrowSIMD(variable, condition, exception)
Definition simd.h:34