Finite Volume Solver  prototype
A framework to build finite volume solvers for the AG Klein at the Freie Universität Berlin.
IdealGasMix.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_IDEAL_GAS_MIX_HPP
22 #define FUB_EQUATIONS_IDEAL_GAS_MIX_HPP
23 
25 
26 #include "fub/CompleteFromCons.hpp"
27 #include "fub/Equation.hpp"
28 #include "fub/State.hpp"
29 #include "fub/ext/Eigen.hpp"
30 
31 #include <array>
32 
33 namespace fub {
34 
35 /// This is a template class for constructing conservative states for the
36 /// perfect gas equations.
37 template <typename Density, typename Momentum, typename Energy,
38  typename Species>
44 };
45 
46 template <int Rank>
49  VectorDepth<-1>>;
50 
51 // We "register" the conservative state with our framework.
52 // This enables us to name and iterate over all member variables in a given
53 // conservative state.
54 template <typename... Xs> struct StateTraits<IdealGasMixConservative<Xs...>> {
55  static constexpr auto names =
56  std::make_tuple("Density", "Momentum", "Energy", "Species");
57 
58  static constexpr auto pointers_to_member =
63 
64  template <int Rank> using Depths = IdealGasConservativeShape<Rank>;
65 };
66 
67 template <typename Density, typename Momentum, typename Energy,
68  typename Species, typename Pressure, typename SpeedOfSound,
69  typename Temperature, typename HeatCapacityAtConstantPressure,
70  typename HeatCapacityRatio>
72  : IdealGasMixConservative<Density, Momentum, Energy, Species> {
76  HeatCapacityAtConstantPressure c_p;
77  HeatCapacityRatio gamma;
78 };
79 
80 template <int Rank>
85 
86 // We "register" the complete state with our framework.
87 // This enables us to name and iterate over all member variables in a given
88 // compete state.
89 template <typename... Xs> struct StateTraits<IdealGasMixComplete<Xs...>> {
90  static constexpr auto names = std::make_tuple(
91  "Density", "Momentum", "Energy", "Species", "Pressure", "SpeedOfSound",
92  "Temperature", "HeatCapacityAtConstantPressure", "HeatCapacityRatio");
93  static constexpr auto pointers_to_member = std::make_tuple(
101 
102  template <int Rank> using Depths = IdealGasMixCompleteShape<Rank>;
103 };
104 
105 template <int N> class IdealGasMix {
106 public:
109 
113 
117 
118  explicit IdealGasMix(const FlameMasterReactor& reactor)
119  : reactor_(std::move(reactor)) {}
120 
121  static constexpr int Rank() noexcept { return N; }
122 
123  void Flux(Conservative& flux, const Complete& state,
124  Direction dir = Direction::X) const noexcept;
125 
126  void Flux(ConservativeArray& flux, const CompleteArray& state,
127  Direction dir = Direction::X) const noexcept;
128 
129  void Flux(ConservativeArray& flux, const CompleteArray& state, MaskArray mask,
130  Direction dir) const noexcept;
131 
132  void CompleteFromCons(Complete& state, const ConservativeBase& cons);
133 
135  const ConservativeArrayBase& cons);
136 
138  MaskArray mask);
139 
140  FlameMasterReactor& GetReactor() noexcept { return reactor_; }
141  const FlameMasterReactor& GetReactor() const noexcept { return reactor_; }
142 
144 
145  static Array<double, N, 1> Velocity(const ConservativeBase& cons) noexcept;
146  static Array<double, N> Velocity(const ConservativeArrayBase& cons) noexcept;
148  MaskArray mask) noexcept;
149 
151  const Eigen::Array<double, N, 1>& velocity =
152  Eigen::Array<double, N, 1>::Zero()) const;
153 
155  CompleteArray& state,
156  const Array<double, N>& velocity = Array<double, N>::Zero()) const;
157 
159  const Array<double, N>& velocit,
160  MaskArray mask) const;
161 
162 private:
165 
166  template <typename State>
167  friend constexpr auto tag_invoke(tag_t<Depths>, const IdealGasMix& equation,
168  Type<State>) noexcept {
170  depths.species = equation.reactor_.GetNSpecies();
171  return depths;
172  }
173 };
174 
175 // We define this class only for dimensions 1 to 3.
176 // The definitions will be found in its source file IdealGasMix.cpp
177 extern template class IdealGasMix<1>;
178 extern template class IdealGasMix<2>;
179 extern template class IdealGasMix<3>;
180 
181 template <int Dim>
182 double KineticEnergy(double density,
183  const Eigen::Array<double, Dim, 1>& momentum) noexcept {
184  return 0.5 * momentum.matrix().squaredNorm() / density;
185 }
186 
187 template <int Dim>
189  const Eigen::Array<double, Dim, kDefaultChunkSize,
190  Eigen::RowMajor>& momentum) noexcept {
191  Array1d square = Array1d::Zero();
192  for (int i = 0; i < Dim; ++i) {
193  square += momentum.row(i) * momentum.row(i);
194  }
195  return Array1d::Constant(0.5) * square / density;
196 }
197 
198 template <int Dim>
200  const Eigen::Array<double, Dim, kDefaultChunkSize,
201  Eigen::RowMajor>& momentum,
202  MaskArray mask) noexcept {
203  Array1d square = Array1d::Zero();
204  for (int i = 0; i < Dim; ++i) {
205  Array1d rhou = mask.select(momentum.row(i), 0.0);
206  square += rhou * rhou;
207  }
208  Array1d density_s = mask.select(density, 1.0);
209  return Array1d::Constant(0.5) * square / density_s;
210 }
211 
212 /// @{
213 /// \brief Defines how to rotate a given state of the euler equations.
214 ///
215 /// This function is needed when computing the reference state in the boundary
216 /// flux of the cut-cell stabilizations.
218  const Conservative<IdealGasMix<2>>& state,
219  const Eigen::Matrix<double, 2, 2>& rotation, const IdealGasMix<2>&);
220 
222  const Complete<IdealGasMix<2>>& state,
223  const Eigen::Matrix<double, 2, 2>& rotation, const IdealGasMix<2>&);
224 
226  const Conservative<IdealGasMix<3>>& state,
227  const Eigen::Matrix<double, 3, 3>& rotation, const IdealGasMix<3>&);
228 
230  const Complete<IdealGasMix<3>>& state,
231  const Eigen::Matrix<double, 3, 3>& rotation, const IdealGasMix<3>&);
232 /// @}
233 
234 void Reflect(Complete<IdealGasMix<1>>& reflected,
235  const Complete<IdealGasMix<1>>& state,
236  const Eigen::Matrix<double, 1, 1>& normal,
237  const IdealGasMix<1>& gas);
238 
239 void Reflect(Complete<IdealGasMix<2>>& reflected,
240  const Complete<IdealGasMix<2>>& state,
241  const Eigen::Vector2d& normal, const IdealGasMix<2>& gas);
242 
243 void Reflect(Complete<IdealGasMix<3>>& reflected,
244  const Complete<IdealGasMix<3>>& state,
245  const Eigen::Vector3d& normal, const IdealGasMix<3>& gas);
246 
247 } // namespace fub
248 
249 #endif
A class mimicking the IdealGasMix / Reactor / ReactorNet interface of Cantera, but with FlameMaster c...
Definition: FlameMasterReactor.hpp:159
int GetNSpecies() const
Return the number of species in the mechanism.
Definition: FlameMasterReactor.hpp:345
Definition: IdealGasMix.hpp:105
void Flux(Conservative &flux, const Complete &state, Direction dir=Direction::X) const noexcept
IdealGasMix(const FlameMasterReactor &reactor)
Definition: IdealGasMix.hpp:118
const FlameMasterReactor & GetReactor() const noexcept
Definition: IdealGasMix.hpp:141
static Array< double, N > Velocity(const ConservativeArrayBase &cons, MaskArray mask) noexcept
::fub::ConservativeArrayBase< IdealGasMix< N > > ConservativeArrayBase
Definition: IdealGasMix.hpp:115
FlameMasterReactor reactor_
Definition: IdealGasMix.hpp:163
void CompleteFromReactor(CompleteArray &state, const Array< double, N > &velocit, MaskArray mask) const
Array< double, Eigen::Dynamic, 1 > species_buffer_
Definition: IdealGasMix.hpp:164
::fub::ConservativeBase< IdealGasMix< N > > ConservativeBase
Definition: IdealGasMix.hpp:111
FlameMasterReactor & GetReactor() noexcept
Definition: IdealGasMix.hpp:140
void CompleteFromReactor(Complete &state, const Eigen::Array< double, N, 1 > &velocity=Eigen::Array< double, N, 1 >::Zero()) const
static Array< double, N, 1 > Velocity(const ConservativeBase &cons) noexcept
static Array< double, N > Velocity(const ConservativeArrayBase &cons) noexcept
static constexpr int Rank() noexcept
Definition: IdealGasMix.hpp:121
constexpr friend auto tag_invoke(tag_t< Depths >, const IdealGasMix &equation, Type< State >) noexcept
Definition: IdealGasMix.hpp:167
void Flux(ConservativeArray &flux, const CompleteArray &state, MaskArray mask, Direction dir) const noexcept
void CompleteFromCons(Complete &state, const ConservativeBase &cons)
void CompleteFromReactor(CompleteArray &state, const Array< double, N > &velocity=Array< double, N >::Zero()) const
void SetReactorStateFromComplete(const Complete &state)
void Flux(ConservativeArray &flux, const CompleteArray &state, Direction dir=Direction::X) const noexcept
void CompleteFromCons(CompleteArray &state, const ConservativeArrayBase &cons, MaskArray mask)
void CompleteFromCons(CompleteArray &state, const ConservativeArrayBase &cons)
constexpr struct fub::euler::SpeedOfSoundFn SpeedOfSound
constexpr struct fub::euler::EnergyFn Energy
constexpr struct fub::euler::SpeciesFn Species
constexpr struct fub::euler::PressureFn Pressure
constexpr struct fub::euler::MomentumFn Momentum
constexpr struct fub::euler::DensityFn Density
constexpr struct fub::euler::TemperatureFn Temperature
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
double KineticEnergy(double density, const Eigen::Array< double, Dim, 1 > &momentum) noexcept
Definition: IdealGasMix.hpp:182
Array< double, 1 > Array1d
Definition: Eigen.hpp:53
constexpr const int kDefaultChunkSize
Definition: Eigen.hpp:39
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.
Direction
This is a type safe type to denote a dimensional split direction.
Definition: Direction.hpp:30
boost::mp11::mp_transform< ToConcreteDepth, Depths > ToConcreteDepths
Definition: State.hpp:122
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
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: IdealGasMix.hpp:72
HeatCapacityRatio gamma
Definition: IdealGasMix.hpp:77
SpeedOfSound speed_of_sound
Definition: IdealGasMix.hpp:74
HeatCapacityAtConstantPressure c_p
Definition: IdealGasMix.hpp:76
Pressure pressure
Definition: IdealGasMix.hpp:73
Temperature temperature
Definition: IdealGasMix.hpp:75
This is a template class for constructing conservative states for the perfect gas equations.
Definition: IdealGasMix.hpp:39
Momentum momentum
Definition: IdealGasMix.hpp:41
Energy energy
Definition: IdealGasMix.hpp:42
Density density
Definition: IdealGasMix.hpp:40
Species species
Definition: IdealGasMix.hpp:43
This type is used to tag scalar quantities.
Definition: State.hpp:109
Definition: State.hpp:35
Definition: State.hpp:162
This type is used to tag quantities with a depth known at compile time.
Definition: State.hpp:112