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

Compositional flash routines for miscible multiphase flow classes with multiple fluid components. More...

#include <PorousFlowFluidStateFlash.h>

Inheritance diagram for PorousFlowFluidStateFlash:
[legend]

Public Member Functions

 PorousFlowFluidStateFlash (const InputParameters &parameters)
 
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...
 
DualReal vaporMassFraction (const DualReal &Z0, const DualReal &K0, const DualReal &K1) const
 
Real vaporMassFraction (std::vector< Real > &Zi, std::vector< Real > &Ki) const
 
void initialize () final
 
void execute () final
 
void finalize () final
 
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...
 
void clearFluidStateProperties (std::vector< FluidStateProperties > &fsp) const
 Clears the contents of the FluidStateProperties data structure. More...
 

Protected Attributes

const Real _nr_max_its
 Maximum number of iterations for the Newton-Raphson routine. More...
 
const Real _nr_tol
 Tolerance for Newton-Raphson iterations. More...
 
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 PorousFlowCapillaryPressure_pc
 Capillary pressure UserObject. More...
 
FluidStateProperties _empty_fsp
 Empty FluidStateProperties object. More...
 

Detailed Description

Compositional flash routines for miscible multiphase flow classes with multiple fluid components.

Definition at line 23 of file PorousFlowFluidStateFlash.h.

Constructor & Destructor Documentation

◆ PorousFlowFluidStateFlash()

PorousFlowFluidStateFlash::PorousFlowFluidStateFlash ( const InputParameters &  parameters)

Definition at line 21 of file PorousFlowFluidStateFlash.C.

22  : PorousFlowFluidStateBase(parameters), _nr_max_its(42), _nr_tol(1.0e-12)
23 {
24 }

Member Function Documentation

◆ aqueousComponentIndex()

unsigned int PorousFlowFluidStateBase::aqueousComponentIndex ( ) const
inlineinherited

The index of the aqueous fluid component.

Returns
aqueous fluid component number

Definition at line 92 of file PorousFlowFluidStateBase.h.

92 { return _aqueous_fluid_component; };

◆ aqueousPhaseIndex()

unsigned int PorousFlowFluidStateBase::aqueousPhaseIndex ( ) const
inlineinherited

The index of the aqueous phase.

Returns
aqueous phase number

Definition at line 80 of file PorousFlowFluidStateBase.h.

80 { return _aqueous_phase_number; };

◆ clearFluidStateProperties()

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

Clears the contents of the FluidStateProperties data structure.

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

Definition at line 39 of file PorousFlowFluidStateBase.C.

40 {
41  std::fill(fsp.begin(), fsp.end(), _empty_fsp);
42 }

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

◆ execute()

void PorousFlowFluidStateBase::execute ( )
inlinefinalinherited

Definition at line 61 of file PorousFlowFluidStateBase.h.

61 {};

◆ finalize()

void PorousFlowFluidStateBase::finalize ( )
inlinefinalinherited

Definition at line 62 of file PorousFlowFluidStateBase.h.

62 {};

◆ fluidStateName()

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

Name of FluidState.

Implemented in PorousFlowBrineCO2, PorousFlowWaterNCG, and PorousFlowWaterVapor.

◆ gasComponentIndex()

unsigned int PorousFlowFluidStateBase::gasComponentIndex ( ) const
inlineinherited

The index of the gas fluid component.

Returns
gas fluid component number

Definition at line 98 of file PorousFlowFluidStateBase.h.

98 { return _gas_fluid_component; };

◆ gasPhaseIndex()

unsigned int PorousFlowFluidStateBase::gasPhaseIndex ( ) const
inlineinherited

The index of the gas phase.

Returns
gas phase number

Definition at line 86 of file PorousFlowFluidStateBase.h.

86 { return _gas_phase_number; };

◆ initialize()

void PorousFlowFluidStateBase::initialize ( )
inlinefinalinherited

Definition at line 60 of file PorousFlowFluidStateBase.h.

60 {};

◆ numComponents()

unsigned int PorousFlowFluidStateBase::numComponents ( ) const
inlineinherited

The maximum number of components in this model.

Returns
number of components

Definition at line 74 of file PorousFlowFluidStateBase.h.

74 { return _num_components; };

◆ numPhases()

unsigned int PorousFlowFluidStateBase::numPhases ( ) const
inlineinherited

The maximum number of phases in this model.

Returns
number of phases

Definition at line 68 of file PorousFlowFluidStateBase.h.

68 { return _num_phases; };

Referenced by PorousFlowFluidState::PorousFlowFluidState(), and PorousFlowFluidStateSingleComponent::PorousFlowFluidStateSingleComponent().

