www.mooseframework.org
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
PorousFlowFluidStateBase Class Referenceabstract

Base class for fluid states for miscible multiphase flow in porous media. More...

#include <PorousFlowFluidStateBase.h>

Inheritance diagram for PorousFlowFluidStateBase:
[legend]

Public Member Functions

 PorousFlowFluidStateBase (const InputParameters &parameters)
 
unsigned int numPhases () const
 The maximum number of phases in this model. More...
 
unsigned int numComponents () const
 The maximum number of components in this model. More...
 
unsigned int aqueousPhaseIndex () const
 The index of the aqueous phase. More...
 
unsigned int gasPhaseIndex () const
 The index of the gas phase. More...
 
unsigned int aqueousComponentIndex () const
 The index of the aqueous fluid component. More...
 
unsigned int gasComponentIndex () const
 The index of the gas fluid component. More...
 
unsigned int saltComponentIndex () const
 The index of the salt component. More...
 
virtual std::string fluidStateName () const =0
 Name of FluidState. More...
 
virtual void thermophysicalProperties (Real pressure, Real temperature, Real Xnacl, Real Z, unsigned int qp, std::vector< FluidStateProperties > &fsp) const =0
 Determines the complete thermophysical state of the system for a given set of primary variables. More...
 
virtual Real totalMassFraction (Real pressure, Real temperature, Real Xnacl, Real saturation, unsigned int qp) const =0
 Total mass fraction of fluid component summed over all phases in the two-phase state for a specified gas saturation. More...
 
void clearFluidStateProperties (std::vector< FluidStateProperties > &fsp) const
 Clears the contents of the FluidStateProperties data structure. More...
 
void initialize () final
 
void execute () final
 
void finalize () final
 
Real rachfordRice (Real vf, std::vector< Real > &Zi, std::vector< Real > &Ki) const
 Rachford-Rice equation for vapor fraction. More...
 
Real rachfordRiceDeriv (Real vf, std::vector< Real > &Zi, std::vector< Real > &Ki) const
 Derivative of Rachford-Rice equation wrt vapor fraction. More...
 
Real vaporMassFraction (Real Z0, Real K0, Real K1) const
 Solves Rachford-Rice equation to provide vapor mass fraction. More...
 
Real vaporMassFraction (std::vector< Real > &Zi, std::vector< Real > &Ki) const
 

Protected Member Functions

void phaseState (Real Zi, Real Xi, Real Yi, FluidStatePhaseEnum &phase_state) const
 Determines the phase state gven the total mass fraction and equilibrium mass fractions. More...
 

Protected Attributes

unsigned int _num_phases
 Number of phases. More...
 
unsigned int _num_components
 Number of components. More...
 
const unsigned int _aqueous_phase_number
 Phase number of the aqueous phase. More...
 
unsigned int _gas_phase_number
 Phase number of the gas phase. More...
 
const unsigned int _aqueous_fluid_component
 Fluid component number of the aqueous component. More...
 
unsigned int _gas_fluid_component
 Fluid component number of the gas phase. More...
 
const unsigned int _salt_component
 Salt component index. More...
 
const Real _R
 Universal gas constant (J/mol/K) More...
 
const Real _T_c2k
 Conversion from C to K. More...
 
const Real _nr_max_its
 Maximum number of iterations for the Newton-Raphson iterations. More...
 
const Real _nr_tol
 Tolerance for Newton-Raphson iterations. More...
 
const PorousFlowCapillaryPressure_pc
 Capillary pressure UserObject. More...
 

Detailed Description

Base class for fluid states for miscible multiphase flow in porous media.

Definition at line 84 of file PorousFlowFluidStateBase.h.

Constructor & Destructor Documentation

◆ PorousFlowFluidStateBase()

PorousFlowFluidStateBase::PorousFlowFluidStateBase ( const InputParameters &  parameters)

Definition at line 27 of file PorousFlowFluidStateBase.C.

