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
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
150
156 Number,
158 MemorySpace>;
159
164 static constexpr unsigned int riemann_data_size =
166
172
174
176
180
187 : view_(view)
188 , riemann_solver_view_(
189 static_cast<const PGRiemannSolver<ScalarNumber> &>(wse)
190 .template view<Number, MemorySpace>())
191 {
192 }
193
199 DEAL_II_HOST_DEVICE Number
200 compute(const primitive_type &riemann_data_i,
201 const primitive_type &riemann_data_j) const;
202
210 DEAL_II_HOST_DEVICE Number
212 const unsigned int i,
213 const unsigned int *js,
214 const state_type &U_i,
215 const state_type &U_j,
216 const flux_contribution_type &flux_i,
217 const flux_contribution_type &flux_j,
218 const dealii::Tensor<1, dim, Number> &n_ij) const;
219
221
222 protected:
227
235 DEAL_II_HOST_DEVICE primitive_type
237 const dealii::Tensor<1, dim, Number> &n_ij) const;
238
239 private:
241
245
246 const View view_;
247 const RiemannSolverView riemann_solver_view_;
248
250 };
251
252
253 /*
254 * -------------------------------------------------------------------------
255 * Inline definitions
256 * -------------------------------------------------------------------------
257 */
258
259
260 template <int dim, typename Number, typename MemorySpace>
261 DEAL_II_HOST_DEVICE_ALWAYS_INLINE Number
263 const primitive_type &riemann_data_i,
264 const primitive_type &riemann_data_j) const
265 {
266 return riemann_solver_view_.compute(riemann_data_i, riemann_data_j);
267 }
268
269
270 template <int dim, typename Number, typename MemorySpace>
271 DEAL_II_HOST_DEVICE_ALWAYS_INLINE Number
273 const PrecomputedVectorView & /*pv*/,
274 const unsigned int /*i*/,
275 const unsigned int * /*js*/,
276 const state_type &U_i,
277 const state_type &U_j,
278 const flux_contribution_type & /*flux_i*/,
279 const flux_contribution_type & /*flux_j*/,
280 const dealii::Tensor<1, dim, Number> &n_ij) const
281 {
282 const auto riemann_data_i = riemann_data_from_state(U_i, n_ij);
283 const auto riemann_data_j = riemann_data_from_state(U_j, n_ij);
284
285 return compute(riemann_data_i, riemann_data_j);
286 }
287
288
289 template <int dim, typename Number, typename MemorySpace>
290 DEAL_II_HOST_DEVICE_ALWAYS_INLINE auto
292 const state_type &U, const dealii::Tensor<1, dim, Number> &n_ij) const
294 {
295 const auto rho = view_.density(U);
296 const auto rho_inverse = Number(1.0) / rho;
297
298 const auto m = view_.momentum(U);
299 const auto proj_m = n_ij * m;
300 const auto perp = m - proj_m * n_ij;
301
302 const auto E = view_.total_energy(U) -
303 Number(0.5) * perp.norm_square() * rho_inverse;
304
305 /*
306 * Compute the pressure and speed of sound of the projected
307 * one-dimensional state [rho, proj_m, E]:
308 */
309 const auto gamma = view_.gamma();
310 const auto internal_energy =
311 E - ScalarNumber(0.5) * (proj_m * proj_m) * rho_inverse;
312 const auto p = (gamma - ScalarNumber(1.)) * internal_energy;
313 const auto a = std::sqrt(gamma * p * rho_inverse);
314
315 return {{rho, proj_m * rho_inverse, p, Number(gamma), a}};
316 }
317 } // namespace Euler
318} // 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
typename View::flux_contribution_type flux_contribution_type
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