ryujin 2.1.1 revision 863a4d36dcc743d4e1a9b41cfabd03d0aea57863
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
17namespace ryujin
18{
19 namespace Euler
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
80 template <int dim, typename Number = double>
82 {
83 public:
88
90
92
94
95 using state_type = typename View::state_type;
96
97 using flux_type = typename View::flux_type;
98
100
102
104
106
124
128 Indicator(const HyperbolicSystem &hyperbolic_system,
129 const Parameters &parameters,
130 const PrecomputedVector &precomputed_values)
131 : hyperbolic_system(hyperbolic_system)
132 , parameters(parameters)
133 , precomputed_values(precomputed_values)
134 {
135 }
136
141 void reset(const unsigned int i, const state_type &U_i);
142
147 void accumulate(const unsigned int *js,
148 const state_type &U_j,
149 const dealii::Tensor<1, dim, Number> &c_ij);
150
154 Number alpha(const Number h_i) const;
155
157
158 private:
163
164 const HyperbolicSystem &hyperbolic_system;
165 const Parameters &parameters;
166 const PrecomputedVector &precomputed_values;
167
168 Number rho_i_inverse = 0.;
169 Number eta_i = 0.;
170 flux_type f_i;
171 state_type d_eta_i;
172
173 Number left = 0.;
174 state_type right;
175
177 };
178
179
180 /*
181 * -------------------------------------------------------------------------
182 * Inline definitions
183 * -------------------------------------------------------------------------
184 */
185
186
187 template <int dim, typename Number>
188 DEAL_II_ALWAYS_INLINE inline void
189 Indicator<dim, Number>::reset(const unsigned int i, const state_type &U_i)
190 {
191 /* Entropy viscosity commutator: */
192
193 const auto view = hyperbolic_system.view<dim, Number>();
194
195 const auto &[new_s_i, new_eta_i] =
196 precomputed_values.template get_tensor<Number, precomputed_type>(i);
197
198 const auto rho_i = view.density(U_i);
199 rho_i_inverse = Number(1.) / rho_i;
200 eta_i = new_eta_i;
201
202 d_eta_i = view.harten_entropy_derivative(U_i);
203 d_eta_i[0] -= eta_i * rho_i_inverse;
204 f_i = view.f(U_i);
205
206 left = 0.;
207 right = 0.;
208 }
209
210
211 template <int dim, typename Number>
212 DEAL_II_ALWAYS_INLINE inline void Indicator<dim, Number>::accumulate(
213 const unsigned int *js,
214 const state_type &U_j,
215 const dealii::Tensor<1, dim, Number> &c_ij)
216 {
217 /* Entropy viscosity commutator: */
218
219 const auto view = hyperbolic_system.view<dim, Number>();
220
221 const auto &[s_j, eta_j] =
222 precomputed_values.template get_tensor<Number, precomputed_type>(js);
223
224 const auto rho_j = view.density(U_j);
225 const auto rho_j_inverse = Number(1.) / rho_j;
226
227 const auto m_j = view.momentum(U_j);
228 const auto f_j = view.f(U_j);
229
230 const auto entropy_flux =
231 (eta_j * rho_j_inverse - eta_i * rho_i_inverse) * (m_j * c_ij);
232
233 left += entropy_flux;
234 for (unsigned int k = 0; k < problem_dimension; ++k) {
235 const auto component = (f_j[k] - f_i[k]) * c_ij;
236 right[k] += component;
237 }
238 }
239
240
241 template <int dim, typename Number>
242 DEAL_II_ALWAYS_INLINE inline Number
243 Indicator<dim, Number>::alpha(const Number hd_i) const
244 {
245 /* Entropy viscosity commutator: */
246
247 Number numerator = left;
248 Number denominator = std::abs(left);
249 for (unsigned int k = 0; k < problem_dimension; ++k) {
250 numerator -= d_eta_i[k] * right[k];
251 denominator += std::abs(d_eta_i[k] * right[k]);
252 }
253
254 const auto quotient =
255 std::abs(numerator) / (denominator + hd_i * std::abs(eta_i));
256
257 return std::min(Number(1.), parameters.evc_factor() * quotient);
258 }
259 } // namespace Euler
260} // namespace ryujin
typename get_value_type< Number >::type ScalarNumber
dealii::Tensor< 1, problem_dimension, dealii::Tensor< 1, dim, Number > > flux_type
Vectors::MultiComponentVector< ScalarNumber, n_precomputed_values > PrecomputedVector
static constexpr unsigned int problem_dimension
dealii::Tensor< 1, problem_dimension, Number > state_type
std::array< Number, n_precomputed_values > precomputed_type
IndicatorParameters(const std::string &subsection="/Indicator")
Definition: indicator.h:25
void accumulate(const unsigned int *js, const state_type &U_j, const dealii::Tensor< 1, dim, Number > &c_ij)
Definition: indicator.h:212
typename View::state_type state_type
Definition: indicator.h:95
IndicatorParameters< ScalarNumber > Parameters
Definition: indicator.h:103
Number alpha(const Number h_i) const
Definition: indicator.h:243
typename View::flux_type flux_type
Definition: indicator.h:97
typename View::precomputed_type precomputed_type
Definition: indicator.h:99
typename View::ScalarNumber ScalarNumber
Definition: indicator.h:91
typename View::PrecomputedVector PrecomputedVector
Definition: indicator.h:101
Indicator(const HyperbolicSystem &hyperbolic_system, const Parameters &parameters, const PrecomputedVector &precomputed_values)
Definition: indicator.h:128
void reset(const unsigned int i, const state_type &U_i)
Definition: indicator.h:189
static constexpr auto problem_dimension
Definition: indicator.h:93