ryujin 2.1.1 revision 46bf70e400e423a8ffffe8300887eeb35b8dfb2c
indicator.h
Go to the documentation of this file.
1//
2// SPDX-License-Identifier: Apache-2.0
3// [LANL Copyright Statement]
4// Copyright (C) 2023 - 2024 by the ryujin authors
5// Copyright (C) 2023 - 2024 by Triad National Security, LLC
6//
7
8#pragma once
9
10#include <compile_time_options.h>
11
12#include "hyperbolic_system.h"
13
15
16#include <deal.II/base/parameter_acceptor.h>
17#include <deal.II/base/vectorization.h>
18
19
20namespace ryujin
21{
22 namespace ShallowWater
23 {
24 template <typename ScalarNumber = double>
25 class IndicatorParameters : public dealii::ParameterAcceptor
26 {
27 public:
28 IndicatorParameters(const std::string &subsection = "/Indicator")
29 : ParameterAcceptor(subsection)
30 {
31 evc_factor_ = ScalarNumber(1.);
32 add_parameter("evc factor",
33 evc_factor_,
34 "Factor for scaling the entropy viscocity commuator");
35 }
36
37 ACCESSOR_READ_ONLY(evc_factor);
38
39 private:
40 ScalarNumber evc_factor_;
41 };
42
43
50 template <int dim, typename Number = double>
52 {
53 public:
58
60
62
64
65 using state_type = typename View::state_type;
66
67 using flux_type = typename View::flux_type;
68
70
72
74
76
94
98 Indicator(const HyperbolicSystem &hyperbolic_system,
99 const Parameters &parameters,
100 const PrecomputedVector &precomputed_values)
101 : hyperbolic_system(hyperbolic_system)
102 , parameters(parameters)
103 , precomputed_values(precomputed_values)
104 {
105 }
106
111 void reset(const unsigned int /*i*/, const state_type &U_i);
112
117 void accumulate(const unsigned int *js,
118 const state_type &U_j,
119 const dealii::Tensor<1, dim, Number> &c_ij);
120
124 Number alpha(const Number h_i);
125
127
128 private:
133
134 const HyperbolicSystem &hyperbolic_system;
135 const Parameters &parameters;
136 const PrecomputedVector &precomputed_values;
137
138 Number h_i = 0.;
139 Number eta_i = 0.;
140 flux_type f_i;
141 state_type d_eta_i;
142 Number pressure_i = 0.;
143
144 Number left = 0.;
145 state_type right;
147 };
148
149
150 /*
151 * -------------------------------------------------------------------------
152 * Inline definitions
153 * -------------------------------------------------------------------------
154 */
155
156
157 template <int dim, typename Number>
158 DEAL_II_ALWAYS_INLINE inline void
159 Indicator<dim, Number>::reset(const unsigned int i, const state_type &U_i)
160 {
161 /* entropy viscosity commutator: */
162
163 const auto view = hyperbolic_system.view<dim, Number>();
164
165 const auto &[eta_m, h_star] =
166 precomputed_values.template get_tensor<Number, precomputed_type>(i);
167
168 h_i = view.water_depth(U_i);
169 eta_i = eta_m;
170 d_eta_i = view.mathematical_entropy_derivative(U_i);
171 f_i = view.f(U_i);
172 pressure_i = view.pressure(U_i);
173
174 left = 0.;
175 right = 0.;
176 }
177
178
179 template <int dim, typename Number>
180 DEAL_II_ALWAYS_INLINE inline void Indicator<dim, Number>::accumulate(
181 const unsigned int *js,
182 const state_type &U_j,
183 const dealii::Tensor<1, dim, Number> &c_ij)
184 {
185 /* entropy viscosity commutator: */
186
187 const auto view = hyperbolic_system.view<dim, Number>();
188
189 const auto &[eta_j, h_star_j] =
190 precomputed_values.template get_tensor<Number, precomputed_type>(js);
191
192 const auto velocity_j =
193 view.momentum(U_j) * view.inverse_water_depth_sharp(U_j);
194 const auto f_j = view.f(U_j);
195 const auto pressure_j = view.pressure(U_j);
196
197 left += (eta_j + pressure_j) * (velocity_j * c_ij);
198
199 for (unsigned int k = 0; k < problem_dimension; ++k)
200 right[k] += (f_j[k] - f_i[k]) * c_ij;
201 }
202
203
204 template <int dim, typename Number>
205 DEAL_II_ALWAYS_INLINE inline Number
207 {
208 Number my_sum = 0.;
209 for (unsigned int k = 0; k < problem_dimension; ++k) {
210 my_sum += d_eta_i[k] * right[k];
211 }
212
213 Number numerator = std::abs(left - my_sum);
214 Number denominator = std::abs(left) + std::abs(my_sum);
215
216 const auto regularization =
217 Number(100. * std::numeric_limits<ScalarNumber>::min());
218
219 const auto quotient =
220 std::abs(numerator) /
221 (denominator + std::max(hd_i * std::abs(eta_i), regularization));
222
223 return std::min(Number(1.), parameters.evc_factor() * quotient);
224 }
225
226
227 } // namespace ShallowWater
228} // namespace ryujin
dealii::Tensor< 1, problem_dimension, dealii::Tensor< 1, dim, Number > > flux_type
typename get_value_type< Number >::type ScalarNumber
Vectors::MultiComponentVector< ScalarNumber, n_precomputed_values > PrecomputedVector
dealii::Tensor< 1, problem_dimension, Number > state_type
std::array< Number, n_precomputed_values > precomputed_type
static constexpr unsigned int problem_dimension
IndicatorParameters(const std::string &subsection="/Indicator")
Definition: indicator.h:28
typename View::PrecomputedVector PrecomputedVector
Definition: indicator.h:71
typename View::state_type state_type
Definition: indicator.h:65
typename View::flux_type flux_type
Definition: indicator.h:67
typename View::precomputed_type precomputed_type
Definition: indicator.h:69
void reset(const unsigned int, const state_type &U_i)
Definition: indicator.h:159
void accumulate(const unsigned int *js, const state_type &U_j, const dealii::Tensor< 1, dim, Number > &c_ij)
Definition: indicator.h:180
static constexpr auto problem_dimension
Definition: indicator.h:63
typename View::ScalarNumber ScalarNumber
Definition: indicator.h:61
Indicator(const HyperbolicSystem &hyperbolic_system, const Parameters &parameters, const PrecomputedVector &precomputed_values)
Definition: indicator.h:98
Number alpha(const Number h_i)
Definition: indicator.h:206
IndicatorParameters< ScalarNumber > Parameters
Definition: indicator.h:73