28  : PorousFlowFluidStateFlash(parameters),
29  _aqueous_phase_number(getParam<unsigned int>("liquid_phase_number")),
30  _aqueous_fluid_component(getParam<unsigned int>("liquid_fluid_component")),
31  _salt_component(getParam<unsigned int>("salt_component")),
32  _R(8.3144598),
33  _T_c2k(273.15),
34  _nr_max_its(42),
35  _nr_tol(1.0e-12),
36  _pc(getUserObject<PorousFlowCapillaryPressure>("capillary_pressure"))
37 {
38 }
const unsigned int _aqueous_phase_number
Phase number of the aqueous phase.
const unsigned int _salt_component
Salt component index.
const Real _T_c2k
Conversion from C to K.
const unsigned int _aqueous_fluid_component
Fluid component number of the aqueous component.
const Real _nr_tol
Tolerance for Newton-Raphson iterations.
const Real _R
Universal gas constant (J/mol/K)
const PorousFlowCapillaryPressure & _pc
Capillary pressure UserObject.
PorousFlowFluidStateFlash(const InputParameters &parameters)
const Real _nr_max_its
Maximum number of iterations for the Newton-Raphson iterations.

Member Function Documentation

◆ aqueousComponentIndex()

unsigned int PorousFlowFluidStateBase::aqueousComponentIndex ( ) const
inline

The index of the aqueous fluid component.

Returns
aqueous fluid component number

Definition at line 117 of file PorousFlowFluidStateBase.h.

117 { return _aqueous_fluid_component; };
const unsigned int _aqueous_fluid_component
Fluid component number of the aqueous component.

◆ aqueousPhaseIndex()

unsigned int PorousFlowFluidStateBase::aqueousPhaseIndex ( ) const
inline

The index of the aqueous phase.

Returns
aqueous phase number

Definition at line 105 of file PorousFlowFluidStateBase.h.

105 { return _aqueous_phase_number; };
const unsigned int _aqueous_phase_number
Phase number of the aqueous phase.

◆ clearFluidStateProperties()

void PorousFlowFluidStateBase::clearFluidStateProperties ( std::vector< FluidStateProperties > &  fsp) const

Clears the contents of the FluidStateProperties data structure.

Parameters
[out]fspFluidStateProperties data structure with all data initialized to 0

Definition at line 41 of file PorousFlowFluidStateBase.C.

Referenced by PorousFlowWaterNCG::thermophysicalProperties(), and PorousFlowBrineCO2::thermophysicalProperties().

42 {
43  std::fill(fsp.begin(), fsp.end(), FluidStateProperties(_num_components));
44 }
unsigned int _num_components
Number of components.
Data structure to pass calculated thermophysical properties.

◆ execute()

void PorousFlowFluidStateFlash::execute ( )
inlinefinalinherited

Definition at line 37 of file PorousFlowFluidStateFlash.h.

37 {};

◆ finalize()

void PorousFlowFluidStateFlash::finalize ( )
inlinefinalinherited

Definition at line 38 of file PorousFlowFluidStateFlash.h.

38 {};

◆ fluidStateName()

virtual std::string PorousFlowFluidStateBase::fluidStateName ( ) const
pure virtual

Name of FluidState.

Implemented in PorousFlowBrineCO2, and PorousFlowWaterNCG.

◆ gasComponentIndex()

unsigned int PorousFlowFluidStateBase::gasComponentIndex ( ) const
inline

The index of the gas fluid component.

Returns
gas fluid component number

Definition at line 123 of file PorousFlowFluidStateBase.h.

123 { return _gas_fluid_component; };
unsigned int _gas_fluid_component
Fluid component number of the gas phase.

◆ gasPhaseIndex()

unsigned int PorousFlowFluidStateBase::gasPhaseIndex ( ) const
inline

The index of the gas phase.

Returns
gas phase number

Definition at line 111 of file PorousFlowFluidStateBase.h.

111 { return _gas_phase_number; };
unsigned int _gas_phase_number
Phase number of the gas phase.

◆ initialize()

void PorousFlowFluidStateFlash::initialize ( )
inlinefinalinherited

Definition at line 36 of file PorousFlowFluidStateFlash.h.

36 {};

◆ numComponents()

