TransFlow  0.1.0
A transient pipeline flow simulation library
BWRS Class Reference

Implements the Benedict-Webb-Rubin-Starling (BWRS) equation of state. More...

#include <bwrs.hpp>

Inheritance diagram for BWRS:
EquationOfStateBase

Public Member Functions

 BWRS (const arma::vec &composition=Composition::defaultComposition, const std::string &parameterSet="Calsep")
 Constructor that uses a string to select which mixture parameters \(A_0\) and \(B_0\), binary interaction coefficients \(k_{ij}\), and critical properties \(T_c\) etc. to use. The options are "Calsep", "JFH" and "Starling". More...
 
virtual arma::vec evaluate (const double pressure, const double temperature) const override
 Evaluate the BWRS equation of state at the given pressure and temperature. More...
 
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. More...
 
virtual bool setComposition (const arma::vec &composition, const bool force=true) override
 Set the composition of the EOS. More...
 
void loadCriticalProperties (const std::string name)
 loadCriticalProperties Load a set of critical properties. Either "Calsep", "JFH" or "Starling". More...
 
void loadParametersAndCriticalProperties (const std::string parameterSet)
 loadParametersAndCriticalProperties Load parameters and critical properties. More...
 
void loadStarlingCriticalProperties ()
 Load the critical properties from Starling. More...
 
void loadJFHCriticalProperties ()
 Load the critical properties from Helgaker. More...
 
void loadCalsepCriticalProperties ()
 Load the critical properties from the Calsep report. More...
 
void loadGasscoParameters ()
 
void loadCalsepParameters ()
 
void loadStarlingParameters ()
 
void loadParameterFiles (const std::string &ABparameterFile, const std::string &binaryInteractionTableFile)
 Load mixture parameters \(A_0\) and \(B_0\), and binary interaction coefficients \(k_{ij}\) coefficients from specific files. More...
 
void enableConstantHeatCapacities ()
 Enable constant heat capacity \(c_p\) and \(c_v\).
 
double findDensity (const double pressure, const double temperature, const double tolerance=1e-4) const
 Find the gas density at a given pressure and temperature. More...
 
double getGasConstant () const
 Get the gas constant R.
 
double getMixtureCriticalPressure () const
 Get the critical pressure of the gas mixture [Pa].
 
double getMixtureCriticalTemperature () const
 Get the critical temperature of the gas mixture [K].
 
- Public Member Functions inherited from EquationOfStateBase
virtual ~EquationOfStateBase ()
 
 EquationOfStateBase (const arma::vec &composition=Composition::defaultComposition)
 EquationOfStateBase constructor. More...
 
virtual arma::vec evaluate (const double pressure, const double temperature, const arma::vec &composition)
 Virtual function for evaluating the EOS at a new composition. More...
 
virtual double calculateStandardDensity () const
 
double getMolarMassOfMixture () const
 Get the molar mass of the gas.
 
const arma::vec & getComposition () const
 Get the current composition stored in the EOS instance.
 

Static Public Member Functions

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 \(A_0\) and \(B_0\) and binary interaction coefficients \(k_{ij}\) from, and which critical properties to use. More...
 

Protected Member Functions

void calculateCoefficients ()
 Calculates all the coefficients used for evaluating BWRS that are independent of pressure and temperature. More...
 
void findNonZeroComponents ()
 Set up BWRS::m_indices to reflect which gas fractions are non-zero. More...
 
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. More...
 

Protected Attributes

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 [K].
 
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 density [kg/m3].
 
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 [-].
 
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 [Pa].
 
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})
 Molar mass of the different gas components [g/mol].
 
arma::vec m_expW = exp(-3.8*m_w)
 Exponential of the accentric factor.
 
double m_R = 8.3160
 The gas constant [J/(K mol)]. More...
 
arma::mat m_binaryInteractionParameterTable
 Binary interaction coefficients \(k_{ij}\). More...
 
arma::vec m_Bi
 Pure component parameters Bi. More...
 
arma::vec m_Ai
 Pure component parameters Ai. More...
 
double m_A0
 A coefficient used when evaluating the BWRS-equation. Independent of pressure and temperature.
 
double m_B0
 A coefficient used when evaluating the BWRS-equation. Independent of pressure and temperature.
 