◆ rachfordRice()

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

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 27 of file PorousFlowFluidStateFlash.C.

30 {
31  const std::size_t num_z = Zi.size();
32  // Check that the sizes of the mass fractions and equilibrium constant vectors are correct
33  if (Ki.size() != num_z + 1)
34  mooseError("The number of mass fractions or equilibrium components passed to rachfordRice is "
35  "not correct");
36 
37  Real f = 0.0;
38  Real Z_total = 0.0;
39 
40  for (std::size_t i = 0; i < num_z; ++i)
41  {
42  f += Zi[i] * (Ki[i] - 1.0) / (1.0 + x * (Ki[i] - 1.0));
43  Z_total += Zi[i];
44  }
45 
46  // Add the last component (with total mass fraction = 1 - z_total)
47  f += (1.0 - Z_total) * (Ki[num_z] - 1.0) / (1.0 + x * (Ki[num_z] - 1.0));
48 
49  return f;
50 }

Referenced by vaporMassFraction().

◆ rachfordRiceDeriv()

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

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 53 of file PorousFlowFluidStateFlash.C.

56 {
57  const std::size_t num_Z = Zi.size();
58  // Check that the sizes of the mass fractions and equilibrium constant vectors are correct
59  if (Ki.size() != num_Z + 1)
60  mooseError("The number of mass fractions or equilibrium components passed to rachfordRice is "
61  "not correct");
62 
63  Real df = 0.0;
64  Real Z_total = 0.0;
65 
66  for (std::size_t i = 0; i < num_Z; ++i)
67  {
68  df -= Zi[i] * (Ki[i] - 1.0) * (Ki[i] - 1.0) / (1.0 + x * (Ki[i] - 1.0)) /
69  (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  df -= (1.0 - Z_total) * (Ki[num_Z] - 1.0) * (Ki[num_Z] - 1.0) / (1.0 + x * (Ki[num_Z] - 1.0)) /
75  (1.0 + x * (Ki[num_Z] - 1.0));
76 
77  return df;
78 }

Referenced by vaporMassFraction().

◆ saltComponentIndex()

unsigned int PorousFlowFluidStateBase::saltComponentIndex ( ) const
inlineinherited

The index of the salt component.

Returns
salt component number

Definition at line 104 of file PorousFlowFluidStateBase.h.

104 { return _salt_component; };

◆ vaporMassFraction() [1/3]

DualReal PorousFlowFluidStateFlash::vaporMassFraction ( const DualReal &  Z0,
const DualReal &  K0,
const DualReal &  K1 
) const

Definition at line 87 of file PorousFlowFluidStateFlash.C.

90 {
91  return (Z0 * (K1 - K0) - (K1 - 1.0)) / ((K0 - 1.0) * (K1 - 1.0));
92 }

◆ vaporMassFraction() [2/3]

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

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 81 of file PorousFlowFluidStateFlash.C.

82 {
83  return (Z0 * (K1 - K0) - (K1 - 1.0)) / ((K0 - 1.0) * (K1 - 1.0));
84 }

Referenced by PorousFlowWaterNCG::saturation(), PorousFlowBrineCO2::saturation(), and vaporMassFraction().

◆ vaporMassFraction() [3/3]

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

Definition at line 95 of file PorousFlowFluidStateFlash.C.

96 {
97  // Check that the sizes of the mass fractions and equilibrium constant vectors are correct
98  if (Ki.size() != Zi.size() + 1)
99  mooseError("The number of mass fractions or equilibrium components passed to rachfordRice is "
100  "not correct");
101  Real v;
102 
103  // If there are only two components, an analytical solution is possible
104  if (Ki.size() == 2)
105  v = vaporMassFraction(Zi[0], Ki[0], Ki[1]);
106  else
107  {
108  // More than two components - solve the Rachford-Rice equation using
109  // Newton-Raphson method
110  // Initial guess for vapor mass fraction
111  Real v0 = 0.5;
112  unsigned int iter = 0;
113 
114  while (std::abs(rachfordRice(v0, Zi, Ki)) > _nr_tol)
115  {
116  v0 = v0 - rachfordRice(v0, Zi, Ki) / rachfordRiceDeriv(v0, Zi, Ki);
117  iter++;
118 
119  if (iter > _nr_max_its)
120  break;
121  }
122  v = v0;
123  }
124  return v;
125 }

Member Data Documentation

◆ _aqueous_fluid_component

const unsigned int PorousFlowFluidStateBase::_aqueous_fluid_component
protectedinherited

◆ _aqueous_phase_number

const unsigned int PorousFlowFluidStateBase::_aqueous_phase_number
protectedinherited

◆ _empty_fsp

FluidStateProperties PorousFlowFluidStateBase::_empty_fsp
protectedinherited

◆ _gas_fluid_component

unsigned int PorousFlowFluidStateBase::_gas_fluid_component
protectedinherited

◆ _gas_phase_number

unsigned int PorousFlowFluidStateBase::_gas_phase_number
protectedinherited

◆ _nr_max_its

const Real PorousFlowFluidStateFlash::_nr_max_its
protected

Maximum number of iterations for the Newton-Raphson routine.

Definition at line 80 of file PorousFlowFluidStateFlash.h.

Referenced by vaporMassFraction().

◆ _nr_tol

const Real PorousFlowFluidStateFlash::_nr_tol
protected

Tolerance for Newton-Raphson iterations.

Definition at line 82 of file PorousFlowFluidStateFlash.h.

Referenced by vaporMassFraction().

◆ _num_components

unsigned int PorousFlowFluidStateBase::_num_components
protectedinherited

◆ _num_phases

unsigned int PorousFlowFluidStateBase::_num_phases
protectedinherited

◆ _pc

const PorousFlowCapillaryPressure& PorousFlowFluidStateBase::_pc
protectedinherited

◆ _R

const Real PorousFlowFluidStateBase::_R
protectedinherited

Universal gas constant (J/mol/K)

Definition at line 133 of file PorousFlowFluidStateBase.h.

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

◆ _salt_component

const unsigned int PorousFlowFluidStateBase::_salt_component
protectedinherited

Salt component index.

Definition at line 131 of file PorousFlowFluidStateBase.h.

Referenced by PorousFlowFluidStateBase::saltComponentIndex().

◆ _T_c2k

const Real PorousFlowFluidStateBase::_T_c2k
protectedinherited

The documentation for this class was generated from the following files:
PorousFlowFluidStateBase::_empty_fsp
FluidStateProperties _empty_fsp
Empty FluidStateProperties object.
Definition: PorousFlowFluidStateBase.h:139
PorousFlowFluidStateBase::_gas_phase_number
unsigned int _gas_phase_number
Phase number of the gas phase.
Definition: PorousFlowFluidStateBase.h:125
PorousFlowFluidStateFlash::rachfordRiceDeriv
Real rachfordRiceDeriv(Real vf, std::vector< Real > &Zi, std::vector< Real > &Ki) const
Derivative of Rachford-Rice equation wrt vapor fraction.
Definition: PorousFlowFluidStateFlash.C:53
PorousFlowFluidStateFlash::vaporMassFraction
Real vaporMassFraction(Real Z0, Real K0, Real K1) const
Solves Rachford-Rice equation to provide vapor mass fraction.
Definition: PorousFlowFluidStateFlash.C:81
PorousFlowFluidStateBase::_gas_fluid_component
unsigned int _gas_fluid_component
Fluid component number of the gas phase.
Definition: PorousFlowFluidStateBase.h:129
PorousFlowFluidStateFlash::_nr_max_its
const Real _nr_max_its
Maximum number of iterations for the Newton-Raphson routine.
Definition: PorousFlowFluidStateFlash.h:80
PorousFlowFluidStateFlash::_nr_tol
const Real _nr_tol
Tolerance for Newton-Raphson iterations.
Definition: PorousFlowFluidStateFlash.h:82
PorousFlowFluidStateBase::_salt_component
const unsigned int _salt_component
Salt component index.
Definition: PorousFlowFluidStateBase.h:131
PorousFlowFluidStateBase::_aqueous_phase_number
const unsigned int _aqueous_phase_number
Phase number of the aqueous phase.
Definition: PorousFlowFluidStateBase.h:123
PorousFlowFluidStateBase::_num_phases
unsigned int _num_phases
Number of phases.
Definition: PorousFlowFluidStateBase.h:119
PorousFlowFluidStateBase::PorousFlowFluidStateBase
PorousFlowFluidStateBase(const InputParameters &parameters)
Definition: PorousFlowFluidStateBase.C:27
PorousFlowFluidStateBase::_num_components
unsigned int _num_components
Number of components.
Definition: PorousFlowFluidStateBase.h:121
PorousFlowFluidStateBase::_aqueous_fluid_component
const unsigned int _aqueous_fluid_component
Fluid component number of the aqueous component.
Definition: PorousFlowFluidStateBase.h:127
PorousFlowFluidStateFlash::rachfordRice
Real rachfordRice(Real vf, std::vector< Real > &Zi, std::vector< Real > &Ki) const
Rachford-Rice equation for vapor fraction.
Definition: PorousFlowFluidStateFlash.C:27