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 Euler
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
99
103 static constexpr unsigned int n_precomputed_values =
105
109 using state_type = typename View::state_type;
110
114 using flux_type = typename View::flux_type;
115
120
125
144
148 Indicator(const HyperbolicSystem &hyperbolic_system,
149 const Parameters &parameters,
151 &precomputed_values)
152 : hyperbolic_system(hyperbolic_system)
153 , parameters(parameters)
154 , precomputed_values(precomputed_values)
155 {
156 }
157
162 void reset(const unsigned int i, const state_type &U_i);
163
168 void accumulate(const unsigned int *js,
169 const state_type &U_j,
170 const dealii::Tensor<1, dim, Number> &c_ij);
171
175 Number alpha(const Number h_i) const;
176
178
179 private:
184
185 const HyperbolicSystem &hyperbolic_system;
186 const Parameters &parameters;
187
189 &precomputed_values;
190
191 Number rho_i_inverse = 0.;
192 Number eta_i = 0.;
193 flux_type f_i;
194 state_type d_eta_i;
195
196 Number left = 0.;
197 state_type right;
198
200 };
201
202
203 /*
204 * -------------------------------------------------------------------------
205 * Inline definitions
206 * -------------------------------------------------------------------------
207 */
208
209
210 template <int dim, typename Number>
211 DEAL_II_ALWAYS_INLINE inline void
212 Indicator<dim, Number>::reset(const unsigned int i, const state_type &U_i)
213 {
214 /* entropy viscosity commutator: */
215
216 const auto view = hyperbolic_system.view<dim, Number>();
217
218 const auto &[new_s_i, new_eta_i] =
219 precomputed_values
220 .template get_tensor<Number, precomputed_state_type>(i);
221
222 const auto rho_i = view.density(U_i);
223 rho_i_inverse = Number(1.) / rho_i;
224 eta_i = new_eta_i;
225
226 d_eta_i = view.harten_entropy_derivative(U_i);
227 d_eta_i[0] -= eta_i * rho_i_inverse;
228 f_i = view.f(U_i);
229
230 left = 0.;
231 right = 0.;
232 }
233
234
235 template <int dim, typename Number>
236 DEAL_II_ALWAYS_INLINE inline void Indicator<dim, Number>::accumulate(
237 const unsigned int *js,
238 const state_type &U_j,
239 const dealii::Tensor<1, dim, Number> &c_ij)
240 {
241 /* entropy viscosity commutator: */
242
243 const auto view = hyperbolic_system.view<dim, Number>();
244
245 const auto &[s_j, eta_j] =
246 precomputed_values
247 .template get_tensor<Number, precomputed_state_type>(js);
248
249 const auto rho_j = view.density(U_j);
250 const auto rho_j_inverse = Number(1.) / rho_j;
251
252 const auto m_j = view.momentum(U_j);
253 const auto f_j = view.f(U_j);
254
255 left += (eta_j * rho_j_inverse - eta_i * rho_i_inverse) * (m_j * c_ij);
256 for (unsigned int k = 0; k < problem_dimension; ++k)
257 right[k] += (f_j[k] - f_i[k]) * c_ij;
258 }
259
260
261 template <int dim, typename Number>
262 DEAL_II_ALWAYS_INLINE inline Number
263 Indicator<dim, Number>::alpha(const Number hd_i) const
264 {
266
267 Number numerator = left;
268 Number denominator = std::abs(left);
269 for (unsigned int k = 0; k < problem_dimension; ++k) {
270 numerator -= d_eta_i[k] * right[k];
271 denominator += std::abs(d_eta_i[k] * right[k]);
272 }
273
274 const auto quotient =
275 std::abs(numerator) / (denominator + hd_i * std::abs(eta_i));
276
277 return std::min(Number(1.), parameters.evc_factor() * quotient);
278 }
279 } // namespace Euler
280} // namespace ryujin
typename get_value_type< Number >::type ScalarNumber
dealii::Tensor< 1, problem_dimension, dealii::Tensor< 1, dim, Number > > flux_type
std::array< Number, n_precomputed_values > precomputed_state_type
static constexpr unsigned int problem_dimension
dealii::Tensor< 1, problem_dimension, Number > state_type
static constexpr unsigned int n_precomputed_values
IndicatorParameters(const std::string &subsection="/Indicator")
Definition: indicator.h:26
void accumulate(const unsigned int *js, const state_type &U_j, const dealii::Tensor< 1, dim, Number > &c_ij)
Definition: indicator.h:236
typename View::state_type state_type
Definition: indicator.h:109
IndicatorParameters< ScalarNumber > Parameters
Definition: indicator.h:124
static constexpr unsigned int n_precomputed_values
Definition: indicator.h:103
Number alpha(const Number h_i) const
Definition: indicator.h:263
typename View::flux_type flux_type
Definition: indicator.h:114
Indicator(const HyperbolicSystem &hyperbolic_system, const Parameters &parameters, const MultiComponentVector< ScalarNumber, n_precomputed_values > &precomputed_values)
Definition: indicator.h:148
typename View::ScalarNumber ScalarNumber
Definition: indicator.h:119
void reset(const unsigned int i, const state_type &U_i)
Definition: indicator.h:212
typename View::precomputed_state_type precomputed_state_type
Definition: indicator.h:98
static constexpr unsigned int problem_dimension
Definition: indicator.h:93