double m_C0
 A coefficient used when evaluating the BWRS-equation. Independent of pressure and temperature.
 
double m_D0
 A coefficient used when evaluating the BWRS-equation. Independent of pressure and temperature.
 
double m_E0
 A coefficient used when evaluating the BWRS-equation. Independent of pressure and temperature.
 
double m_a
 A coefficient used when evaluating the BWRS-equation. Independent of pressure and temperature.
 
double m_b
 A coefficient used when evaluating the BWRS-equation. Independent of pressure and temperature.
 
double m_c
 A coefficient used when evaluating the BWRS-equation. Independent of pressure and temperature.
 
double m_d
 A coefficient used when evaluating the BWRS-equation. Independent of pressure and temperature.
 
double m_ALPHA
 A coefficient used when evaluating the BWRS-equation. Independent of pressure and temperature.
 
double m_GAMMA
 A coefficient used when evaluating the BWRS-equation. Independent of pressure and temperature.
 
double m_criticalPressureOfMixture
 Critical pressure of the gas mixture.
 
double m_criticalTemperatureOfMixture
 Critical temperature of the gas mixture.
 
bool m_useConstantHeatCapacities = false
 Flag to set if we want to use constant heat capacity \(c_p\) and \(c_v\).
 
arma::uvec m_indices
 The indices of the non-zero gas fractions (components).
 
- Protected Attributes inherited from EquationOfStateBase
arma::vec m_molarMass = { 16.04, 30.07, 44.1, 58.12, 58.12, 72.15, 72.15, 86.18, 28.13, 44.01}
 The molar mass [g/mol] of the different gas components, in order C1, C2, C3, iC4, nC4, iC5, nC5, C6, N2, CO2.
 
arma::vec::fixed< 10 > m_composition = arma::vec(10)
 The composition of the gas as fractions, in order C1, C2, C3, iC4, nC4, iC5, nC5, C6, N2, CO2.
 
double m_molarMassOfMixture
 The molar mass of the gas mixture [g/mol].
 
double m_density = 0
 Cache density for optimization [kg/m3].
 

Detailed Description

Implements the Benedict-Webb-Rubin-Starling (BWRS) equation of state.

This class implements the Benedict-Webb-Rubin-Starling (BWRS) equation of state. BWRS depends on 11 mixture parameters B_0 and A_0, which are calculated from the pure component parameters \(A_{0i}\) and \(B_{0i}\), as well as the binary interaction coefficients \(k_{ij}\).

More information on BWRS can be found in Fluid Properties for Light Petroleum Systems (Kenneth E. Starling, 1973, ISBN 978-0872012936).

Critical properties refer to the critical temperature (m_Tc), critical density (m_rhoc), critical pressure (m_pc), and accentric factor (m_w), which are used in the evaluation of the BWRS equation. These are found in Table 5 at page 223 of Fluid Properties for Light Petroleum Systems.

Constructor & Destructor Documentation

◆ BWRS()

BWRS::BWRS ( const arma::vec &  composition = Composition::defaultComposition,
const std::string &  parameterSet = "Calsep" 
)

Constructor that uses a string to select which mixture parameters \(A_0\) and \(B_0\), binary interaction coefficients \(k_{ij}\), and critical properties \(T_c\) etc. to use. The options are "Calsep", "JFH" and "Starling".

"Calsep" refers to the parameters tuned for Statpipe, see Tuning af parametre i BWRS-tilstandsligningen til brug i STATPIPES termodynamiske programpakke (Jan Munch, 1985) for more info.

"JFH" refer to the parameters found in the original code by Helgaker. These have been shown to give bad results after the solver was rewritten to use molar density (the original form used regular density), so I would recommend not using this.

"Staring" refers to the parameters given by Starling in Fluid Properties for Light Petroleum Systems (Kenneth E. Starling, 1973, ISBN 978-0872012936).

Parameters
compositionGas composition fraction, in order C1, C2, C3, iC4, nC4, iC5, nC5, C6, N2, CO2.
parameterSetWhich parameter set to use ("Starling", "Calsep" or "JFH").
Returns
An instance of BWRS.

Member Function Documentation

◆ calculateCoefficients()

void BWRS::calculateCoefficients ( )
protected

Calculates all the coefficients used for evaluating BWRS that are independent of pressure and temperature.

