Reaktoro  v2.11.0
A unified framework for modeling chemically reactive systems
CubicEOS.hpp
1 // Reaktoro is a unified framework for modeling chemically reactive systems.
2 //
3 // Copyright © 2014-2024 Allan Leal
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library 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 GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this library. If not, see <http://www.gnu.org/licenses/>.
17 
18 #pragma once
19 
20 // Reaktoro includes
21 #include <Reaktoro/Common/Constants.hpp>
22 #include <Reaktoro/Common/Matrix.hpp>
23 #include <Reaktoro/Common/Types.hpp>
24 #include <Reaktoro/Core/Model.hpp>
25 #include <Reaktoro/Core/StateOfMatter.hpp>
26 
27 namespace Reaktoro {
28 namespace CubicEOS {
29 
31 struct Substance
32 {
34  real Tcr = NaN;
35  real Pcr = NaN;
37 };
38 
40 struct Props
41 {
42  real V;
43  real VT;
44  real VP;
52 };
53 
55 struct Bip
56 {
60 };
61 
62 // Note: The list of arguments below for the computation of @eq{k_{ij}} and its
63 // first and second order temperature derivatives is inspired by the binary
64 // interaction parameter model of Jaubert et al. (2004):
65 // \eqc{k_{ij}=\dfrac{-\dfrac{1}{2}\sum_{k=1}^{N_{g}}\sum_{l=1}^{N_{g}}(\alpha_{ik}-\alpha_{jk})(\alpha_{il}-\alpha_{jl})A_{kl}\cdot(298.15T^{-1})^{\left(\frac{B_{kl}}{A_{kl}}-1\right)}-\left(\dfrac{\sqrt{a_{i}}}{b_{i}}-\dfrac{\sqrt{a_{j}}}{b_{j}}\right)}{2\dfrac{\sqrt{a_{i}a_{j}}}{b_{i}b_{j}}}.}
66 
69 {
71  real const& T;
82 };
83 
85 using BipModel = Model<Bip(BipModelArgs const&)>;
86 
88 struct Alpha
89 {
93 };
94 
97 {
98  real const& Tr;
99  real const& TrT;
100  real const& omega;
101 };
102 
104 using AlphaModel = Model<Alpha(AlphaModelArgs const&)>;
105 
130 {
136 };
137 
139 auto EquationModelVanDerWaals() -> EquationModel;
140 
142 auto EquationModelRedlichKwong() -> EquationModel;
143 
145 auto EquationModelSoaveRedlichKwong() -> EquationModel;
146 
148 auto EquationModelPengRobinson76() -> EquationModel;
149 
151 auto EquationModelPengRobinson78() -> EquationModel;
152 
154 auto EquationModelPengRobinson() -> EquationModel;
155 
158 {
162 };
163 
165 class Equation
166 {
167 public:
169  explicit Equation(EquationSpecs const& specs);
170 
172  Equation(Equation const& other);
173 
175  virtual ~Equation();
176 
178  auto operator=(Equation other) -> Equation&;
179 
181  auto equationSpecs() const -> EquationSpecs const&;
182 
188  auto compute(Props& props, real const& T, real const& P, ArrayXrConstRef const& x) -> void;
189 
190 private:
191  struct Impl;
192 
193  Ptr<Impl> pimpl;
194 };
195 
199 {
200  real kH2O_CO2 = 0.19;
201  real kH2O_H2S = 0.19;
202  real kH2O_CH4 = 0.49;
203  real kH2O_N2 = 0.49;
204  real kH2O_C2H6 = 0.49;
205  real kH2O_C3H8 = 0.55;
206 };
207 
210 {
212  real kH2O_CO2 = 0.1896;
213 
215  real kH2O_N2 = 0.4778;
216 
218  real kH2O_CH4 = 0.4850;
219 
221  real kH2O_C2H6 = 0.4920;
222 
224  real kH2O_C3H8 = 0.5525;
225 
227  real kH2O_nC4H10 = 0.5525;
228 
230  real kH2O_H2S_a1 = 0.19031;
231 
233  real kH2O_H2S_a2 = -0.05965;
234 };
235 
237 auto BipModelPhreeqc(Strings const& substances, BipModelParamsPhreeqc const& params = {}) -> BipModel;
238 
240 auto BipModelSoreideWhitson(Strings const& substances, BipModelParamsSoreideWhitson const& params = {}) -> BipModel;
241 
242 // DEPRECATED METHODS TO BE REMOVED IN THE NEAR FUTURE
243 
244 struct [[deprecated("BipModelParamsPHREEQC has been deprecated and renamed to BipModelParamsPhreeqc.")]] BipModelParamsPHREEQC
245 {};
246 
247 [[deprecated("BipModelPHREEQC has been deprecated and renamed to BipModelPhreeqc.")]]
248 auto BipModelPHREEQC(Strings const& substances, BipModelParamsPHREEQC const& params = {}) -> BipModel;
249 
250 } // namespace CubicEOS
251 } // namespace Reaktoro
Calculates thermodynamic properties of fluid phases based on a cubic equation of state model.
Definition: CubicEOS.hpp:166
auto equationSpecs() const -> EquationSpecs const &
Return the underlying EquationSpecs object used to create this Equation object.
auto compute(Props &props, real const &T, real const &P, ArrayXrConstRef const &x) -> void
Compute the thermodynamic properties of the phase.
Equation(EquationSpecs const &specs)
Construct an Equation object representing a cubic equation of state.
virtual ~Equation()
Destroy this Equation object.
auto operator=(Equation other) -> Equation &
Assign an Equation object to this.
Equation(Equation const &other)
Construct a copy of an Equation object.
The namespace containing all components of the Reaktoro library.
Definition: Algorithms.hpp:29
autodiff::MatrixXreal MatrixXr
Convenient alias to Eigen type.
Definition: Matrix.hpp:131
std::vector< T > Vec
Convenient alias for std::vector<T>.
Definition: Types.hpp:66
constexpr auto NaN
The value of NaN.
Definition: Constants.hpp:65
std::string String
Convenient alias for std::string.
Definition: Types.hpp:52
autodiff::real real
The number type used throughout the library.
Definition: Real.hpp:26
std::vector< std::string > Strings
Convenient alias for std::vector<String>.
Definition: Types.hpp:55
std::unique_ptr< T > Ptr
Convenient alias for std::unique_ptr<T>.
Definition: Types.hpp:102
StateOfMatter
The list of states of matter for phases.
Definition: StateOfMatter.hpp:27
Eigen::Ref< const ArrayXr > ArrayXrConstRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:89
autodiff::ArrayXreal ArrayXr
Convenient alias to Eigen type.
Definition: Matrix.hpp:87
The arguments for the evaluation of a function in a cubic equation of state.
Definition: CubicEOS.hpp:97
real const & Tr
The reduced temperature with respect to the substance for which is computed.
Definition: CubicEOS.hpp:98
real const & omega
The acentric factor of the substance for which is computed.
Definition: CubicEOS.hpp:100
real const & TrT
The first-order temperature derivative of for convenience.
Definition: CubicEOS.hpp:99
The value and temperature derivatives of the function in a cubic equation of state.
Definition: CubicEOS.hpp:89
real alphaT
The evaluated first-order temperature derivative of the function.
Definition: CubicEOS.hpp:91
real alpha
The evaluated value of the function in a cubic equation of state.
Definition: CubicEOS.hpp:90
real alphaTT
The evaluated second-order temperature derivative of the function.
Definition: CubicEOS.hpp:92
The arguments for the evaluation of binary interaction parameters in a cubic equation of state.
Definition: CubicEOS.hpp:69
ArrayXrConstRef Tcr
The critical temperatures of the substances in the fluid phase (in K).
Definition: CubicEOS.hpp:72
ArrayXrConstRef aT
The first-order temperature derivative of .
Definition: CubicEOS.hpp:76
real const & T
The temperature of the fluid (in K).
Definition: CubicEOS.hpp:71
ArrayXrConstRef b
The variables in the cubic equation of state for each substance in the fluid phase computed at curre...
Definition: CubicEOS.hpp:81
Strings const & substances
The chemical formulas of the substances in the fluid phase.
Definition: CubicEOS.hpp:70
ArrayXrConstRef Pcr
The critical pressures of the substances in the fluid phase (in Pa).
Definition: CubicEOS.hpp:73
ArrayXrConstRef alpha
The variables in the cubic equation of state for each substance in the fluid phase computed at curre...
Definition: CubicEOS.hpp:78
ArrayXrConstRef aTT
The second-order temperature derivative of .
Definition: CubicEOS.hpp:77
ArrayXrConstRef omega
The acentric factors of the substances in the fluid phase.
Definition: CubicEOS.hpp:74
ArrayXrConstRef a
The variables in the cubic equation of state for each substance in the fluid phase computed at curre...
Definition: CubicEOS.hpp:75
ArrayXrConstRef alphaTT
The second-order temperature derivative of .
Definition: CubicEOS.hpp:80
ArrayXrConstRef alphaT
The first-order temperature derivative of .
Definition: CubicEOS.hpp:79
Definition: CubicEOS.hpp:245
The parameters in the binary interaction parameter model of PHREEQC for Peng-Robinson EOS.
Definition: CubicEOS.hpp:199
The parameters in the binary interaction parameter model of Søreide and Whitson (1992) for Peng-Robin...
Definition: CubicEOS.hpp:210
The binary interaction parameters for the cubic equation of state.
Definition: CubicEOS.hpp:56
MatrixXr k
The computed binary interaction parameters for the species in the fluid phase.
Definition: CubicEOS.hpp:57
MatrixXr kT
The computed first-order temperature derivative of the binary interaction parameters .
Definition: CubicEOS.hpp:58
MatrixXr kTT
The computed second-order temperature derivative of the binary interaction parameters .
Definition: CubicEOS.hpp:59
The necessary constants , , , and function that uniquely define a cubic equation of state.
Definition: CubicEOS.hpp:130
AlphaModel alphafn
The function in the cubic equation of state.
Definition: CubicEOS.hpp:135
real epsilon
The constant in the cubic equation of state.
Definition: CubicEOS.hpp:131
real sigma
The constant in the cubic equation of state.
Definition: CubicEOS.hpp:132
real Psi
The constant in the cubic equation of state.
Definition: CubicEOS.hpp:134
real Omega
The constant in the cubic equation of state.
Definition: CubicEOS.hpp:133
The specifications for configuting a cubic equation of state.
Definition: CubicEOS.hpp:158
BipModel bipmodel
The function that calculates the binary interaction parameters in .
Definition: CubicEOS.hpp:161
Vec< Substance > substances
The substances in the fluid phase and their attributes.
Definition: CubicEOS.hpp:159
EquationModel eqmodel
The cubic equation of state model to be used.
Definition: CubicEOS.hpp:160
The properties calculated by evaluating a cubic equation of state.
Definition: CubicEOS.hpp:41
real Gres
The residual molar Gibbs energy of the phase (in J/mol).
Definition: CubicEOS.hpp:45
real Hres
The residual molar enthalpy of the phase (in J/mol).
Definition: CubicEOS.hpp:46
StateOfMatter som
The state of matter of the fluid phase.
Definition: CubicEOS.hpp:51
ArrayXr Vi
Species partial molar volumes (in m3/mol).
Definition: CubicEOS.hpp:49
real Cpres
The residual molar heat capacity at constant pressure of the phase (in J/(mol*K)).
Definition: CubicEOS.hpp:47
real VP
The pressure derivative of the molar volume constant temperature (in m3/(mol*Pa)).
Definition: CubicEOS.hpp:44
ArrayXr ln_phi
The ln fugacity coefficients of the species in the phase.
Definition: CubicEOS.hpp:50
real V
The molar volume of the phase (in m3/mol).
Definition: CubicEOS.hpp:42
real VT
The temperature derivative of the molar volume at constant pressure (in m3/(mol*K)).
Definition: CubicEOS.hpp:43
real Cvres
The residual molar heat capacity at constant volume of the phase (in J/(mol*K)).
Definition: CubicEOS.hpp:48
The attributes of a substance in a fluid phase required by a cubic equation of state.
Definition: CubicEOS.hpp:32
real omega
The acentric factor of the substance in the fluid phase.
Definition: CubicEOS.hpp:36
real Tcr
The critical temperature of the substance in the fluid phase (in K).
Definition: CubicEOS.hpp:34
String formula
The chemical formula of the substance in the fluid phase.
Definition: CubicEOS.hpp:33
real Pcr
The critical pressure of the substance in the fluid phase (in Pa).
Definition: CubicEOS.hpp:35