ryujin 2.1.1 revision ee5cbcbf2346c1299c942d0e1f13b46449973c18
Loading...
Searching...
No Matches
indicator.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 <compile_time_options.h>
9
10#include "hyperbolic_system.h"
11
13#include <observer_pointer.h>
14#include <simd.h>
15
16#include <deal.II/base/parameter_acceptor.h>
17#include <deal.II/base/vectorization.h>
18
19
20namespace ryujin
21{
22 namespace EulerBarotropic
23 {
24 template <int dim, typename Number = double>
25 class IndicatorView;
26
33 template <typename ScalarNumber = double>
34 class Indicator : public dealii::ParameterAcceptor
35 {
36 public:
41
46 template <int dim, typename Number = double>
48
50
54
58 Indicator(const HyperbolicSystem &hyperbolic_system,
59 const std::string &subsection = "/Indicator")
60 : ParameterAcceptor(subsection)
61 , hyperbolic_system_(&hyperbolic_system)
62 {
63 evc_factor_ = ScalarNumber(1.);
64 add_parameter("evc factor",
65 evc_factor_,
66 "Factor for scaling the entropy viscocity commuator");
67 }
68
70
74
75 ACCESSOR_READ_ONLY(evc_factor);
76
82 template <int dim, typename Number>
83 auto view() const
84 {
85 return View<dim, Number>{
86 hyperbolic_system_->template view<dim, Number>(), *this};
87 }
88
89 private:
91
95
96 ScalarNumber evc_factor_;
97
99
103
104 dealii::ObserverPointer<const HyperbolicSystem> hyperbolic_system_;
105
107 };
108
109
118 template <int dim, typename Number>
120 {
121 public:
126
128
130
132
133 using state_type = typename View::state_type;
134
135 using flux_type = typename View::flux_type;
136
138
140
142
160
165 IndicatorView(const View &view, const Indicator<ScalarNumber> &indicator)
166 : view_(view)
167 , indicator_(indicator)
168 {
169 }
170
175 void reset(const PrecomputedVectorView &pv,
176 const unsigned int i,
177 const state_type &U_i);
178
183 void accumulate(const PrecomputedVectorView &pv,
184 const unsigned int *js,
185 const state_type &U_j,
186 const dealii::Tensor<1, dim, Number> &c_ij);
187
191 Number alpha(const Number h_i) const;
192
193
194 private:
196
200
201 const View view_;
202 const Indicator<ScalarNumber> &indicator_;
203
204 Number eta_i_ = 0.;
205 state_type d_eta_i_;
206
207 Number left_ = 0.;
208 state_type right_;
209
211 };
212
213
214 /*
215 * -------------------------------------------------------------------------
216 * Inline definitions
217 * -------------------------------------------------------------------------
218 */
219
220
221 template <int dim, typename Number>
222 DEAL_II_ALWAYS_INLINE inline void
224 const unsigned int i,
225 const state_type &U_i)
226 {
227 /* Entropy viscosity commutator: */
228
229 const auto &[e_i, p_i, a_i] =
230 pv.template read_tensor<Number, precomputed_type>(i);
231
232 eta_i_ = view_.total_energy(U_i, e_i);
233 d_eta_i_ = view_.total_energy_derivative(U_i, e_i, p_i);
234
235 // left_ = sum_j F(U_j) * c_ij, where F is the mathematical entropy flux
236 left_ = 0.;
237
238 // right_ = sum_j f(U_j) * c_ij, where f is the flux of the system
239 right_ = 0.;
240 }
241
242
243 template <int dim, typename Number>
244 DEAL_II_ALWAYS_INLINE inline void IndicatorView<dim, Number>::accumulate(
245 const PrecomputedVectorView &pv,
246 const unsigned int *js,
247 const state_type &U_j,
248 const dealii::Tensor<1, dim, Number> &c_ij)
249 {
250 /* Entropy viscosity commutator: */
251
252 const auto &[e_j, p_j, a_j] =
253 pv.template read_tensor<Number, precomputed_type>(js);
254
255 const auto rho_j = view_.density(U_j);
256 const auto rho_j_inverse = Number(1.) / rho_j;
257 const auto eta_j = view_.total_energy(U_j, e_j);
258
259 const auto m_j = view_.momentum(U_j);
260
261 const auto f_j = view_.f(U_j, p_j);
262
263 const auto entropy_flux = (eta_j + p_j) * rho_j_inverse * (m_j * c_ij);
264
265 left_ += entropy_flux;
266 for (unsigned int k = 0; k < problem_dimension; ++k) {
267 right_[k] += f_j[k] * c_ij;
268 }
269 }
270
271
272 template <int dim, typename Number>
273 DEAL_II_ALWAYS_INLINE inline Number
274 IndicatorView<dim, Number>::alpha(const Number hd_i) const
275 {
276 /* Entropy viscosity commutator: */
277
278 Number numerator = left_;
279 Number denominator = std::abs(left_);
280 for (unsigned int k = 0; k < problem_dimension; ++k) {
281 numerator -= d_eta_i_[k] * right_[k];
282 denominator += std::abs(d_eta_i_[k] * right_[k]);
283 }
284
285 const auto quotient = safe_division(
286 std::abs(numerator), denominator + hd_i * std::abs(eta_i_));
287
288 return std::min(Number(1.), indicator_.evc_factor() * quotient);
289 }
290 } // namespace EulerBarotropic
291} // namespace ryujin
std::array< Number, n_precomputed_values > precomputed_type
dealii::Tensor< 1, problem_dimension, dealii::Tensor< 1, dim, Number > > flux_type
dealii::Tensor< 1, problem_dimension, Number > state_type
static constexpr unsigned int problem_dimension
typename get_value_type< Number >::type ScalarNumber
Vectors::MultiComponentVectorView< ScalarNumber, n_precomputed_values, dealii::VectorizedArray< ScalarNumber >::size(), dealii::MemorySpace::Host, false > PrecomputedVectorView
Number alpha(const Number h_i) const
Definition indicator.h:274
typename View::state_type state_type
Definition indicator.h:133
static constexpr auto problem_dimension
Definition indicator.h:131
IndicatorView(const View &view, const Indicator< ScalarNumber > &indicator)
Definition indicator.h:165
typename View::PrecomputedVectorView PrecomputedVectorView
Definition indicator.h:139
void accumulate(const PrecomputedVectorView &pv, const unsigned int *js, const state_type &U_j, const dealii::Tensor< 1, dim, Number > &c_ij)
Definition indicator.h:244
void reset(const PrecomputedVectorView &pv, const unsigned int i, const state_type &U_i)
Definition indicator.h:223
typename View::precomputed_type precomputed_type
Definition indicator.h:137
HyperbolicSystemView< dim, Number > View
Definition indicator.h:127
typename View::ScalarNumber ScalarNumber
Definition indicator.h:129
typename View::flux_type flux_type
Definition indicator.h:135
Indicator(const HyperbolicSystem &hyperbolic_system, const std::string &subsection="/Indicator")
Definition indicator.h:58
DEAL_II_ALWAYS_INLINE Number safe_division(const Number &numerator, const Number &denominator)