ryujin 2.1.1 revision b04fb4aba7bd97ddfa5994a6b4b6e8586eb15db2
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 <compile_time_options.h>
9
10#include "hyperbolic_system.h"
11#include "nasg_riemann_solver.h"
12
13#include <gpu.h>
14#include <observer_pointer.h>
15#include <simd.h>
16
17#include <deal.II/base/point.h>
18#include <deal.II/base/tensor.h>
19
20namespace ryujin
21{
22 namespace EulerAEOS
23 {
24 template <int dim,
25 typename Number = double,
26 typename MemorySpace = dealii::MemorySpace::Host>
27 class WaveSpeedEstimatorView;
28
38 template <typename ScalarNumber = double>
39 class WaveSpeedEstimator : protected NASGRiemannSolver<ScalarNumber>
40 {
41 public:
46
50 WaveSpeedEstimator(const HyperbolicSystem &hyperbolic_system,
51 const std::string &subsection = "/WaveSpeedEstimator")
52 : NASGRiemannSolver<ScalarNumber>(subsection)
53 , hyperbolic_system_(&hyperbolic_system)
54 {
55 /* Transfer all equation of state parameters to the Riemann solver. */
56
57 const auto update_parameters = [this] {
58 const auto view =
59 hyperbolic_system_->template view<1, ScalarNumber>();
60 this->set_equation_of_state(view.eos_covolume_constant(),
61 view.eos_interpolation_pinfty(),
62 view.compute_strict_bounds());
63 };
64
65 this->parse_parameters_call_back.connect(update_parameters);
66 update_parameters();
67 }
68
76 template <int dim,
77 typename Number,
78 typename MemorySpace = dealii::MemorySpace::Host>
79 auto view() const
80 {
82 hyperbolic_system_->template view<dim, Number, MemorySpace>(),
83 *this};
84 }
85
86 private:
88
92
93 dealii::ObserverPointer<const HyperbolicSystem> hyperbolic_system_;
94
95 template <int, typename, typename>
97
99 };
100
101
110 template <int dim, typename Number, typename MemorySpace>
112 {
113 public:
114 static_assert(
115 std::is_same_v<MemorySpace, dealii::MemorySpace::Host> ||
116 std::is_same_v<MemorySpace, dealii::MemorySpace::Default>,
117 "Unexpected memory space");
118
123
125
127
128 using state_type = typename View::state_type;
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 state_type &U_i,
192 const state_type &U_j,
193 const unsigned int i,
194 const unsigned int *js,
195 const dealii::Tensor<1, dim, Number> &n_ij) const;
196
198
199 protected:
204
212 DEAL_II_HOST_DEVICE primitive_type
214 const Number &p,
215 const dealii::Tensor<1, dim, Number> &n_ij) const;
216
217 private:
219
223
224 const View view_;
225 const RiemannSolverView riemann_solver_view_;
226
228 };
229
230
231 /*
232 * -------------------------------------------------------------------------
233 * Inline definitions
234 * -------------------------------------------------------------------------
235 */
236
237
238 template <int dim, typename Number, typename MemorySpace>
239 DEAL_II_HOST_DEVICE_ALWAYS_INLINE Number
241 const primitive_type &riemann_data_i,
242 const primitive_type &riemann_data_j) const
243 {
244 return riemann_solver_view_.compute(riemann_data_i, riemann_data_j);
245 }
246
247
248 template <int dim, typename Number, typename MemorySpace>
249 DEAL_II_HOST_DEVICE_ALWAYS_INLINE Number
251 const PrecomputedVectorView &pv,
252 const state_type &U_i,
253 const state_type &U_j,
254 const unsigned int i,
255 const unsigned int *js,
256 const dealii::Tensor<1, dim, Number> &n_ij) const
257 {
258 const auto &[p_i, unused_i, s_i, eta_i] =
259 pv.template read_tensor<Number, precomputed_type>(i);
260
261 const auto &[p_j, unused_j, s_j, eta_j] =
262 pv.template read_tensor<Number, precomputed_type>(js);
263
264 const auto riemann_data_i = riemann_data_from_state(U_i, p_i, n_ij);
265 const auto riemann_data_j = riemann_data_from_state(U_j, p_j, n_ij);
266
267 return compute(riemann_data_i, riemann_data_j);
268 }
269
270
271 template <int dim, typename Number, typename MemorySpace>
272 DEAL_II_HOST_DEVICE_ALWAYS_INLINE auto
274 const state_type &U,
275 const Number &p,
276 const dealii::Tensor<1, dim, Number> &n_ij) const -> primitive_type
277 {
278 const auto rho = view_.density(U);
279 const auto rho_inverse = ScalarNumber(1.0) / rho;
280
281 const auto m = view_.momentum(U);
282 const auto proj_m = n_ij * m;
283
284 const auto gamma = view_.surrogate_gamma(U, p);
285
286 const auto covolume_b = view_.eos_covolume_constant();
287 const auto pinf = view_.eos_interpolation_pinfty();
288 const auto x = Number(1.) - covolume_b * rho;
289 const auto a = std::sqrt(gamma * (p + pinf) / (rho * x));
290
291#ifdef DEBUG_EXPENSIVE_BOUNDS_CHECK
293 Number(p + pinf),
294 [](auto val) { return val >= ScalarNumber(0.); },
295 dealii::ExcMessage("Internal error: p + pinf < 0."));
296
298 x,
299 [](auto val) { return val > ScalarNumber(0.); },
300 dealii::ExcMessage("Internal error: 1. - b * rho <= 0."));
301
303 gamma,
304 [](auto val) { return val >= ScalarNumber(1.); },
305 dealii::ExcMessage("Internal error: gamma < 1."));
306#endif
307
308 return {{rho, proj_m * rho_inverse, p, gamma, a}};
309 }
310 } // namespace EulerAEOS
311} // 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)
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