ryujin 2.1.1 revision d1a5601757449924e68a428cfd892dfe8915810d
indicator.h
Go to the documentation of this file.
1//
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3// Copyright (C) 2023 - 2024 by the ryujin authors
4//
5
6#pragma once
7
8#include "hyperbolic_system.h"
9
11#include <simd.h>
12
13#include <deal.II/base/parameter_acceptor.h>
14#include <deal.II/base/vectorization.h>
15
16
17namespace ryujin
18{
19 namespace ScalarConservation
20 {
21 template <typename ScalarNumber = double>
22 class IndicatorParameters : public dealii::ParameterAcceptor
23 {
24 public:
25 IndicatorParameters(const std::string &subsection = "/Indicator")
26 : ParameterAcceptor(subsection)
27 {
28 evc_factor_ = ScalarNumber(1.);
29 add_parameter("evc factor",
30 evc_factor_,
31 "Factor for scaling the entropy viscocity commuator");
32 }
33
34 ACCESSOR_READ_ONLY(evc_factor);
35
36 private:
37 ScalarNumber evc_factor_;
38 };
39
40
47 template <int dim, typename Number = double>
49 {
50 public:
55
57
59
61
62 using state_type = typename View::state_type;
63
64 using flux_type = typename View::flux_type;
65
67
69
71
73
91
95 Indicator(const HyperbolicSystem &hyperbolic_system,
96 const Parameters &parameters,
97 const PrecomputedVector &precomputed_values)
98 : hyperbolic_system(hyperbolic_system)
99 , parameters(parameters)
100 , precomputed_values(precomputed_values)
101 {
102 }
103
108 void reset(const unsigned int i, const state_type &U_i);
109
114 void accumulate(const unsigned int *js,
115 const state_type &U_j,
116 const dealii::Tensor<1, dim, Number> &c_ij);
117
121 Number alpha(const Number h_i) const;
122
124
125 private:
130
131 const HyperbolicSystem &hyperbolic_system;
132 const Parameters &parameters;
133 const PrecomputedVector &precomputed_values;
134
135 Number u_i;
136 Number u_abs_max;
137 dealii::Tensor<1, dim, Number> f_i;
138 Number left;
139 Number right;
141 };
142
143
144 /*
145 * -------------------------------------------------------------------------
146 * Inline definitions
147 * -------------------------------------------------------------------------
148 */
149
150
151 template <int dim, typename Number>
152 DEAL_II_ALWAYS_INLINE inline void
153 Indicator<dim, Number>::reset(const unsigned int i, const state_type &U_i)
154 {
155 /* entropy viscosity commutator: */
156
157 const auto view = hyperbolic_system.view<dim, Number>();
158
159 const auto prec_i =
160 precomputed_values.template get_tensor<Number, precomputed_type>(i);
161
162 u_i = view.state(U_i);
163 u_abs_max = std::abs(u_i);
164 f_i = view.construct_flux_tensor(prec_i);
165 left = 0.;
166 right = 0.;
167 }
168
169
170 template <int dim, typename Number>
171 DEAL_II_ALWAYS_INLINE inline void Indicator<dim, Number>::accumulate(
172 const unsigned int *js,
173 const state_type &U_j,
174 const dealii::Tensor<1, dim, Number> &c_ij)
175 {
176 /* entropy viscosity commutator: */
177
178 const auto view = hyperbolic_system.view<dim, Number>();
179
180 const auto prec_j =
181 precomputed_values.template get_tensor<Number, precomputed_type>(js);
182
183 const auto u_j = view.state(U_j);
184 u_abs_max = std::max(u_abs_max, std::abs(u_j));
185 const auto d_eta_j = view.kruzkov_entropy_derivative(u_i, u_j);
186 const auto f_j = view.construct_flux_tensor(prec_j);
187
188 left += d_eta_j * (f_j * c_ij);
189 right += d_eta_j * (f_i * c_ij);
190 }
191
192
193 template <int dim, typename Number>
194 DEAL_II_ALWAYS_INLINE inline Number
195 Indicator<dim, Number>::alpha(const Number hd_i) const
196 {
197 Number numerator = left - right;
198 Number denominator = std::abs(left) + std::abs(right);
199
200 const auto regularization =
201 Number(100. * std::numeric_limits<ScalarNumber>::min());
202
203 const auto quotient =
204 std::abs(numerator) /
205 (denominator + std::max(hd_i * std::abs(u_abs_max), regularization));
206
207 return std::min(Number(1.), parameters.evc_factor() * quotient);
208 }
209
210 } // namespace ScalarConservation
211} // namespace ryujin
dealii::Tensor< 1, problem_dimension, dealii::Tensor< 1, dim, Number > > flux_type
std::array< Number, n_precomputed_values > precomputed_type
Vectors::MultiComponentVector< ScalarNumber, n_precomputed_values > PrecomputedVector
typename get_value_type< Number >::type ScalarNumber
dealii::Tensor< 1, problem_dimension, Number > state_type
IndicatorParameters(const std::string &subsection="/Indicator")
Definition: indicator.h:25
void reset(const unsigned int i, const state_type &U_i)
Definition: indicator.h:153
typename View::state_type state_type
Definition: indicator.h:62
typename View::PrecomputedVector PrecomputedVector
Definition: indicator.h:68
typename View::ScalarNumber ScalarNumber
Definition: indicator.h:58
void accumulate(const unsigned int *js, const state_type &U_j, const dealii::Tensor< 1, dim, Number > &c_ij)
Definition: indicator.h:171
static constexpr auto problem_dimension
Definition: indicator.h:60
typename View::flux_type flux_type
Definition: indicator.h:64
Indicator(const HyperbolicSystem &hyperbolic_system, const Parameters &parameters, const PrecomputedVector &precomputed_values)
Definition: indicator.h:95
Number alpha(const Number h_i) const
Definition: indicator.h:195
typename View::precomputed_type precomputed_type
Definition: indicator.h:66