Loading [MathJax]/extensions/tex2jax.js
Finite Volume Solver  prototype
A framework to build finite volume solvers for the AG Klein at the Freie Universität Berlin.
•All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
PerfectGas.hpp
Go to the documentation of this file.
1 // Copyright (c) 2019 Maikel Nadolski
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 // SOFTWARE.
20 
21 #ifndef FUB_EQUATIONS_PERFECT_GAS_HPP
22 #define FUB_EQUATIONS_PERFECT_GAS_HPP
23 
24 #include "fub/State.hpp"
25 #include "fub/StateArray.hpp"
26 
27 #include "fub/CompleteFromCons.hpp"
28 #include "fub/Equation.hpp"
29 #include "fub/ext/Eigen.hpp"
30 
32 
33 #include <array>
34 
35 namespace fub {
36 template <int Rank> struct PerfectGas;
37 
38 /// This is a template class for constructing conservative states for the
39 /// perfect gas equations.
40 template <typename Density, typename Momentum, typename Energy>
45 };
46 
47 template <int Rank>
50 
51 namespace meta {
52 template <int R>
54 } // namespace meta
55 
56 // We "register" the conservative state with our framework.
57 // This enables us to name and iterate over all member variables in a given
58 // conservative state.
59 template <typename... Xs> struct StateTraits<PerfectGasConservative<Xs...>> {
60  static constexpr auto names =
61  std::make_tuple("Density", "Momentum", "Energy");
62 
63  static constexpr auto pointers_to_member =
67 
68  template <int Rank> using Depths = PerfectGasConsShape<Rank>;
69 
70  template <int Rank> using Equation = PerfectGas<Rank>;
71 };
72 
73 template <typename Density, typename Velocity, typename Pressure>
78 };
79 
80 template <int Rank>
83 
84 namespace meta {
85 template <int R>
87 } // namespace meta
88 
89 template <typename... Xs> struct StateTraits<PerfectGasPrimitive<Xs...>> {
90  static constexpr auto names =
91  std::make_tuple("Density", "Velocity", "Pressure");
92 
93  static constexpr auto pointers_to_member =
94  std::make_tuple(&PerfectGasPrimitive<Xs...>::density,
97 
98  template <int Rank> using Depths = PerfectGasPrimShape<Rank>;
99 
100  template <int Rank> using Equation = PerfectGas<Rank>;
101 };
102 
103 template <typename Minus, typename Zero, typename Plus>
105  Minus minus;
106  Zero zero;
107  Plus plus;
108 };
109 
110 template <int Rank>
113 
114 namespace meta {
115 template <int R>
117 } // namespace meta
118 
119 template <typename... Xs> struct StateTraits<PerfectGasCharacteristics<Xs...>> {
120  static constexpr auto names = std::make_tuple("Minus", "Zero", "Plus");
121 
122  static constexpr auto pointers_to_member =
126 
127  template <int Rank> using Depths = PerfectGasCharShape<Rank>;
128 
129  template <int Rank> using Equation = PerfectGas<Rank>;
130 };
131 
132 template <typename Density, typename Momentum, typename Energy,
133  typename Pressure, typename SpeedOfSound>
134 struct PerfectGasComplete : PerfectGasConservative<Density, Momentum, Energy> {
137 };
138 
139 template <int Rank>
142  ScalarDepth>;
143 
144 namespace meta {
145 template <int R>
147 } // namespace meta
148 
149 // We "register" the complete state with our framework.
150 // This enables us to name and iterate over all member variables in a given
151 // compete state.
152 template <typename... Xs> struct StateTraits<PerfectGasComplete<Xs...>> {
153  static constexpr auto names = std::make_tuple("Density", "Momentum", "Energy",
154  "Pressure", "SpeedOfSound");
155  static constexpr auto pointers_to_member = std::make_tuple(
159 
160  template <int Rank> using Depths = PerfectGasCompleteShape<Rank>;
161 };
162 template <int Rank> struct PerfectGas;
163 
164 template <int N> struct PerfectGas {
169 
174 
175  static constexpr int Rank() noexcept { return N; }
176 
177  void Flux(Conservative& flux, const Complete& state,
178  [[maybe_unused]] Direction dir = Direction::X) const noexcept;
179 
180  void Flux(ConservativeArray& flux, const CompleteArray& state,
181  [[maybe_unused]] Direction dir) const noexcept;
182 
183  void Flux(ConservativeArray& flux, const CompleteArray& state, MaskArray mask,
184  [[maybe_unused]] Direction dir) const noexcept;
185 
186  void
188  const ConservativeBase<PerfectGas>& cons) const noexcept;
189 
191  CompleteArray& complete,
192  const ConservativeArrayBase<PerfectGas>& cons) const noexcept;
193 
196  MaskArray mask) const noexcept;
197 
199  double pressure) const noexcept;
200 
202  Array1d pressure) const noexcept;
203 
205  Array1d pressure,
206  const MaskArray& mask) const noexcept;
207 
208  Array<double, N, 1> Velocity(const Complete& q) const noexcept;
209  Array<double, N> Velocity(const CompleteArray& q) const noexcept;
210 
211  double Machnumber(const Complete& q) const noexcept;
212 
213  double Temperature(const Complete& q) const noexcept;
214  Array1d Temperature(const CompleteArray& q) const noexcept;
215 
216  double Rspec{287.058};
217 
218  double gamma{1.4};
219  double gamma_minus_1_inv{1.0 / (gamma - 1.0)};
220 
221  Array1d gamma_array_{Array1d::Constant(gamma)};
223 
224 private:
225  template <typename Density, typename Momentum, typename Energy>
226  friend auto tag_invoke(
227  tag_t<euler::Gamma>, const PerfectGas& eq,
229  if constexpr (std::is_same_v<double, Density>) {
230  return eq.gamma;
231  } else {
232  return Array1d::Constant(eq.gamma);
233  }
234  }
235 
236  template <typename Density, typename Momentum, typename Energy>
237  friend const Density& tag_invoke(
240  return q.density;
241  }
242 
243  template <typename Density, typename Momentum, typename Energy>
244  friend const Momentum& tag_invoke(
247  return q.momentum;
248  }
249 
250  template <typename Density, typename Momentum, typename Energy>
251  friend decltype(auto)
254  int d) noexcept {
255  if constexpr (std::is_same_v<double, Density>) {
256  return q.momentum[d];
257  } else {
258  return q.row(d);
259  }
260  }
261 
262  template <typename Density, typename Momentum, typename Energy>
266  return q.momentum / q.density;
267  }
268 
269  template <typename Density, typename Momentum, typename Energy>
270  friend auto
273  int d) noexcept {
274  if constexpr (std::is_same_v<double, Density>) {
275  return q.momentum[d] / q.density;
276  } else {
277  return q.row(d) / q.density;
278  }
279  }
280 
281  template <typename Density, typename Momentum, typename Energy>
282  friend const Energy& tag_invoke(
285  return q.energy;
286  }
287 
288  template <typename Density, typename Momentum, typename Energy,
289  typename Pressure, typename SpeedOfSound>
290  friend const Pressure&
293  SpeedOfSound>& q) noexcept {
294  return q.pressure;
295  }
296 
297  template <typename Density, typename Momentum, typename Energy,
298  typename Pressure, typename SpeedOfSound>
299  friend const SpeedOfSound&
302  SpeedOfSound>& q) noexcept {
303  return q.speed_of_sound;
304  }
305 };
306 
307 // We define this class only for dimensions 1 to 3.
308 // The definitions will be found in its source file PerfetGas.cpp
309 extern template struct PerfectGas<1>;
310 extern template struct PerfectGas<2>;
311 extern template struct PerfectGas<3>;
312 
313 template <int Rank>
314 void CompleteFromPrim(const PerfectGas<Rank>& equation,
315  Complete<PerfectGas<Rank>>& complete,
316  const Primitive<PerfectGas<Rank>>& prim) {
317  complete =
318  equation.CompleteFromPrim(prim.density, prim.velocity, prim.pressure);
319 }
320 
321 template <int Rank>
324  const Complete<PerfectGas<Rank>>& complete) {
325  prim.density = complete.density;
326  prim.pressure = complete.pressure;
327  prim.velocity = complete.momentum / complete.density;
328 }
329 
330 template <int Rank>
331 void CompleteFromPrim(const PerfectGas<Rank>& equation,
332  CompleteArray<PerfectGas<Rank>>& complete,
333  const PrimitiveArray<PerfectGas<Rank>>& prim) {
334  complete =
335  equation.CompleteFromPrim(prim.density, prim.velocity, prim.pressure);
336 }
337 
338 template <int Rank>
341  const CompleteArray<PerfectGas<Rank>>& complete) {
342  prim.density = complete.density;
343  prim.pressure = complete.pressure;
344  for (int i = 0; i < Rank; ++i) {
345  prim.velocity.row(i) = complete.momentum.row(i) / complete.density;
346  }
347 }
348 
349 /// @{
350 /// \brief Defines how to rotate a given state of the euler equations.
351 ///
352 /// This function is needed when computing the reference state in the boundary
353 /// flux of the cut-cell stabilizations.
355  const Conservative<PerfectGas<2>>& state,
356  const Eigen::Matrix<double, 2, 2>& rotation, const PerfectGas<2>&);
357 
359  const Complete<PerfectGas<2>>& state,
360  const Eigen::Matrix<double, 2, 2>& rotation, const PerfectGas<2>&);
361 
363  const Conservative<PerfectGas<3>>& state,
364  const Eigen::Matrix<double, 3, 3>& rotation, const PerfectGas<3>&);
365 
367  const Complete<PerfectGas<3>>& state,
368  const Eigen::Matrix<double, 3, 3>& rotation, const PerfectGas<3>&);
369 /// @}
370 
372  const Conservative<PerfectGas<1>>& state,
373  const Eigen::Matrix<double, 1, 1>& normal,
374  const PerfectGas<1>& gas);
375 
377  const Conservative<PerfectGas<2>>& state,
378  const Eigen::Vector2d& normal, const PerfectGas<2>& gas);
379 
381  const Conservative<PerfectGas<3>>& state,
382  const Eigen::Vector3d& normal, const PerfectGas<3>& gas);
383 
384 void Reflect(Complete<PerfectGas<1>>& reflected,
385  const Complete<PerfectGas<1>>& state,
386  const Eigen::Matrix<double, 1, 1>& normal,
387  const PerfectGas<1>& gas);
388 
389 void Reflect(Complete<PerfectGas<2>>& reflected,
390  const Complete<PerfectGas<2>>& state,
391  const Eigen::Vector2d& normal, const PerfectGas<2>& gas);
392 
393 void Reflect(Complete<PerfectGas<3>>& reflected,
394  const Complete<PerfectGas<3>>& state,
395  const Eigen::Vector3d& normal, const PerfectGas<3>& gas);
396 
397 } // namespace fub
398 
399 #endif
constexpr struct fub::euler::SpeedOfSoundFn SpeedOfSound
constexpr struct fub::euler::EnergyFn Energy
constexpr struct fub::euler::PressureFn Pressure
constexpr struct fub::euler::MomentumFn Momentum
constexpr struct fub::euler::DensityFn Density
constexpr struct fub::euler::VelocityFn Velocity
The fub namespace.
Definition: AnyBoundaryCondition.hpp:31
std::conditional_t< N==1||M==1, Eigen::Array< T, N, M >, Eigen::Array< T, N, M, Eigen::RowMajor > > Array
Definition: Eigen.hpp:50
Array< double, 1 > Array1d
Definition: Eigen.hpp:53
std::decay_t< decltype(T)> tag_t
Definition: type_traits.hpp:350
void Rotate(Conservative< IdealGasMix< 2 >> &rotated, const Conservative< IdealGasMix< 2 >> &state, const Eigen::Matrix< double, 2, 2 > &rotation, const IdealGasMix< 2 > &)
Defines how to rotate a given state of the euler equations.
void PrimFromComplete(const PerfectGas< Rank > &, Primitive< PerfectGas< Rank >> &prim, const Complete< PerfectGas< Rank >> &complete)
Definition: PerfectGas.hpp:322
void CompleteFromPrim(const PerfectGas< Rank > &equation, Complete< PerfectGas< Rank >> &complete, const Primitive< PerfectGas< Rank >> &prim)
Definition: PerfectGas.hpp:314
Direction
This is a type safe type to denote a dimensional split direction.
Definition: Direction.hpp:30
void Reflect(Complete< IdealGasMix< 1 >> &reflected, const Complete< IdealGasMix< 1 >> &state, const Eigen::Matrix< double, 1, 1 > &normal, const IdealGasMix< 1 > &gas)
Array< bool, 1 > MaskArray
Definition: Eigen.hpp:59
std::integral_constant< int, I > int_constant
Definition: type_traits.hpp:183
typename detail::ConservativeArrayBaseImpl< Eq, Width >::type ConservativeArrayBase
Definition: StateArray.hpp:132
boost::mp11::mp_transform< detail::DepthToStateValueType, typename Equation::ConservativeDepths > ConservativeBase
This type alias transforms state depths into a conservative state associated with a specified equatio...
Definition: State.hpp:247
Definition: StateArray.hpp:178
This type has a constructor which takes an equation and might allocate any dynamically sized member v...
Definition: State.hpp:335
Definition: StateArray.hpp:135
This type has a constructor which takes an equation and might allocate any dynamically sized member v...
Definition: State.hpp:251
Definition: PerfectGas.hpp:104
Minus minus
Definition: PerfectGas.hpp:105
Zero zero
Definition: PerfectGas.hpp:106
Plus plus
Definition: PerfectGas.hpp:107
Definition: PerfectGas.hpp:134
SpeedOfSound speed_of_sound
Definition: PerfectGas.hpp:136
Pressure pressure
Definition: PerfectGas.hpp:135
This is a template class for constructing conservative states for the perfect gas equations.
Definition: PerfectGas.hpp:41
Energy energy
Definition: PerfectGas.hpp:44
Momentum momentum
Definition: PerfectGas.hpp:43
Density density
Definition: PerfectGas.hpp:42
Definition: PerfectGas.hpp:74
Pressure pressure
Definition: PerfectGas.hpp:77
Velocity velocity
Definition: PerfectGas.hpp:76
Density density
Definition: PerfectGas.hpp:75
Array< double, N, 1 > Velocity(const Complete &q) const noexcept
Array1d gamma_array_
Definition: PerfectGas.hpp:221
double Machnumber(const Complete &q) const noexcept
CompleteArray CompleteFromPrim(Array1d density, const Array< double, N > &u, Array1d pressure) const noexcept
double Rspec
Definition: PerfectGas.hpp:216
friend auto tag_invoke(tag_t< euler::Velocity >, const PerfectGas &, const PerfectGasConservative< Density, Momentum, Energy > &q, int d) noexcept
Definition: PerfectGas.hpp:271
void Flux(ConservativeArray &flux, const CompleteArray &state, [[maybe_unused]] Direction dir) const noexcept
friend const Density & tag_invoke(tag_t< euler::Density >, const PerfectGas &, const PerfectGasConservative< Density, Momentum, Energy > &q) noexcept
Definition: PerfectGas.hpp:237
static constexpr int Rank() noexcept
Definition: PerfectGas.hpp:175
friend auto tag_invoke(tag_t< euler::Gamma >, const PerfectGas &eq, const PerfectGasConservative< Density, Momentum, Energy > &) noexcept
Definition: PerfectGas.hpp:226
void Flux(ConservativeArray &flux, const CompleteArray &state, MaskArray mask, [[maybe_unused]] Direction dir) const noexcept
friend const Pressure & tag_invoke(tag_t< euler::Pressure >, const PerfectGas &, const PerfectGasComplete< Density, Momentum, Energy, Pressure, SpeedOfSound > &q) noexcept
Definition: PerfectGas.hpp:291
void CompleteFromCons(Complete &complete, const ConservativeBase< PerfectGas > &cons) const noexcept
double gamma_minus_1_inv
Definition: PerfectGas.hpp:219
void Flux(Conservative &flux, const Complete &state, [[maybe_unused]] Direction dir=Direction::X) const noexcept
void CompleteFromCons(CompleteArray &complete, const ConservativeArrayBase< PerfectGas > &cons, MaskArray mask) const noexcept
void CompleteFromCons(CompleteArray &complete, const ConservativeArrayBase< PerfectGas > &cons) const noexcept
Complete CompleteFromPrim(double density, const Array< double, N, 1 > &u, double pressure) const noexcept
friend const SpeedOfSound & tag_invoke(tag_t< euler::SpeedOfSound >, const PerfectGas &, const PerfectGasComplete< Density, Momentum, Energy, Pressure, SpeedOfSound > &q) noexcept
Definition: PerfectGas.hpp:300
friend const Energy & tag_invoke(tag_t< euler::Energy >, const PerfectGas &, const PerfectGasConservative< Density, Momentum, Energy > &q) noexcept
Definition: PerfectGas.hpp:282
Array1d gamma_minus_1_inv_array_
Definition: PerfectGas.hpp:222
double Temperature(const Complete &q) const noexcept
double gamma
Definition: PerfectGas.hpp:218
Array< double, N > Velocity(const CompleteArray &q) const noexcept
friend const Momentum & tag_invoke(tag_t< euler::Momentum >, const PerfectGas &, const PerfectGasConservative< Density, Momentum, Energy > &q) noexcept
Definition: PerfectGas.hpp:244
CompleteArray CompleteFromPrim(Array1d density, const Array< double, N > &u, Array1d pressure, const MaskArray &mask) const noexcept
Array1d Temperature(const CompleteArray &q) const noexcept
friend Momentum tag_invoke(tag_t< euler::Velocity >, const PerfectGas &, const PerfectGasConservative< Density, Momentum, Energy > &q) noexcept
Definition: PerfectGas.hpp:263
Definition: StateArray.hpp:89
Definition: State.hpp:290
This type is used to tag scalar quantities.
Definition: State.hpp:109
Definition: State.hpp:35
Definition: State.hpp:39