unsigned int PorousFlowFluidStateBase::numComponents ( ) const
inline

The maximum number of components in this model.

Returns
number of components

Definition at line 99 of file PorousFlowFluidStateBase.h.

99 { return _num_components; };
unsigned int _num_components
Number of components.

◆ numPhases()

unsigned int PorousFlowFluidStateBase::numPhases ( ) const
inline

The maximum number of phases in this model.

Returns
number of phases

Definition at line 93 of file PorousFlowFluidStateBase.h.

Referenced by PorousFlowFluidState::PorousFlowFluidState().

93 { return _num_phases; };
unsigned int _num_phases
Number of phases.

◆ phaseState()

void PorousFlowFluidStateFlash::phaseState ( Real  Zi,
Real  Xi,
Real  Yi,
FluidStatePhaseEnum phase_state 
) const
protectedinherited

Determines the phase state gven the total mass fraction and equilibrium mass fractions.

Parameters
Zitotal mass fraction
Xiequilibrium mass fraction in liquid
Yiequilibrium mass fraction in gas
[out]phase_statethe phase state (gas, liquid, two phase)

Definition at line 29 of file PorousFlowFluidStateFlash.C.

Referenced by PorousFlowWaterNCG::massFractions(), and PorousFlowBrineCO2::massFractions().

33 {
34  if (Zi <= Xi)
35  {
36  // In this case, there is not enough component i to form a gas phase,
37  // so only a liquid phase is present
38  phase_state = FluidStatePhaseEnum::LIQUID;
39  }
40  else if (Zi > Xi && Zi < Yi)
41  {
42  // Two phases are present
43  phase_state = FluidStatePhaseEnum::TWOPHASE;
44  }
45  else // (Zi >= Yi)
46  {
47  // In this case, there is not enough water to form a liquid
48  // phase, so only a gas phase is present
49  phase_state = FluidStatePhaseEnum::GAS;
50  }
51 }

◆ rachfordRice()

Real PorousFlowFluidStateFlash::rachfordRice ( Real  vf,
std::vector< Real > &  Zi,
std::vector< Real > &  Ki 
) const
inherited

Rachford-Rice equation for vapor fraction.

Can be solved analytically for two components in two phases, but must be solved iteratively using a root finding algorithm for more components. This equation has the nice property that it is monotonic in the interval [0,1], so that only a small number of iterations are typically required to find the root.

The Rachford-Rice equation can also be used to check whether the phase state is two phase, single phase gas, or single phase liquid. Evaluate f(v), the Rachford-Rice equation evaluated at the vapor mass fraction.

If f(0) < 0, then the mixture is below the bubble point, and only a single phase liquid can exist

If f(1) > 0, then the mixture is above the dew point, and only a single phase gas exists.

If f(0) >= 0 and f(1) <= 0, the mixture is between the bubble and dew points, and both gas and liquid phases exist.

Parameters
vfvapor fraction
Zimass fractions
Kiequilibrium constants
Returns
f(x)

Definition at line 54 of file PorousFlowFluidStateFlash.C.

Referenced by PorousFlowFluidStateFlash::vaporMassFraction().

57 {
58  const std::size_t num_z = Zi.size();
59  // Check that the sizes of the mass fractions and equilibrium constant vectors are correct
60  if (Ki.size() != num_z + 1)
61  mooseError("The number of mass fractions or equilibrium components passed to rachfordRice is "
62  "not correct");
63 
64  Real f = 0.0;
65  Real Z_total = 0.0;
66 
67  for (std::size_t i = 0; i < num_z; ++i)
68  {
69  f += Zi[i] * (Ki[i] - 1.0) / (1.0 + x * (Ki[i] - 1.0));
70  Z_total += Zi[i];
71  }
72 
73  // Add the last component (with total mass fraction = 1 - z_total)
74  f += (1.0 - Z_total) * (Ki[num_z] - 1.0) / (1.0 + x * (Ki[num_z] - 1.0));
75 
76  return f;
77 }

◆ rachfordRiceDeriv()

