Finite Volume Solver  prototype
A framework to build finite volume solvers for the AG Klein at the Freie Universität Berlin.
TChemReactor.hpp
Go to the documentation of this file.
1 // Copyright (c) 2018 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_IDEAL_GAS_TCHEM_REACTOR_HPP
22 #define FUB_IDEAL_GAS_TCHEM_REACTOR_HPP
23 
24 #include "fub/core/span.hpp"
25 #include "fub/ode_solver/OdeSolver.hpp"
26 
27 #include <memory>
28 #include <stdexcept>
29 #include <string>
30 #include <vector>
31 
32 namespace fub {
33 namespace ideal_gas {
34 
35 struct TChemNotInitialized : std::runtime_error {
37  : std::runtime_error(
38  "You have not initialized TChem before using this reactor.") {}
39 };
40 
41 struct TChemReactorUniqueError : std::runtime_error {
43  : std::runtime_error(
44  "Only one Reactor at the time is allowed to exist.") {}
45 };
46 
48  virtual ~TChemMechanism() = default;
49  virtual int getNSpecies() const = 0;
50  virtual const char* GetMechanismResource() const = 0;
51  virtual const char* GetThermoResource() const = 0;
52  virtual std::unique_ptr<TChemMechanism> Clone_() const = 0;
53 };
54 
55 class TChemReactor {
56 public:
57  using Feedback = OdeSolver::feedback_type;
58 
59  TChemReactor(const TChemMechanism& mechanism);
60  ~TChemReactor() noexcept;
61 
62  TChemReactor(const TChemReactor&) = delete;
63  TChemReactor& operator=(const TChemReactor&) = delete;
65  TChemReactor& operator=(TChemReactor&&) = delete;
66 
67  void SetOdeSolver(std::unique_ptr<OdeSolver> solver) {
68  ode_solver_ = std::move(solver);
69  }
70 
71  void Advance(double dt);
72  void Advance(double dt, Feedback feedback);
73 
74  int GetNSpecies() const;
75  double GetPressure() const { return pressure_; }
76  double GetDensity() const { return density_; }
77  double GetTemperature() const { return temperature_; }
78 
80  return make_span(temperature_and_mass_fractions_).subspan(1);
81  }
83  double GetMeanMolarMass() const;
86  span<const double> GetCps() const { return cps_; }
87  span<const double> GetCvs() const { return cvs_; }
90 
91  const OdeSolver& GetOdeSolver() const { return *ode_solver_; }
92 
93  double GetSpeedOfSound() const;
94  double GetInternalEnergy() const;
95  double GetCp() const;
96  double GetCv() const;
97  double GetGamma() const;
98 
99  void SetPressure(double p);
100  void SetDensity(double rho);
101  void SetTemperature(double T);
102  void SetInternalEnergy(double e, double tolerance = 1e-6);
105  void SetMoleFractions(std::string X);
106 
107  double SetPressureIsentropic(double p);
108 
110 
111  const char* GetSpeciesName(int i) const { return species_names_[i].data(); }
112 
113 private:
114  std::vector<double> temperature_and_mass_fractions_;
115  std::vector<double> moles_;
116  std::vector<double> internal_energies_;
117  std::vector<double> enthalpies_;
118  std::vector<double> cps_;
119  std::vector<double> cvs_;
120  std::vector<double> molar_masses_;
121  std::vector<std::string> species_names_;
122  double density_;
123  double pressure_;
124  double temperature_;
126  std::array<double, 2> setPVector_;
127  std::unique_ptr<OdeSolver> ode_solver_;
128 };
129 
130 } // namespace ideal_gas
131 } // namespace fub
132 
133 #endif
Definition: TChemReactor.hpp:55
std::vector< double > molar_masses_
Definition: TChemReactor.hpp:120
TChemReactor(const TChemMechanism &mechanism)
OdeSolver::feedback_type Feedback
Definition: TChemReactor.hpp:57
std::vector< double > moles_
Definition: TChemReactor.hpp:115
std::vector< double > temperature_and_mass_fractions_
Definition: TChemReactor.hpp:114
double density_
Definition: TChemReactor.hpp:122
std::vector< double > cps_
Definition: TChemReactor.hpp:118
span< const double > GetMolarMasses() const
Definition: TChemReactor.hpp:82
span< const double > GetMoleFractions() const
Definition: TChemReactor.hpp:85
void SetDensity(double rho)
double GetInternalEnergy() const
void SetOdeSolver(std::unique_ptr< OdeSolver > solver)
Definition: TChemReactor.hpp:67
void SetMassFractions(span< const double > Y)
void Advance(double dt, Feedback feedback)
double GetMeanMolarMass() const
double thermo_temperature_
Definition: TChemReactor.hpp:125
std::vector< double > cvs_
Definition: TChemReactor.hpp:119
double GetTemperature() const
Definition: TChemReactor.hpp:77
std::unique_ptr< OdeSolver > ode_solver_
Definition: TChemReactor.hpp:127
span< const double > GetCps() const
Definition: TChemReactor.hpp:86
const OdeSolver & GetOdeSolver() const
Definition: TChemReactor.hpp:91
const char * GetSpeciesName(int i) const
Definition: TChemReactor.hpp:111
span< const double > GetMassFractions() const
Definition: TChemReactor.hpp:79
double pressure_
Definition: TChemReactor.hpp:123
double SetPressureIsentropic(double p)
void SetInternalEnergy(double e, double tolerance=1e-6)
span< const double > GetEnthalpies() const
Definition: TChemReactor.hpp:88
span< const double > GetInternalEnergies() const
Definition: TChemReactor.hpp:89
double GetDensity() const
Definition: TChemReactor.hpp:76
span< const double > GetCvs() const
Definition: TChemReactor.hpp:87
std::vector< double > internal_energies_
Definition: TChemReactor.hpp:116
void SetMoleFractions(span< const double > X)
double GetPressure() const
Definition: TChemReactor.hpp:75
double GetSpeedOfSound() const
std::vector< std::string > species_names_
Definition: TChemReactor.hpp:121
span< const std::string > GetSpeciesNames() const
Definition: TChemReactor.hpp:84
void SetMoleFractions(std::string X)
std::array< double, 2 > setPVector_
Definition: TChemReactor.hpp:126
double temperature_
Definition: TChemReactor.hpp:124
std::vector< double > enthalpies_
Definition: TChemReactor.hpp:117
A span is a view over a contiguous sequence of objects, the storage of which is owned by some other o...
Definition: span.hpp:81
The fub namespace.
Definition: AnyBoundaryCondition.hpp:31
auto make_span(T(&array)[N]) -> span< T, static_cast< std::ptrdiff_t >(N)>
Definition: span.hpp:1001
Definition: TChemReactor.hpp:47
virtual ~TChemMechanism()=default
virtual const char * GetThermoResource() const =0
virtual const char * GetMechanismResource() const =0
virtual std::unique_ptr< TChemMechanism > Clone_() const =0
virtual int getNSpecies() const =0
Definition: TChemReactor.hpp:35
TChemNotInitialized()
Definition: TChemReactor.hpp:36
Definition: TChemReactor.hpp:41
TChemReactorUniqueError()
Definition: TChemReactor.hpp:42