A lot of different coefficients are used when evaluating the BWRS equation to find the compressibility and the partial derivatives of Z. Many of these are independent of pressure and temperature, so they can be tabulated for the current gas composition.

This optimization is most effective if we use constant composition, but should also improve the evaluation of the formulas otherwise.

◆ calculateCompressibility()

virtual double BWRS::calculateCompressibility ( const double  pressure,
const double  temperature 
) const
overridevirtual

Calculate the compressibility factor (Z) of the gas at a given pressure and temperature.

This function is useful if we just need the compressibility and not all the other properties we can find from the EOS.

It contains a call to BWRS::findMolarDensity(), which contains some Newton-Raphson root finding, which are among the heaviest part of this whole class, so I don't expect much time-save over a call to evaluate().

Parameters
pressureGas pressure [Pa].
temperatureGas temperature [K].
Returns
Compressibility factor Z [-].

Implements EquationOfStateBase.

◆ evaluate()

virtual arma::vec BWRS::evaluate ( const double  pressure,
const double  temperature 
) const
overridevirtual

Evaluate the BWRS equation of state at the given pressure and temperature.

Parameters
pressureGas pressure [Pa]
temperatureGas temperature [K]
Returns
See EquationOfStateBase::evaluate().

Implements EquationOfStateBase.

◆ findDensity()

double BWRS::findDensity ( const double  pressure,
const double  temperature,
const double  tolerance = 1e-4 
) const

Find the gas density at a given pressure and temperature.

This is just a wrapper around findMolarDensity() and a conversion from molar density [mol/m3] to density [kg/m3]

Parameters
pressureGas pressure [Pa].
temperatureGas temperature [K].
toleranceNewton-Raphson tolerance.
Returns
Gas density [kg/m3].

◆ findMolarDensity()

double BWRS::findMolarDensity ( const double  pressure,
const double  temperature,
const double  tolerance = 1e-4 
) const
protected

Find the molar density of the gas at a given pressure and temperature.

This is most likely the most computationally heavy function in this class, since it contains a Newton-Raphson root finding, meaning that the BWRS equation will be evaluated multiple times until it reaches convergence.

The convergence criterion is implemented as

if (std::abs(change/previous) < tolerance) break;
Parameters
pressureGas pressure [Pa].
temperatureGas temperature [K].
toleranceConvergence criterion for the Newton-Raphson method.
Returns
Molar density [mol/m3]

◆ findNonZeroComponents()

void BWRS::findNonZeroComponents ( )
protected

Set up BWRS::m_indices to reflect which gas fractions are non-zero.

The BWRS equation has some issues if it is evaluated with gas fractions of zero, so to avoid this we store the indices of the non-zero fractions and only loop over those when evaluating the equation.

Call this function to find the non-zero indices and store them in BWRS::m_indices.

◆ fromFilePaths()

static BWRS 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" 
)
static

Explicit BWRS constructor which allows specifying which files to load mixture parameters \(A_0\) and \(B_0\) and binary interaction coefficients \(k_{ij}\) from, and which critical properties to use.

See also
loadJFHCriticalProperties()
loadCalsepCriticalProperties()
loadStarlingCriticalProperties()
Parameters
compositionGas composition fractions, in order C1, C2, C3, iC4, nC4, iC5, nC5, C6, N2, CO2.
ABparameterFilePath to file which contains the pure component parameters \(A_{0i}\) and \(B_{0i}\)
binaryInteractionTableFilePath to file which contains the interaction parameters \(k_{ij}\)
criticalPropertiesWhich set of critical gas properties should be used.

◆ loadCalsepCriticalProperties()

void BWRS::loadCalsepCriticalProperties ( )

Load the critical properties from the Calsep report.

This function sets the values of m_Tc, m_rhoc, m_w, m_pc, m_molarMass, m_expW, and m_R according to the values found in the original Helgaker Matlab code.

Warning
The values set by this function have been found to produce bad results. This is likely due to the rewrite to a molar density based solver, as the equations are originally given by Starling. Use loadStarlingCriticalProperties() instead.

◆ loadCalsepParameters()

void BWRS::loadCalsepParameters ( )

Load the mixture parameters \(A_0\) and \(B_0\), and binary interaction coefficients \(k_{ij}\) from the Calsep report.