Real PorousFlowFluidStateFlash::rachfordRiceDeriv ( Real  vf,
std::vector< Real > &  Zi,
std::vector< Real > &  Ki 
) const
inherited

Derivative of Rachford-Rice equation wrt vapor fraction.

Has the nice property that it is strictly negative in the interval [0,1]

Parameters
vfvapor fraction
Zimass fractions
Kiequilibrium constants
Returns
f'(x)

Definition at line 80 of file PorousFlowFluidStateFlash.C.

Referenced by PorousFlowFluidStateFlash::vaporMassFraction().

83 {
84  const std::size_t num_Z = Zi.size();
85  // Check that the sizes of the mass fractions and equilibrium constant vectors are correct
86  if (Ki.size() != num_Z + 1)
87  mooseError("The number of mass fractions or equilibrium components passed to rachfordRice is "
88  "not correct");
89 
90  Real df = 0.0;
91  Real Z_total = 0.0;
92 
93  for (std::size_t i = 0; i < num_Z; ++i)
94  {
95  df -= Zi[i] * (Ki[i] - 1.0) * (Ki[i] - 1.0) / (1.0 + x * (Ki[i] - 1.0)) /
96  (1.0 + x * (Ki[i] - 1.0));
97  Z_total += Zi[i];
98  }
99 
100  // Add the last component (with total mass fraction = 1 - z_total)
101  df -= (1.0 - Z_total) * (Ki[num_Z] - 1.0) * (Ki[num_Z] - 1.0) / (1.0 + x * (Ki[num_Z] - 1.0)) /
102  (1.0 + x * (Ki[num_Z] - 1.0));
103 
104  return df;
105 }

◆ saltComponentIndex()

unsigned int PorousFlowFluidStateBase::saltComponentIndex ( ) const
inline

The index of the salt component.

Returns
salt component number

Definition at line 129 of file PorousFlowFluidStateBase.h.

129 { return _salt_component; };
const unsigned int _salt_component
Salt component index.

◆ thermophysicalProperties()

virtual void PorousFlowFluidStateBase::thermophysicalProperties ( Real  pressure,
Real  temperature,
Real  Xnacl,
Real  Z,
unsigned int  qp,
std::vector< FluidStateProperties > &  fsp 
) const
pure virtual

Determines the complete thermophysical state of the system for a given set of primary variables.

Parameters
pressuregas phase pressure (Pa)
temperaturefluid temperature (K)
Xnaclmass fraction of NaCl
Ztotal mass fraction of fluid component
qpquadpoint index
[out]fspthe FluidStateProperties struct containing all properties

Implemented in PorousFlowBrineCO2, and PorousFlowWaterNCG.

Referenced by PorousFlowFluidState::thermophysicalProperties().

◆ totalMassFraction()

virtual Real PorousFlowFluidStateBase::totalMassFraction ( Real  pressure,
Real  temperature,
Real  Xnacl,
Real  saturation,
unsigned int  qp 
) const
pure virtual

Total mass fraction of fluid component summed over all phases in the two-phase state for a specified gas saturation.

Parameters
pressuregas pressure (Pa)
temperaturetemperature (K)
XnaclNaCl mass fraction (kg/kg)
saturationgas saturation (-)
qpquadpoint index
Returns
total mass fraction Z (-)

Implemented in PorousFlowBrineCO2, and PorousFlowWaterNCG.

Referenced by PorousFlowFluidStateIC::value().

◆ vaporMassFraction() [1/2]

Real PorousFlowFluidStateFlash::vaporMassFraction ( Real  Z0,
Real  K0,
Real  K1 
) const
inherited

Solves Rachford-Rice equation to provide vapor mass fraction.

For two components, the analytical solution is used, while for cases with more than two components, a Newton-Raphson iterative solution is calculated.

Parameters
Zitotal mass fraction(s)
Kiequilibrium constant(s)
Returns
vapor mass fraction

Definition at line 108 of file PorousFlowFluidStateFlash.C.

Referenced by PorousFlowWaterNCG::saturationTwoPhase(), PorousFlowBrineCO2::saturationTwoPhase(), and PorousFlowFluidStateFlash::vaporMassFraction().

