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) 2023 - 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>
13
14#include <deal.II/base/point.h>
15#include <deal.II/base/tensor.h>
16
17// #define DEBUG_WAVE_SPEED_ESTIMATOR
18
19namespace ryujin
20{
21 namespace EulerBarotropic
22 {
23 template <int dim,
24 typename Number = double,
25 typename MemorySpace = dealii::MemorySpace::Host>
26 class WaveSpeedEstimatorView;
27
36 template <typename ScalarNumber = double>
37 class WaveSpeedEstimator : public dealii::ParameterAcceptor
38 {
39 public:
44
48 WaveSpeedEstimator(const HyperbolicSystem &hyperbolic_system,
49 const std::string &subsection = "/WaveSpeedEstimator")
50 : ParameterAcceptor(subsection)
51 , hyperbolic_system_(&hyperbolic_system)
52 {
53 }
54
62 template <int dim,
63 typename Number,
64 typename MemorySpace = dealii::MemorySpace::Host>
65 auto view() const
66 {
68 hyperbolic_system_->template view<dim, Number, MemorySpace>(),
69 *this};
70 }
71
72 private:
74
78
79 dealii::ObserverPointer<const HyperbolicSystem> hyperbolic_system_;
80
81 template <int, typename, typename>
83
85 };
86
87
96 template <int dim, typename Number, typename MemorySpace>
98 {
99 public:
100 static_assert(
101 std::is_same_v<MemorySpace, dealii::MemorySpace::Host> ||
102 std::is_same_v<MemorySpace, dealii::MemorySpace::Default>,
103 "Unexpected memory space");
104
109
111
113
114 using state_type = typename View::state_type;
115
117
121 static constexpr unsigned int riemann_data_size = 2;
122
127 using primitive_type = typename std::array<Number, riemann_data_size>;
128
130
132
134
138
144 const WaveSpeedEstimator<ScalarNumber> & /*wse*/)
145 : view_(view)
146 {
147 }
148
154 DEAL_II_HOST_DEVICE Number
155 compute(const primitive_type &riemann_data_i,
156 const primitive_type &riemann_data_j) const;
157
163 DEAL_II_HOST_DEVICE Number
165 const unsigned int i,
166 const unsigned int *js,
167 const state_type &U_i,
168 const state_type &U_j,
169 const flux_contribution_type &flux_i,
170 const flux_contribution_type &flux_j,
171 const dealii::Tensor<1, dim, Number> &n_ij) const;
172
173 private:
175
179
180 const View view_;
181
183 };
184
185
186 /*
187 * -------------------------------------------------------------------------
188 * Inline definitions
189 * -------------------------------------------------------------------------
190 */
191
192
193 template <int dim, typename Number, typename MemorySpace>
194 DEAL_II_HOST_DEVICE_ALWAYS_INLINE Number
196 const primitive_type &riemann_data_i,
197 const primitive_type &riemann_data_j) const
198 {
199 const auto &[u_i, a_i] = riemann_data_i;
200 const auto &[u_j, a_j] = riemann_data_j;
201
202#ifdef DEBUG_WAVE_SPEED_ESTIMATOR
203 std::cout << "u_left: " << u_i << std::endl;
204 std::cout << "a_left: " << a_i << std::endl;
205 std::cout << "u_right: " << u_j << std::endl;
206 std::cout << "a_right: " << a_j << std::endl;
207#endif
208
209 const Number lambda_max =
210 std::max(std::abs(u_i) + a_i, std::abs(u_j) + a_j);
211 return lambda_max;
212 }
213
214
215 template <int dim, typename Number, typename MemorySpace>
216 DEAL_II_HOST_DEVICE_ALWAYS_INLINE Number
218 const PrecomputedVectorView &pv,
219 const unsigned int i,
220 const unsigned int *js,
221 const state_type &U_i,
222 const state_type &U_j,
223 const flux_contribution_type & /*flux_i*/,
224 const flux_contribution_type & /*flux_j*/,
225 const dealii::Tensor<1, dim, Number> &n_ij) const
226 {
227 const auto &[e_i, p_i, a_i] =
228 pv.template read_tensor<Number, precomputed_type>(i);
229
230 const auto &[e_j, p_j, a_j] =
231 pv.template read_tensor<Number, precomputed_type>(js);
232
233 const auto rho_i = view_.density(U_i);
234 const auto rho_i_inverse = Number(1.0) / rho_i;
235 const auto m_i = view_.momentum(U_i);
236 const auto u_i = rho_i_inverse * n_ij * m_i;
237
238 const auto rho_j = view_.density(U_j);
239 const auto rho_j_inverse = Number(1.0) / rho_j;
240 const auto m_j = view_.momentum(U_j);
241 const auto u_j = rho_j_inverse * n_ij * m_j;
242
243 return compute(primitive_type{u_i, a_i}, primitive_type{u_j, a_j});
244 }
245 } // namespace EulerBarotropic
246} // namespace ryujin
VectorView< n_precomputed_values > PrecomputedVectorView
std::array< Number, n_precomputed_values > precomputed_type
dealii::Tensor< 1, problem_dimension, Number > state_type
typename get_value_type< Number >::type ScalarNumber
DEAL_II_HOST_DEVICE Number compute(const primitive_type &riemann_data_i, const primitive_type &riemann_data_j) const
typename std::array< Number, riemann_data_size > primitive_type
typename View::PrecomputedVectorView PrecomputedVectorView
HyperbolicSystemView< dim, Number, MemorySpace > View
typename View::flux_contribution_type flux_contribution_type
WaveSpeedEstimatorView(const View &view, const WaveSpeedEstimator< ScalarNumber > &)
WaveSpeedEstimator(const HyperbolicSystem &hyperbolic_system, const std::string &subsection="/WaveSpeedEstimator")