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) 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
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 EulerAEOS
23 {
24 template <int dim, typename Number = double>
25 class IndicatorView;
26
66 template <typename ScalarNumber = double>
67 class Indicator : public dealii::ParameterAcceptor
68 {
69 public:
74
79 template <int dim, typename Number = double>
81
83
87
91 Indicator(const HyperbolicSystem &hyperbolic_system,
92 const std::string &subsection = "/Indicator")
93 : ParameterAcceptor(subsection)
94 , hyperbolic_system_(&hyperbolic_system)
95 {
96 evc_factor_ = ScalarNumber(1.);
97 add_parameter("evc factor",
98 evc_factor_,
99 "Factor for scaling the entropy viscocity commuator");
100 }
101
103
107
109
115 template <int dim, typename Number>
116 auto view() const
117 {
118 return View<dim, Number>{
119 hyperbolic_system_->template view<dim, Number>(), *this};
120 }
121
122 private:
124
128
129 ScalarNumber evc_factor_;
130
132
136
137 dealii::ObserverPointer<const HyperbolicSystem> hyperbolic_system_;
138
140 };
141
142
151 template <int dim, typename Number>
153 {
154 public:
159
161
163
165
166 using state_type = typename View::state_type;
167
168 using flux_type = typename View::flux_type;
169
171
173
175
193
198 IndicatorView(const View &view, const Indicator<ScalarNumber> &indicator)
199 : view_(view)
200 , indicator_(indicator)
201 {
202 }
203
208 void reset(const PrecomputedVectorView &pv,
209 const unsigned int i,
210 const state_type &U_i);
211
216 void accumulate(const PrecomputedVectorView &pv,
217 const unsigned int *js,
218 const state_type &U_j,
219 const dealii::Tensor<1, dim, Number> &c_ij);
220
224 Number alpha(const Number h_i) const;
225
226
227 private:
229
233
234 const View view_;
235 const Indicator<ScalarNumber> &indicator_;
236
237 Number rho_i_inverse_ = 0.;
238 Number eta_i_ = 0.;
239 flux_type f_i_;
240 state_type d_eta_i_;
241 Number gamma_min_;
242
243 Number left_ = 0.;
244 state_type right_;
245
247 };
248
249
250 /*
251 * -------------------------------------------------------------------------
252 * Inline definitions
253 * -------------------------------------------------------------------------
254 */
255
256
257 template <int dim, typename Number>
258 DEAL_II_ALWAYS_INLINE inline void
260 const unsigned int i,
261 const state_type &U_i)
262 {
263 /* Entropy viscosity commutator: */
264
265 const auto &[p_i, gamma_min_i, s_i, eta_i] =
266 pv.template read_tensor<Number, precomputed_type>(i);
267
268 gamma_min_ = gamma_min_i;
269
270 const auto rho_i = view_.density(U_i);
271 rho_i_inverse_ = Number(1.) / rho_i;
272 eta_i_ = eta_i;
273
274 d_eta_i_ =
275 view_.surrogate_harten_entropy_derivative(U_i, eta_i_, gamma_min_);
276 d_eta_i_[0] -= eta_i_ * rho_i_inverse_;
277
278 const auto surrogate_p_i = view_.surrogate_pressure(U_i, gamma_min_);
279 f_i_ = view_.f(U_i, surrogate_p_i);
280
281 left_ = 0.;
282 right_ = 0.;
283 }
284
285
286 template <int dim, typename Number>
287 DEAL_II_ALWAYS_INLINE inline void IndicatorView<dim, Number>::accumulate(
288 const PrecomputedVectorView & /*pv*/,
289 const unsigned int * /*js*/,
290 const state_type &U_j,
291 const dealii::Tensor<1, dim, Number> &c_ij)
292 {
293 /* Entropy viscosity commutator: */
294
295 const auto eta_j = view_.surrogate_harten_entropy(U_j, gamma_min_);
296
297 const auto rho_j = view_.density(U_j);
298 const auto rho_j_inverse = Number(1.) / rho_j;
299
300 const auto m_j = view_.momentum(U_j);
301
302 const auto surrogate_p_j = view_.surrogate_pressure(U_j, gamma_min_);
303 const auto f_j = view_.f(U_j, surrogate_p_j);
304
305 const auto entropy_flux =
306 (eta_j * rho_j_inverse - eta_i_ * rho_i_inverse_) * (m_j * c_ij);
307
308 left_ += entropy_flux;
309 for (unsigned int k = 0; k < problem_dimension; ++k) {
310 const auto component = (f_j[k] - f_i_[k]) * c_ij;
311 right_[k] += component;
312 }
313 }
314
315
316 template <int dim, typename Number>
317 DEAL_II_ALWAYS_INLINE inline Number
318 IndicatorView<dim, Number>::alpha(const Number hd_i) const
319 {
320 /* Entropy viscosity commutator: */
321
322 Number numerator = left_;
323 Number denominator = std::abs(left_);
324 for (unsigned int k = 0; k < problem_dimension; ++k) {
325 numerator -= d_eta_i_[k] * right_[k];
326 denominator += std::abs(d_eta_i_[k] * right_[k]);
327 }
328
329 const auto quotient = safe_division(
330 std::abs(numerator), denominator + hd_i * std::abs(eta_i_));
331
332 return std::min(Number(1.), indicator_.evc_factor() * quotient);
333 }
334 } // namespace EulerAEOS
335} // namespace ryujin
dealii::Tensor< 1, problem_dimension, Number > state_type
Vectors::MultiComponentVectorView< ScalarNumber, n_precomputed_values, dealii::VectorizedArray< ScalarNumber >::size(), dealii::MemorySpace::Host, false > PrecomputedVectorView
typename get_value_type< Number >::type ScalarNumber
static constexpr unsigned int problem_dimension
std::array< Number, n_precomputed_values > precomputed_type
dealii::Tensor< 1, problem_dimension, dealii::Tensor< 1, dim, Number > > flux_type
IndicatorView(const View &view, const Indicator< ScalarNumber > &indicator)
Definition indicator.h:198
typename View::state_type state_type
Definition indicator.h:166
typename View::flux_type flux_type
Definition indicator.h:168
static constexpr auto problem_dimension
Definition indicator.h:164
typename View::precomputed_type precomputed_type
Definition indicator.h:170
Number alpha(const Number h_i) const
Definition indicator.h:318
HyperbolicSystemView< dim, Number > View
Definition indicator.h:160
typename View::ScalarNumber ScalarNumber
Definition indicator.h:162
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:287
void reset(const PrecomputedVectorView &pv, const unsigned int i, const state_type &U_i)
Definition indicator.h:259
typename View::PrecomputedVectorView PrecomputedVectorView
Definition indicator.h:172
Indicator(const HyperbolicSystem &hyperbolic_system, const std::string &subsection="/Indicator")
Definition indicator.h:91
DEAL_II_ALWAYS_INLINE Number safe_division(const Number &numerator, const Number &denominator)