ryujin 2.1.1 revision ee5cbcbf2346c1299c942d0e1f13b46449973c18
Loading...
Searching...
No Matches
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 - 2026 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#include <observer_pointer.h>
16
17#include <deal.II/base/parameter_acceptor.h>
18#include <deal.II/base/vectorization.h>
19
20
21namespace ryujin
22{
23 namespace ShallowWater
24 {
25 template <int dim, typename Number = double>
26 class IndicatorView;
27
34 template <typename ScalarNumber = double>
35 class Indicator : public dealii::ParameterAcceptor
36 {
37 public:
42
47 template <int dim, typename Number = double>
49
51
55
59 Indicator(const HyperbolicSystem &hyperbolic_system,
60 const std::string &subsection = "/Indicator")
61 : ParameterAcceptor(subsection)
62 , hyperbolic_system_(&hyperbolic_system)
63 {
64 evc_factor_ = ScalarNumber(1.);
65 add_parameter("evc factor",
66 evc_factor_,
67 "Factor for scaling the entropy viscocity commuator");
68 }
69
71
75
76 ACCESSOR_READ_ONLY(evc_factor);
77
83 template <int dim, typename Number>
84 auto view() const
85 {
86 return View<dim, Number>{
87 hyperbolic_system_->template view<dim, Number>(), *this};
88 }
89
90 private:
92
96
97 ScalarNumber evc_factor_;
98
100
104
105 dealii::ObserverPointer<const HyperbolicSystem> hyperbolic_system_;
106
108 };
109
110
119 template <int dim, typename Number>
121 {
122 public:
127
129
131
133
134 using state_type = typename View::state_type;
135
136 using flux_type = typename View::flux_type;
137
139
141
143
161
166 IndicatorView(const View &view, const Indicator<ScalarNumber> &indicator)
167 : view_(view)
168 , indicator_(indicator)
169 {
170 }
171
176 void reset(const PrecomputedVectorView &pv,
177 const unsigned int /*i*/,
178 const state_type &U_i);
179
184 void accumulate(const PrecomputedVectorView &pv,
185 const unsigned int *js,
186 const state_type &U_j,
187 const dealii::Tensor<1, dim, Number> &c_ij);
188
192 Number alpha(const Number h_i);
193
194
195 private:
197
201
202 const View view_;
203 const Indicator<ScalarNumber> &indicator_;
204
205 Number h_i_ = 0.;
206 Number eta_i_ = 0.;
207 flux_type f_i_;
208 state_type d_eta_i_;
209 Number pressure_i_ = 0.;
210
211 Number left_ = 0.;
212 state_type right_;
214 };
215
216
217 /*
218 * -------------------------------------------------------------------------
219 * Inline definitions
220 * -------------------------------------------------------------------------
221 */
222
223
224 template <int dim, typename Number>
225 DEAL_II_ALWAYS_INLINE inline void
227 const unsigned int i,
228 const state_type &U_i)
229 {
230 /* entropy viscosity commutator: */
231
232 const auto &[eta_m, h_star] =
233 pv.template read_tensor<Number, precomputed_type>(i);
234
235 h_i_ = view_.water_depth(U_i);
236 eta_i_ = eta_m;
237 d_eta_i_ = view_.mathematical_entropy_derivative(U_i);
238 f_i_ = view_.f(U_i);
239 pressure_i_ = view_.pressure(U_i);
240
241 left_ = 0.;
242 right_ = 0.;
243 }
244
245
246 template <int dim, typename Number>
247 DEAL_II_ALWAYS_INLINE inline void IndicatorView<dim, Number>::accumulate(
248 const PrecomputedVectorView &pv,
249 const unsigned int *js,
250 const state_type &U_j,
251 const dealii::Tensor<1, dim, Number> &c_ij)
252 {
253 /* entropy viscosity commutator: */
254
255 const auto &[eta_j, h_star_j] =
256 pv.template read_tensor<Number, precomputed_type>(js);
257
258 const auto velocity_j =
259 view_.momentum(U_j) * view_.inverse_water_depth_sharp(U_j);
260 const auto f_j = view_.f(U_j);
261 const auto pressure_j = view_.pressure(U_j);
262
263 left_ += (eta_j + pressure_j) * (velocity_j * c_ij);
264
265 for (unsigned int k = 0; k < problem_dimension; ++k)
266 right_[k] += (f_j[k] - f_i_[k]) * c_ij;
267 }
268
269
270 template <int dim, typename Number>
271 DEAL_II_ALWAYS_INLINE inline Number
273 {
274 Number my_sum = 0.;
275 for (unsigned int k = 0; k < problem_dimension; ++k) {
276 my_sum += d_eta_i_[k] * right_[k];
277 }
278
279 Number numerator = std::abs(left_ - my_sum);
280 Number denominator = std::abs(left_) + std::abs(my_sum);
281
282 const auto regularization =
283 Number(100. * std::numeric_limits<ScalarNumber>::min());
284
285 const auto quotient =
286 std::abs(numerator) /
287 (denominator + std::max(hd_i * std::abs(eta_i_), regularization));
288
289 return std::min(Number(1.), indicator_.evc_factor() * quotient);
290 }
291
292
293 } // namespace ShallowWater
294} // namespace ryujin
dealii::Tensor< 1, problem_dimension, dealii::Tensor< 1, dim, Number > > flux_type
typename get_value_type< Number >::type ScalarNumber
dealii::Tensor< 1, problem_dimension, Number > state_type
Vectors::MultiComponentVectorView< ScalarNumber, n_precomputed_values, dealii::VectorizedArray< ScalarNumber >::size(), dealii::MemorySpace::Host, false > PrecomputedVectorView
std::array< Number, n_precomputed_values > precomputed_type
static constexpr unsigned int problem_dimension
typename View::ScalarNumber ScalarNumber
Definition indicator.h:130
IndicatorView(const View &view, const Indicator< ScalarNumber > &indicator)
Definition indicator.h:166
void reset(const PrecomputedVectorView &pv, const unsigned int, const state_type &U_i)
Definition indicator.h:226
typename View::PrecomputedVectorView PrecomputedVectorView
Definition indicator.h:140
HyperbolicSystemView< dim, Number > View
Definition indicator.h:128
void accumulate(const PrecomputedVectorView &pv, const unsigned int *js, const state_type &U_j, const dealii::Tensor< 1, dim, Number > &c_ij)
Definition indicator.h:247
Number alpha(const Number h_i)
Definition indicator.h:272
typename View::flux_type flux_type
Definition indicator.h:136
typename View::state_type state_type
Definition indicator.h:134
static constexpr auto problem_dimension
Definition indicator.h:132
typename View::precomputed_type precomputed_type
Definition indicator.h:138
Indicator(const HyperbolicSystem &hyperbolic_system, const std::string &subsection="/Indicator")
Definition indicator.h:59