ryujin 2.1.1 revision a15074459a388761bd8df6bd4ef7e6abe9d8077b
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 "hyperbolic_system.h"
9
10#include <compile_time_options.h>
12#include <simd.h>
13
14#include <deal.II/base/parameter_acceptor.h>
15#include <deal.II/base/vectorization.h>
16
17
18namespace ryujin
19{
20 namespace EulerAEOS
21 {
22 template <typename ScalarNumber = double>
23 class IndicatorParameters : public dealii::ParameterAcceptor
24 {
25 public:
26 IndicatorParameters(const std::string &subsection = "/Indicator")
27 : ParameterAcceptor(subsection)
28 {
29 evc_factor_ = ScalarNumber(1.);
30 add_parameter("evc factor",
31 evc_factor_,
32 "Factor for scaling the entropy viscocity commuator");
33 }
34
35 ACCESSOR_READ_ONLY(evc_factor);
36
37 private:
38 ScalarNumber evc_factor_;
39 };
40
41
81 template <int dim, typename Number = double>
83 {
84 public:
89
93 static constexpr unsigned int problem_dimension = View::problem_dimension;
94
98 using state_type = typename View::state_type;
99
103 static constexpr unsigned int n_precomputed_values =
105
110
114 using flux_type = typename View::flux_type;
115
120
125
130
149
153 Indicator(const HyperbolicSystem &hyperbolic_system,
154 const Parameters &parameters,
156 &precomputed_values)
157 : hyperbolic_system(hyperbolic_system)
158 , parameters(parameters)
159 , precomputed_values(precomputed_values)
160 {
161 }
162
167 void reset(const unsigned int i, const state_type &U_i);
168
173 void accumulate(const unsigned int *js,
174 const state_type &U_j,
175 const dealii::Tensor<1, dim, Number> &c_ij);
176
180 Number alpha(const Number h_i) const;
181
183
184 private:
189
190 const HyperbolicSystem &hyperbolic_system;
191 const Parameters &parameters;
192
194 &precomputed_values;
195
196
197 Number rho_i_inverse = 0.;
198 Number eta_i = 0.;
199 flux_type f_i;
200 state_type d_eta_i;
201
202 Number left = 0.;
203 state_type right;
204
205 Number gamma_min;
206
208 };
209
210
211 /*
212 * -------------------------------------------------------------------------
213 * Inline definitions
214 * -------------------------------------------------------------------------
215 */
216
217
218 template <int dim, typename Number>
219 DEAL_II_ALWAYS_INLINE inline void
220 Indicator<dim, Number>::reset(const unsigned int i, const state_type &U_i)
221 {
222 const auto view = hyperbolic_system.view<dim, Number>();
223
224 if (!view.compute_strict_bounds())
225 return;
226
227 /* entropy viscosity commutator: */
228
229 const auto &[p_i, gamma_min_i, s_i, new_eta_i] =
230 precomputed_values
231 .template get_tensor<Number, precomputed_state_type>(i);
232
233 gamma_min = gamma_min_i;
234
235 const auto rho_i = view.density(U_i);
236 rho_i_inverse = Number(1.) / rho_i;
237 eta_i = new_eta_i;
238
239 d_eta_i = view.surrogate_harten_entropy_derivative(U_i, eta_i, gamma_min);
240 d_eta_i[0] -= eta_i * rho_i_inverse;
241
242 const auto surrogate_p_i = view.surrogate_pressure(U_i, gamma_min);
243 f_i = view.f(U_i, surrogate_p_i);
244
245 left = 0.;
246 right = 0.;
247 }
248
249
250 template <int dim, typename Number>
251 DEAL_II_ALWAYS_INLINE inline void Indicator<dim, Number>::accumulate(
252 const unsigned int * /*js*/,
253 const state_type &U_j,
254 const dealii::Tensor<1, dim, Number> &c_ij)
255 {
256 const auto view = hyperbolic_system.view<dim, Number>();
257
258 if (!view.compute_strict_bounds())
259 return;
260
261 /* entropy viscosity commutator: */
262
263 const auto eta_j = view.surrogate_harten_entropy(U_j, gamma_min);
264
265 const auto rho_j = view.density(U_j);
266 const auto rho_j_inverse = Number(1.) / rho_j;
267
268 const auto m_j = view.momentum(U_j);
269
270 const auto surrogate_p_j = view.surrogate_pressure(U_j, gamma_min);
271 const auto f_j = view.f(U_j, surrogate_p_j);
272
273 left += (eta_j * rho_j_inverse - eta_i * rho_i_inverse) * (m_j * c_ij);
274 for (unsigned int k = 0; k < problem_dimension; ++k)
275 right[k] += (f_j[k] - f_i[k]) * c_ij;
276 }
277
278
279 template <int dim, typename Number>
280 DEAL_II_ALWAYS_INLINE inline Number
281 Indicator<dim, Number>::alpha(const Number hd_i) const
282 {
283 const auto view = hyperbolic_system.view<dim, Number>();
284
285 if (!view.compute_strict_bounds())
286 return Number(0.);
287
288 Number numerator = left;
289 Number denominator = std::abs(left);
290 for (unsigned int k = 0; k < problem_dimension; ++k) {
291 numerator -= d_eta_i[k] * right[k];
292 denominator += std::abs(d_eta_i[k] * right[k]);
293 }
294
295 const auto quotient =
296 std::abs(numerator) / (denominator + hd_i * std::abs(eta_i));
297
298 return std::min(Number(1.), parameters.evc_factor() * quotient);
299 }
300
301 } // namespace EulerAEOS
302} // namespace ryujin
dealii::Tensor< 1, problem_dimension, Number > state_type
std::array< Number, n_precomputed_values > precomputed_state_type
typename get_value_type< Number >::type ScalarNumber
static constexpr unsigned int n_precomputed_values
static constexpr unsigned int problem_dimension
dealii::Tensor< 1, problem_dimension, dealii::Tensor< 1, dim, Number > > flux_type
IndicatorParameters(const std::string &subsection="/Indicator")
Definition: indicator.h:26
typename View::flux_type flux_type
Definition: indicator.h:114
void accumulate(const unsigned int *js, const state_type &U_j, const dealii::Tensor< 1, dim, Number > &c_ij)
Definition: indicator.h:251
typename View::state_type state_type
Definition: indicator.h:98
typename View::flux_contribution_type flux_contribution_type
Definition: indicator.h:119
Number alpha(const Number h_i) const
Definition: indicator.h:281
void reset(const unsigned int i, const state_type &U_i)
Definition: indicator.h:220
IndicatorParameters< ScalarNumber > Parameters
Definition: indicator.h:129
Indicator(const HyperbolicSystem &hyperbolic_system, const Parameters &parameters, const MultiComponentVector< ScalarNumber, n_precomputed_values > &precomputed_values)
Definition: indicator.h:153
static constexpr unsigned int n_precomputed_values
Definition: indicator.h:103
static constexpr unsigned int problem_dimension
Definition: indicator.h:93
typename View::precomputed_state_type precomputed_state_type
Definition: indicator.h:109
typename View::ScalarNumber ScalarNumber
Definition: indicator.h:124