ryujin 2.1.1 revision 46bf70e400e423a8ffffe8300887eeb35b8dfb2c
indicator.h
Go to the documentation of this file.
1//
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3// Copyright (C) 2020 - 2024 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 <simd.h>
14
15#include <deal.II/base/parameter_acceptor.h>
16#include <deal.II/base/vectorization.h>
17
18
19namespace ryujin
20{
21 namespace EulerAEOS
22 {
23 template <typename ScalarNumber = double>
24 class IndicatorParameters : public dealii::ParameterAcceptor
25 {
26 public:
27 IndicatorParameters(const std::string &subsection = "/Indicator")
28 : ParameterAcceptor(subsection)
29 {
30 evc_factor_ = ScalarNumber(1.);
31 add_parameter("evc factor",
32 evc_factor_,
33 "Factor for scaling the entropy viscocity commuator");
34 }
35
36 ACCESSOR_READ_ONLY(evc_factor);
37
38 private:
39 ScalarNumber evc_factor_;
40 };
41
42
82 template <int dim, typename Number = double>
84 {
85 public:
90
92
94
96
97 using state_type = typename View::state_type;
98
99 using flux_type = typename View::flux_type;
100
102
104
106
108
126
130 Indicator(const HyperbolicSystem &hyperbolic_system,
131 const Parameters &parameters,
132 const PrecomputedVector &precomputed_values)
133 : hyperbolic_system(hyperbolic_system)
134 , parameters(parameters)
135 , precomputed_values(precomputed_values)
136 {
137 }
138
143 void reset(const unsigned int i, const state_type &U_i);
144
149 void accumulate(const unsigned int *js,
150 const state_type &U_j,
151 const dealii::Tensor<1, dim, Number> &c_ij);
152
156 Number alpha(const Number h_i) const;
157
159
160 private:
165
166 const HyperbolicSystem &hyperbolic_system;
167 const Parameters &parameters;
168 const PrecomputedVector &precomputed_values;
169
170 Number rho_i_inverse = 0.;
171 Number eta_i = 0.;
172 flux_type f_i;
173 state_type d_eta_i;
174 Number gamma_min;
175
176 Number left = 0.;
177 state_type right;
178
180 };
181
182
183 /*
184 * -------------------------------------------------------------------------
185 * Inline definitions
186 * -------------------------------------------------------------------------
187 */
188
189
190 template <int dim, typename Number>
191 DEAL_II_ALWAYS_INLINE inline void
192 Indicator<dim, Number>::reset(const unsigned int i, const state_type &U_i)
193 {
194 /* Entropy viscosity commutator: */
195
196 const auto view = hyperbolic_system.view<dim, Number>();
197
198 const auto &[p_i, gamma_min_i, s_i, new_eta_i] =
199 precomputed_values.template get_tensor<Number, precomputed_type>(i);
200
201 gamma_min = gamma_min_i;
202
203 const auto rho_i = view.density(U_i);
204 rho_i_inverse = Number(1.) / rho_i;
205 eta_i = new_eta_i;
206
207 d_eta_i = view.surrogate_harten_entropy_derivative(U_i, eta_i, gamma_min);
208 d_eta_i[0] -= eta_i * rho_i_inverse;
209
210 const auto surrogate_p_i = view.surrogate_pressure(U_i, gamma_min);
211 f_i = view.f(U_i, surrogate_p_i);
212
213 left = 0.;
214 right = 0.;
215 }
216
217
218 template <int dim, typename Number>
219 DEAL_II_ALWAYS_INLINE inline void Indicator<dim, Number>::accumulate(
220 const unsigned int * /*js*/,
221 const state_type &U_j,
222 const dealii::Tensor<1, dim, Number> &c_ij)
223 {
224 /* Entropy viscosity commutator: */
225
226 const auto view = hyperbolic_system.view<dim, Number>();
227
228 const auto eta_j = view.surrogate_harten_entropy(U_j, gamma_min);
229
230 const auto rho_j = view.density(U_j);
231 const auto rho_j_inverse = Number(1.) / rho_j;
232
233 const auto m_j = view.momentum(U_j);
234
235 const auto surrogate_p_j = view.surrogate_pressure(U_j, gamma_min);
236 const auto f_j = view.f(U_j, surrogate_p_j);
237
238 const auto entropy_flux =
239 (eta_j * rho_j_inverse - eta_i * rho_i_inverse) * (m_j * c_ij);
240
241 left += entropy_flux;
242 for (unsigned int k = 0; k < problem_dimension; ++k) {
243 const auto component = (f_j[k] - f_i[k]) * c_ij;
244 right[k] += component;
245 }
246 }
247
248
249 template <int dim, typename Number>
250 DEAL_II_ALWAYS_INLINE inline Number
251 Indicator<dim, Number>::alpha(const Number hd_i) const
252 {
253 /* Entropy viscosity commutator: */
254
255 Number numerator = left;
256 Number denominator = std::abs(left);
257 for (unsigned int k = 0; k < problem_dimension; ++k) {
258 numerator -= d_eta_i[k] * right[k];
259 denominator += std::abs(d_eta_i[k] * right[k]);
260 }
261
262 const auto quotient = safe_division(std::abs(numerator),
263 denominator + hd_i * std::abs(eta_i));
264
265 return std::min(Number(1.), parameters.evc_factor() * quotient);
266 }
267 } // namespace EulerAEOS
268} // namespace ryujin
dealii::Tensor< 1, problem_dimension, Number > state_type
typename get_value_type< Number >::type ScalarNumber
static constexpr unsigned int problem_dimension
Vectors::MultiComponentVector< ScalarNumber, n_precomputed_values > PrecomputedVector
std::array< Number, n_precomputed_values > precomputed_type
dealii::Tensor< 1, problem_dimension, dealii::Tensor< 1, dim, Number > > flux_type
IndicatorParameters(const std::string &subsection="/Indicator")
Definition: indicator.h:27
static constexpr auto problem_dimension
Definition: indicator.h:95
typename View::PrecomputedVector PrecomputedVector
Definition: indicator.h:103
typename View::flux_type flux_type
Definition: indicator.h:99
typename View::precomputed_type precomputed_type
Definition: indicator.h:101
void accumulate(const unsigned int *js, const state_type &U_j, const dealii::Tensor< 1, dim, Number > &c_ij)
Definition: indicator.h:219
typename View::state_type state_type
Definition: indicator.h:97
Number alpha(const Number h_i) const
Definition: indicator.h:251
Indicator(const HyperbolicSystem &hyperbolic_system, const Parameters &parameters, const PrecomputedVector &precomputed_values)
Definition: indicator.h:130
void reset(const unsigned int i, const state_type &U_i)
Definition: indicator.h:192
IndicatorParameters< ScalarNumber > Parameters
Definition: indicator.h:105
typename View::ScalarNumber ScalarNumber
Definition: indicator.h:93
DEAL_II_ALWAYS_INLINE Number safe_division(const Number &numerator, const Number &denominator)