◆ loadCriticalProperties()

void BWRS::loadCriticalProperties ( const std::string  name)

loadCriticalProperties Load a set of critical properties. Either "Calsep", "JFH" or "Starling".

Parameters
nameName of critical properties. Either "Calsep", "JFH" or "Starling".

◆ loadGasscoParameters()

void BWRS::loadGasscoParameters ( )

Load the mixture parameters \(A_0\) and \(B_0\), and binary interaction coefficients \(k_{ij}\) from Gassco.

◆ loadJFHCriticalProperties()

void BWRS::loadJFHCriticalProperties ( )

Load the critical properties from Helgaker.

This function sets the values of m_Tc, m_rhoc, m_w, m_pc, m_molarMass, m_expW, and m_R according to the values found in the original Helgaker Matlab code.

Warning
The values set by this function have been found to produce bad results. This is likely due to the rewrite to a molar density based solver, as the equations are originally given by Starling. Use loadStarlingCriticalProperties() instead.

◆ loadParameterFiles()

void BWRS::loadParameterFiles ( const std::string &  ABparameterFile,
const std::string &  binaryInteractionTableFile 
)

Load mixture parameters \(A_0\) and \(B_0\), and binary interaction coefficients \(k_{ij}\) coefficients from specific files.

Parameters
ABparameterFilePath to AB parameter file.
binaryInteractionTableFilePath to binary interaction coefficients file.

◆ loadParametersAndCriticalProperties()

void BWRS::loadParametersAndCriticalProperties ( const std::string  parameterSet)

loadParametersAndCriticalProperties Load parameters and critical properties.

Parameters
parameterSetName of parameter set. Either "Calsep", "JFH" or "Starling".

◆ loadStarlingCriticalProperties()

void BWRS::loadStarlingCriticalProperties ( )

Load the critical properties from Starling.

This function sets the values of m_Tc, m_rhoc, m_w, m_pc, m_molarMass, m_expW, and m_R according to the values found in Fluid Properties for Light Petroleum Systems (Kenneth E. Starling, 1973, ISBN 978-0872012936).

The values set by this function have been found to produce the best results.

◆ loadStarlingParameters()

void BWRS::loadStarlingParameters ( )

Load the mixture parameters \(A_0\) and \(B_0\), and binary interaction coefficients \(k_{ij}\) from the Starling BWRS book.

◆ setComposition()

virtual bool BWRS::setComposition ( const arma::vec &  composition,
const bool  force = true 
)
overridevirtual

Set the composition of the EOS.

This calls EquationOfStateBase::setComposition(), then updates the non-zero component indices BWRS::m_indices, calculates the new critical pressure and temperature of the gas mixture, before finally updating all the coefficients m_A0, m_B0, through m_GAMMA.

Parameters
compositionNew gas composition.
forceIf the composition should be changed even if it's within machine precision of the previous composition.
Returns
True if composition was changed, else false.

Reimplemented from EquationOfStateBase.

Member Data Documentation

◆ m_Ai

arma::vec BWRS::m_Ai
protected

Pure component parameters Ai.

From Table 1 at page 221 of Fluid Properties for Light Petroleum Systems.

◆ m_Bi

arma::vec BWRS::m_Bi
protected

Pure component parameters Bi.

From Table 1 at page 221 of Fluid Properties for Light Petroleum Systems.

◆ m_binaryInteractionParameterTable

arma::mat BWRS::m_binaryInteractionParameterTable
protected

Binary interaction coefficients \(k_{ij}\).

The binary interaction coefficients are stored in matrix of size 10x10, where the binary interactions between component i and j are stored at location \((i, j)\) in the matrix. The matrix is symmetric, so \(k(i, j) == k(j, i)\). The components are in the usual order (C1, C2, C3, iC4, nC4, iC5, nC5, C6, N2, CO2).

These can be found in Table 1 at page 227 of Fluid Properties for Light Petroleum Systems.

◆ m_R

double BWRS::m_R = 8.3160
protected

The gas constant [J/(K mol)].

The exact value of the gas constant is approx 8.3145 J/Kmol, but if we are using the critical properties and other parameters from Starling, these have been determined using an older definition of the gas constant, which is 8.3160 J/Kmol.


The documentation for this class was generated from the following file: