Reaktoro 
A unified framework for modeling chemically reactive systems
CubicEOS.hpp
1 // Reaktoro is a unified framework for modeling chemically reactive systems.
2 //
3 // Copyright (C) 2014-2015 Allan Leal
4 //
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18 #pragma once
19 
20 // C++ includes
21 #include <functional>
22 #include <memory>
23 #include <string>
24 #include <tuple>
25 #include <vector>
26 
27 // Reaktoro includes
28 #include <Reaktoro/Common/ChemicalScalar.hpp>
29 #include <Reaktoro/Common/ChemicalVector.hpp>
30 #include <Reaktoro/Common/Index.hpp>
31 #include <Reaktoro/Common/TableUtils.hpp>
32 #include <Reaktoro/Common/ThermoScalar.hpp>
33 #include <Reaktoro/Common/ThermoVector.hpp>
34 
35 namespace Reaktoro {
36 
38 class CubicEOS
39 {
40 public:
42  enum Model
43  {
44  VanDerWaals, RedlichKwong, SoaveRedlichKwong, PengRobinson,
45  };
46 
48  {
49  Table2D<ThermoScalar> k;
50 
51  Table2D<ThermoScalar> kT;
52 
53  Table2D<ThermoScalar> kTT;
54  };
55 
57  {
58  const ThermoScalar& T;
59 
60  const ThermoVector& a;
61 
62  const ThermoVector& aT;
63 
64  const ThermoVector& aTT;
65 
66  const Vector& b;
67  };
68 
69  using InteractionParamsFunction =
70  std::function<InteractionParamsResult(const InteractionParamsArgs&)>;
71 
72  struct Result
73  {
75  Result();
76 
79  explicit Result(unsigned nspecies);
80 
83 
86 
89 
92 
95 
98 
101 
104 
107  };
108 
111  explicit CubicEOS(unsigned nspecies);
112 
114  CubicEOS(const CubicEOS& other);
115 
117  virtual ~CubicEOS();
118 
120  auto operator=(CubicEOS other) -> CubicEOS&;
121 
123  auto numSpecies() const -> unsigned;
124 
127  auto setModel(Model model) -> void;
128 
130  auto setPhaseAsLiquid() -> void;
131 
133  auto setPhaseAsVapor() -> void;
134 
136  auto setCriticalTemperatures(const std::vector<double>& values) -> void;
137 
139  auto setCriticalPressures(const std::vector<double>& values) -> void;
140 
142  auto setAcentricFactors(const std::vector<double>& values) -> void;
143 
146  auto setInteractionParamsFunction(const InteractionParamsFunction& func) -> void;
147 
152  auto operator()(const ThermoScalar& T, const ThermoScalar& P, const ChemicalVector& x) -> Result;
153 
154 private:
155  struct Impl;
156 
157  std::unique_ptr<Impl> pimpl;
158 };
159 
160 } // namespace Reaktoro
ChemicalScalar residual_molar_enthalpy
The residual molar enthalpy of the phase (in units of J/mol).
Definition: CubicEOS.hpp:88
ChemicalScalar residual_molar_heat_capacity_cv
The residual molar heat capacity at constant volume of the phase (in units of J/(mol*K)).
Definition: CubicEOS.hpp:94
auto setAcentricFactors(const std::vector< double > &values) -> void
Set the acentric factors of the species.
Definition: CubicEOS.cpp:479
ChemicalVector residual_partial_molar_enthalpies
The residual partial molar enthalpies of the species in the phase (in units of J/mol).
Definition: CubicEOS.hpp:103
auto setInteractionParamsFunction(const InteractionParamsFunction &func) -> void
Set the function that calculates the interaction parameters kij and its temperature derivatives...
Definition: CubicEOS.cpp:489
auto setModel(Model model) -> void
Set the type of the cubic equation of state (default: PengRobinson).
Definition: CubicEOS.cpp:436
auto numSpecies() const -> unsigned
Return the number of species in the phase.
Definition: CubicEOS.cpp:431
STL namespace.
Defines a cubic equation of state and calculates thermodynamic properties of a fluid phase...
Definition: CubicEOS.hpp:38
ChemicalScalar residual_molar_gibbs_energy
The residual molar Gibbs energy of the phase (in units of J/mol).
Definition: CubicEOS.hpp:85
auto setPhaseAsVapor() -> void
Set the equation of state to compute properties for a vapor phase.
Definition: CubicEOS.cpp:446
ChemicalVector partial_molar_volumes
The partial molar volumes of the speies in the phase (in units of m3/mol).
Definition: CubicEOS.hpp:97
ChemicalScalar residual_molar_heat_capacity_cp
The residual molar heat capacity at constant pressure of the phase (in units of J/(mol*K)).
Definition: CubicEOS.hpp:91
Eigen::VectorXd Vector
Define an alias to the vector type of the Eigen library.
Definition: Matrix.hpp:384
Definition: CubicEOS.hpp:72
ChemicalScalar molar_volume
The molar volume of the phase (in units of m3/mol).
Definition: CubicEOS.hpp:82
auto setCriticalPressures(const std::vector< double > &values) -> void
Set the critical pressures of the species (in units of Pa).
Definition: CubicEOS.cpp:465
ChemicalVector residual_partial_molar_gibbs_energies
The residual partial molar Gibbs energies of the species in the phase (in units of J/mol)...
Definition: CubicEOS.hpp:100
virtual ~CubicEOS()
Destroy this CubicEOS instance.
Definition: CubicEOS.cpp:422
ChemicalVector ln_fugacity_coefficients
The fugacity coefficients of the species in the phase.
Definition: CubicEOS.hpp:106
auto setCriticalTemperatures(const std::vector< double > &values) -> void
Set the critical temperatures of the species (in units of K).
Definition: CubicEOS.cpp:451
The namespace containing all components of the Reaktoro library.
Definition: ChemicalScalar.hpp:24
Model
Defines the enumeration of available cubic EOS models.
Definition: CubicEOS.hpp:42
CubicEOS(unsigned nspecies)
Construct a CubicEOS instance with given number of species.
Definition: CubicEOS.cpp:414
auto operator=(CubicEOS other) -> CubicEOS &
Assign a CubicEOS instance to this.
Definition: CubicEOS.cpp:425
auto setPhaseAsLiquid() -> void
Set the equation of state to compute properties for a liquid phase.
Definition: CubicEOS.cpp:441