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 ScalarConservation
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 u_i_;
205 Number u_abs_max_;
206 dealii::Tensor<1, dim, Number> f_i_;
207 Number left_;
208 Number right_;
210 };
211
212
213 /*
214 * -------------------------------------------------------------------------
215 * Inline definitions
216 * -------------------------------------------------------------------------
217 */
218
219
220 template <int dim, typename Number>
221 DEAL_II_ALWAYS_INLINE inline void
223 const unsigned int i,
224 const state_type &U_i)
225 {
226 /* entropy viscosity commutator: */
227
228 const auto prec_i = pv.template read_tensor<Number, precomputed_type>(i);
229
230 u_i_ = view_.state(U_i);
231 u_abs_max_ = std::abs(u_i_);
232 f_i_ = view_.construct_flux_tensor(prec_i);
233 left_ = 0.;
234 right_ = 0.;
235 }
236
237
238 template <int dim, typename Number>
239 DEAL_II_ALWAYS_INLINE inline void IndicatorView<dim, Number>::accumulate(
240 const PrecomputedVectorView &pv,
241 const unsigned int *js,
242 const state_type &U_j,
243 const dealii::Tensor<1, dim, Number> &c_ij)
244 {
245 /* entropy viscosity commutator: */
246
247 const auto prec_j = pv.template read_tensor<Number, precomputed_type>(js);
248
249 const auto u_j = view_.state(U_j);
250 u_abs_max_ = std::max(u_abs_max_, std::abs(u_j));
251 const auto d_eta_j = view_.kruzkov_entropy_derivative(u_i_, u_j);
252 const auto f_j = view_.construct_flux_tensor(prec_j);
253
254 left_ += d_eta_j * (f_j * c_ij);
255 right_ += d_eta_j * (f_i_ * c_ij);
256 }
257
258
259 template <int dim, typename Number>
260 DEAL_II_ALWAYS_INLINE inline Number
261 IndicatorView<dim, Number>::alpha(const Number hd_i) const
262 {
263 Number numerator = left_ - right_;
264 Number denominator = std::abs(left_) + std::abs(right_);
265
266 const auto regularization =
267 Number(100. * std::numeric_limits<ScalarNumber>::min());
268
269 const auto quotient =
270 std::abs(numerator) /
271 (denominator + std::max(hd_i * std::abs(u_abs_max_), regularization));
272
273 return std::min(Number(1.), indicator_.evc_factor() * quotient);
274 }
275
276 } // namespace ScalarConservation
277} // namespace ryujin
dealii::Tensor< 1, problem_dimension, dealii::Tensor< 1, dim, Number > > flux_type
std::array< Number, n_precomputed_values > precomputed_type
Vectors::MultiComponentVectorView< ScalarNumber, n_precomputed_values, dealii::VectorizedArray< ScalarNumber >::size(), dealii::MemorySpace::Host, false > PrecomputedVectorView
typename get_value_type< Number >::type ScalarNumber
dealii::Tensor< 1, problem_dimension, Number > state_type
typename View::flux_type flux_type
Definition indicator.h:135
static constexpr auto problem_dimension
Definition indicator.h:131
typename View::ScalarNumber ScalarNumber
Definition indicator.h:129
Number alpha(const Number h_i) const
Definition indicator.h:261
typename View::PrecomputedVectorView PrecomputedVectorView
Definition indicator.h:139
HyperbolicSystemView< dim, Number > View
Definition indicator.h:127
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:239
typename View::state_type state_type
Definition indicator.h:133
IndicatorView(const View &view, const Indicator< ScalarNumber > &indicator)
Definition indicator.h:165
void reset(const PrecomputedVectorView &pv, const unsigned int i, const state_type &U_i)
Definition indicator.h:222
typename View::precomputed_type precomputed_type
Definition indicator.h:137
Indicator(const HyperbolicSystem &hyperbolic_system, const std::string &subsection="/Indicator")
Definition indicator.h:58