Loading [MathJax]/extensions/tex2jax.js
TransFlow  0.1.0
A transient pipeline flow simulation library
All Classes Namespaces Functions Variables Friends Modules Pages
bwrs.hpp
1 #pragma once
2 
3 #include <string>
4 #include <armadillo>
5 
6 #include "equationofstate/equationofstatebase.hpp"
7 
26 class BWRS : public EquationOfStateBase
27 {
28 public:
52  BWRS(
53  const arma::vec& composition = Composition::defaultComposition,
54  const std::string& parameterSet = "Calsep"
55  );
56 
71  static BWRS fromFilePaths(
72  const arma::vec& composition = Composition::defaultComposition,
73  const std::string& ABparameterFile = std::string(TRANSFLOW_RESOURCE_PATH) + "/equationofstate/bwrs/calsepABparameters.csv",
74  const std::string& binaryInteractionTableFile = std::string(TRANSFLOW_RESOURCE_PATH) + "/equationofstate/bwrs/calsepBinaryInteraction.csv",
75  const std::string& criticalProperties = "Starling"
76  );
77 
84  virtual arma::vec evaluate(
85  const double pressure,
86  const double temperature) const override;
87 
104  virtual double calculateCompressibility(
105  const double pressure,
106  const double temperature) const override;
107 
120  virtual bool setComposition(const arma::vec& composition, const bool force = true) override;
121 
128  void loadCriticalProperties(const std::string name);
129 
136  void loadParametersAndCriticalProperties(const std::string parameterSet);
137 
149 
163 
177 
181  void loadGasscoParameters();
182 
186  void loadCalsepParameters();
187 
191  void loadStarlingParameters();
192 
199  void loadParameterFiles(
200  const std::string& ABparameterFile,
201  const std::string& binaryInteractionTableFile);
202 
205 
217  double findDensity(
218  const double pressure,
219  const double temperature,
220  const double tolerance = 1e-4) const;
221 
222 // double getDerivativeOfZwrtDensityAtConstantTemperature(const double density, const double temperature) const;
223 
224  double getGasConstant() const { return m_R; }
225 
228 
231 
232 protected:
233 
234  // parameters from Starling book
235  // C1 C2 C3 iC4 nC4 iC5 nC5 C6 N2 CO2
236 
238  arma::vec m_Tc = arma::vec({ 190.69, 305.39, 369.89, 408.13, 425.19, 460.37, 469.49, 507.29, 126.15, 304.15}); // critical temperature
240  arma::vec m_rhoc = arma::vec({ 1.00500e+4, 6.75659e+3, 4.99936e+3, 3.80118e+3, 3.92132e+3, 3.24694e+3, 3.21491e+3, 2.71673e+3, 1.10992e+4, 1.06379e+4}); // critical molar density [mol/m3]
242  arma::vec m_w = arma::vec({ 0.013, 0.1018, 0.157, 0.183, 0.197, 0.226, 0.252, 0.302, 0.035, 0.21}); // accentric factor
244  arma::vec m_pc = arma::vec({ 45.96, 48.839, 42.5, 36.48, 37.96, 33.81, 33.69, 27.34, 33.99, 73.825})*1e5; // critical pressure
246  arma::vec m_molarMass = arma::vec({ 16.042, 30.068, 44.094, 58.12, 58.12, 72.146, 72.146, 86.172, 28.016, 44.01}); // [g/mol]
248  arma::vec m_expW = exp(-3.8*m_w);
249 
258  double m_R = 8.3160; // gas constant from Starling [m3 Pa / K mol]
259 
272 
278  arma::vec m_Bi;
279 
285  arma::vec m_Ai;
286 
287  double m_A0;
288  double m_B0;
289  double m_C0;
290  double m_D0;
291  double m_E0;
292  double m_a;
293  double m_b;
294  double m_c;
295  double m_d;
296  double m_ALPHA;
297  double m_GAMMA;
298 
301 
303 
315  void calculateCoefficients();
316 
326  void findNonZeroComponents();
327 
328  arma::uvec m_indices;
329 
347  double findMolarDensity(
348  const double pressure,
349  const double temperature,
350  const double tolerance = 1e-4) const;
351 };
BWRS::m_D0
double m_D0
A coefficient used when evaluating the BWRS-equation. Independent of pressure and temperature.
Definition: bwrs.hpp:290
BWRS::m_indices
arma::uvec m_indices
The indices of the non-zero gas fractions (components).
Definition: bwrs.hpp:328
BWRS::getMixtureCriticalPressure
double getMixtureCriticalPressure() const
Get the critical pressure of the gas mixture [Pa].
Definition: bwrs.hpp:227
BWRS::loadJFHCriticalProperties
void loadJFHCriticalProperties()
Load the critical properties from Helgaker.
BWRS::setComposition
virtual bool setComposition(const arma::vec &composition, const bool force=true) override
Set the composition of the EOS.
BWRS::m_binaryInteractionParameterTable
arma::mat m_binaryInteractionParameterTable
Binary interaction coefficients .
Definition: bwrs.hpp:271
BWRS::m_rhoc
arma::vec m_rhoc
Critical density [kg/m3].
Definition: bwrs.hpp:240
Composition::defaultComposition
static const Composition defaultComposition
Default composition.
Definition: composition.hpp:81
BWRS::m_pc
arma::vec m_pc
Critical pressure [Pa].
Definition: bwrs.hpp:244
BWRS::m_GAMMA
double m_GAMMA
A coefficient used when evaluating the BWRS-equation. Independent of pressure and temperature.
Definition: bwrs.hpp:297
BWRS::loadCalsepParameters
void loadCalsepParameters()
BWRS::calculateCompressibility
virtual double calculateCompressibility(const double pressure, const double temperature) const override
Calculate the compressibility factor (Z) of the gas at a given pressure and temperature.
BWRS::m_molarMass
arma::vec m_molarMass
Molar mass of the different gas components [g/mol].
Definition: bwrs.hpp:246
BWRS::fromFilePaths
static BWRS fromFilePaths(const arma::vec &composition=Composition::defaultComposition, const std::string &ABparameterFile=std::string(TRANSFLOW_RESOURCE_PATH)+"/equationofstate/bwrs/calsepABparameters.csv", const std::string &binaryInteractionTableFile=std::string(TRANSFLOW_RESOURCE_PATH)+"/equationofstate/bwrs/calsepBinaryInteraction.csv", const std::string &criticalProperties="Starling")
Explicit BWRS constructor which allows specifying which files to load mixture parameters and and bi...
BWRS::m_expW
arma::vec m_expW
Exponential of the accentric factor.
Definition: bwrs.hpp:248
BWRS::m_d
double m_d
A coefficient used when evaluating the BWRS-equation. Independent of pressure and temperature.
Definition: bwrs.hpp:295
BWRS::loadStarlingCriticalProperties
void loadStarlingCriticalProperties()
Load the critical properties from Starling.
BWRS::calculateCoefficients
void calculateCoefficients()
Calculates all the coefficients used for evaluating BWRS that are independent of pressure and tempera...
BWRS::m_B0
double m_B0
A coefficient used when evaluating the BWRS-equation. Independent of pressure and temperature.
Definition: bwrs.hpp:288
BWRS::m_C0
double m_C0
A coefficient used when evaluating the BWRS-equation. Independent of pressure and temperature.
Definition: bwrs.hpp:289
BWRS::m_b
double m_b
A coefficient used when evaluating the BWRS-equation. Independent of pressure and temperature.
Definition: bwrs.hpp:293
BWRS::m_R
double m_R
The gas constant [J/(K mol)].
Definition: bwrs.hpp:258
EquationOfStateBase
The EquationOfStateBase is an abstract class, the base class for different equations of state.
Definition: equationofstatebase.hpp:20
BWRS::m_ALPHA
double m_ALPHA
A coefficient used when evaluating the BWRS-equation. Independent of pressure and temperature.
Definition: bwrs.hpp:296
BWRS::loadParameterFiles
void loadParameterFiles(const std::string &ABparameterFile, const std::string &binaryInteractionTableFile)
Load mixture parameters and , and binary interaction coefficients coefficients from specific files.
BWRS::enableConstantHeatCapacities
void enableConstantHeatCapacities()
Enable constant heat capacity and .
BWRS::m_A0
double m_A0
A coefficient used when evaluating the BWRS-equation. Independent of pressure and temperature.
Definition: bwrs.hpp:287
BWRS::loadCalsepCriticalProperties
void loadCalsepCriticalProperties()
Load the critical properties from the Calsep report.
BWRS::loadGasscoParameters
void loadGasscoParameters()
BWRS::m_criticalPressureOfMixture
double m_criticalPressureOfMixture
Critical pressure of the gas mixture.
Definition: bwrs.hpp:299
BWRS::m_a
double m_a
A coefficient used when evaluating the BWRS-equation. Independent of pressure and temperature.
Definition: bwrs.hpp:292
BWRS::m_useConstantHeatCapacities
bool m_useConstantHeatCapacities
Flag to set if we want to use constant heat capacity and .
Definition: bwrs.hpp:302
BWRS::loadParametersAndCriticalProperties
void loadParametersAndCriticalProperties(const std::string parameterSet)
loadParametersAndCriticalProperties Load parameters and critical properties.
BWRS::findNonZeroComponents
void findNonZeroComponents()
Set up BWRS::m_indices to reflect which gas fractions are non-zero.
BWRS::loadStarlingParameters
void loadStarlingParameters()
BWRS::m_Bi
arma::vec m_Bi
Pure component parameters Bi.
Definition: bwrs.hpp:278
BWRS::loadCriticalProperties
void loadCriticalProperties(const std::string name)
loadCriticalProperties Load a set of critical properties. Either "Calsep", "JFH" or "Starling".
BWRS::findDensity
double findDensity(const double pressure, const double temperature, const double tolerance=1e-4) const
Find the gas density at a given pressure and temperature.
BWRS
Implements the Benedict-Webb-Rubin-Starling (BWRS) equation of state.
Definition: bwrs.hpp:26
BWRS::getGasConstant
double getGasConstant() const
Get the gas constant R.
Definition: bwrs.hpp:224
BWRS::m_c
double m_c
A coefficient used when evaluating the BWRS-equation. Independent of pressure and temperature.
Definition: bwrs.hpp:294
BWRS::m_w
arma::vec m_w
Accentric factor [-].
Definition: bwrs.hpp:242
BWRS::evaluate
virtual arma::vec evaluate(const double pressure, const double temperature) const override
Evaluate the BWRS equation of state at the given pressure and temperature.
BWRS::getMixtureCriticalTemperature
double getMixtureCriticalTemperature() const
Get the critical temperature of the gas mixture [K].
Definition: bwrs.hpp:230
BWRS::m_E0
double m_E0
A coefficient used when evaluating the BWRS-equation. Independent of pressure and temperature.
Definition: bwrs.hpp:291
BWRS::m_criticalTemperatureOfMixture
double m_criticalTemperatureOfMixture
Critical temperature of the gas mixture.
Definition: bwrs.hpp:300
BWRS::m_Ai
arma::vec m_Ai
Pure component parameters Ai.
Definition: bwrs.hpp:285
BWRS::BWRS
BWRS(const arma::vec &composition=Composition::defaultComposition, const std::string &parameterSet="Calsep")
Constructor that uses a string to select which mixture parameters and , binary interaction coefficie...
BWRS::findMolarDensity
double findMolarDensity(const double pressure, const double temperature, const double tolerance=1e-4) const
Find the molar density of the gas at a given pressure and temperature.
BWRS::m_Tc
arma::vec m_Tc
Critical temperature [K].
Definition: bwrs.hpp:238