ryujin 2.1.1 revision 0348cbb53a3e4b1da2a4c037e81f88f2d21ce219
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
91
93
95
96 using state_type = typename View::state_type;
97
98 using flux_type = typename View::flux_type;
99
101
103
105
107
125
129 Indicator(const HyperbolicSystem &hyperbolic_system,
130 const Parameters &parameters,
131 const PrecomputedVector &precomputed_values)
132 : hyperbolic_system(hyperbolic_system)
133 , parameters(parameters)
134 , precomputed_values(precomputed_values)
135 {
136 }
137
142 void reset(const unsigned int i, const state_type &U_i);
143
148 void accumulate(const unsigned int *js,
149 const state_type &U_j,
150 const dealii::Tensor<1, dim, Number> &c_ij);
151
155 Number alpha(const Number h_i) const;
156
158
159 private:
164
165 const HyperbolicSystem &hyperbolic_system;
166 const Parameters &parameters;
167 const PrecomputedVector &precomputed_values;
168
169 Number rho_i_inverse = 0.;
170 Number eta_i = 0.;
171 flux_type f_i;
172 state_type d_eta_i;
173 Number gamma_min;
174
175 Number left = 0.;
176 state_type right;
177
179 };
180
181
182 /*
183 * -------------------------------------------------------------------------
184 * Inline definitions
185 * -------------------------------------------------------------------------
186 */
187
188
189 template <int dim, typename Number>
190 DEAL_II_ALWAYS_INLINE inline void
191 Indicator<dim, Number>::reset(const unsigned int i, const state_type &U_i)
192 {
193 /* Entropy viscosity commutator: */
194
195 const auto view = hyperbolic_system.view<dim, Number>();
196
197 const auto &[p_i, gamma_min_i, s_i, new_eta_i] =
198 precomputed_values.template get_tensor<Number, precomputed_type>(i);
199
200 gamma_min = gamma_min_i;
201
202 const auto rho_i = view.density(U_i);
203 rho_i_inverse = Number(1.) / rho_i;
204 eta_i = new_eta_i;
205
206 d_eta_i = view.surrogate_harten_entropy_derivative(U_i, eta_i, gamma_min);
207 d_eta_i[0] -= eta_i * rho_i_inverse;
208
209 const auto surrogate_p_i = view.surrogate_pressure(U_i, gamma_min);
210 f_i = view.f(U_i, surrogate_p_i);
211
212 left = 0.;
213 right = 0.;
214 }
215
216
217 template <int dim, typename Number>
218 DEAL_II_ALWAYS_INLINE inline void Indicator<dim, Number>::accumulate(
219 const unsigned int * /*js*/,
220 const state_type &U_j,
221 const dealii::Tensor<1, dim, Number> &c_ij)
222 {
223 /* Entropy viscosity commutator: */
224
225 const auto view = hyperbolic_system.view<dim, Number>();
226
227 const auto eta_j = view.surrogate_harten_entropy(U_j, gamma_min);
228
229 const auto rho_j = view.density(U_j);
230 const auto rho_j_inverse = Number(1.) / rho_j;
231
232 const auto m_j = view.momentum(U_j);
233
234 const auto surrogate_p_j = view.surrogate_pressure(U_j, gamma_min);
235 const auto f_j = view.f(U_j, surrogate_p_j);
236
237 const auto entropy_flux =
238 (eta_j * rho_j_inverse - eta_i * rho_i_inverse) * (m_j * c_ij);
239
240 left += entropy_flux;
241 for (unsigned int k = 0; k < problem_dimension; ++k) {
242 const auto component = (f_j[k] - f_i[k]) * c_ij;
243 right[k] += component;
244 }
245 }
246
247
248 template <int dim, typename Number>
249 DEAL_II_ALWAYS_INLINE inline Number
250 Indicator<dim, Number>::alpha(const Number hd_i) const
251 {
252 /* Entropy viscosity commutator: */
253
254 Number numerator = left;
255 Number denominator = std::abs(left);
256 for (unsigned int k = 0; k < problem_dimension; ++k) {
257 numerator -= d_eta_i[k] * right[k];
258 denominator += std::abs(d_eta_i[k] * right[k]);
259 }
260
261 const auto quotient = safe_division(std::abs(numerator),
262 denominator + hd_i * std::abs(eta_i));
263
264 return std::min(Number(1.), parameters.evc_factor() * quotient);
265 }
266 } // namespace EulerAEOS
267} // 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:26
static constexpr auto problem_dimension
Definition: indicator.h:94
typename View::PrecomputedVector PrecomputedVector
Definition: indicator.h:102
typename View::flux_type flux_type
Definition: indicator.h:98
typename View::precomputed_type precomputed_type
Definition: indicator.h:100
void accumulate(const unsigned int *js, const state_type &U_j, const dealii::Tensor< 1, dim, Number > &c_ij)
Definition: indicator.h:218
typename View::state_type state_type
Definition: indicator.h:96
Number alpha(const Number h_i) const
Definition: indicator.h:250
Indicator(const HyperbolicSystem &hyperbolic_system, const Parameters &parameters, const PrecomputedVector &precomputed_values)
Definition: indicator.h:129
void reset(const unsigned int i, const state_type &U_i)
Definition: indicator.h:191
IndicatorParameters< ScalarNumber > Parameters
Definition: indicator.h:104
typename View::ScalarNumber ScalarNumber
Definition: indicator.h:92
DEAL_II_ALWAYS_INLINE Number safe_division(const Number &numerator, const Number &denominator)