109 {
110  return (Z0 * (K1 - K0) - (K1 - 1.0)) / ((K0 - 1.0) * (K1 - 1.0));
111 }

◆ vaporMassFraction() [2/2]

Real PorousFlowFluidStateFlash::vaporMassFraction ( std::vector< Real > &  Zi,
std::vector< Real > &  Ki 
) const
inherited

Definition at line 114 of file PorousFlowFluidStateFlash.C.

115 {
116  // Check that the sizes of the mass fractions and equilibrium constant vectors are correct
117  if (Ki.size() != Zi.size() + 1)
118  mooseError("The number of mass fractions or equilibrium components passed to rachfordRice is "
119  "not correct");
120  Real v;
121 
122  // If there are only two components, an analytical solution is possible
123  if (Ki.size() == 2)
124  v = vaporMassFraction(Zi[0], Ki[0], Ki[1]);
125  else
126  {
127  // More than two components - solve the Rachford-Rice equation using
128  // Newton-Raphson method
129  // Initial guess for vapor mass fraction
130  Real v0 = 0.5;
131  unsigned int iter = 0;
132 
133  while (std::abs(rachfordRice(v0, Zi, Ki)) > _nr_tol)
134  {
135  v0 = v0 - rachfordRice(v0, Zi, Ki) / rachfordRiceDeriv(v0, Zi, Ki);
136  iter++;
137 
138  if (iter > _nr_max_its)
139  break;
140  }
141  v = v0;
142  }
143  return v;
144 }
Real rachfordRice(Real vf, std::vector< Real > &Zi, std::vector< Real > &Ki) const
Rachford-Rice equation for vapor fraction.
Real vaporMassFraction(Real Z0, Real K0, Real K1) const
Solves Rachford-Rice equation to provide vapor mass fraction.
const Real _nr_tol
Tolerance for Newton-Raphson iterations.
Real rachfordRiceDeriv(Real vf, std::vector< Real > &Zi, std::vector< Real > &Ki) const
Derivative of Rachford-Rice equation wrt vapor fraction.
const Real _nr_max_its
Maximum number of iterations for the Newton-Raphson routine.

Member Data Documentation

◆ _aqueous_fluid_component

const unsigned int PorousFlowFluidStateBase::_aqueous_fluid_component
protected

◆ _aqueous_phase_number

const unsigned int PorousFlowFluidStateBase::_aqueous_phase_number
protected

◆ _gas_fluid_component

unsigned int PorousFlowFluidStateBase::_gas_fluid_component
protected

◆ _gas_phase_number

unsigned int PorousFlowFluidStateBase::_gas_phase_number
protected

◆ _nr_max_its

const Real PorousFlowFluidStateBase::_nr_max_its
protected

Maximum number of iterations for the Newton-Raphson iterations.

Definition at line 194 of file PorousFlowFluidStateBase.h.

◆ _nr_tol

const Real PorousFlowFluidStateBase::_nr_tol
protected

Tolerance for Newton-Raphson iterations.

Definition at line 196 of file PorousFlowFluidStateBase.h.

◆ _num_components

unsigned int PorousFlowFluidStateBase::_num_components
protected

◆ _num_phases

unsigned int PorousFlowFluidStateBase::_num_phases
protected

◆ _pc

const PorousFlowCapillaryPressure& PorousFlowFluidStateBase::_pc
protected

◆ _R

const Real PorousFlowFluidStateBase::_R
protected

Universal gas constant (J/mol/K)

Definition at line 190 of file PorousFlowFluidStateBase.h.

Referenced by PorousFlowWaterNCG::enthalpyOfDissolution(), and PorousFlowBrineCO2::enthalpyOfDissolutionGas().

◆ _salt_component

const unsigned int PorousFlowFluidStateBase::_salt_component
protected

Salt component index.

Definition at line 188 of file PorousFlowFluidStateBase.h.

Referenced by saltComponentIndex().

◆ _T_c2k

const Real PorousFlowFluidStateBase::_T_c2k
protected

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