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

Compositional flash routines for miscible multiphase flow classes. More...

#include <PorousFlowFluidStateFlash.h>

Inheritance diagram for PorousFlowFluidStateFlash:
[legend]

Public Member Functions

 PorousFlowFluidStateFlash (const InputParameters &parameters)
 
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

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...
 

Detailed Description

Compositional flash routines for miscible multiphase flow classes.

Definition at line 31 of file PorousFlowFluidStateFlash.h.

Constructor & Destructor Documentation

◆ PorousFlowFluidStateFlash()

PorousFlowFluidStateFlash::PorousFlowFluidStateFlash ( const InputParameters &  parameters)

Definition at line 23 of file PorousFlowFluidStateFlash.C.

24  : GeneralUserObject(parameters), _nr_max_its(42), _nr_tol(1.0e-12)
25 {
26 }
const Real _nr_tol
Tolerance for Newton-Raphson iterations.
const Real _nr_max_its
Maximum number of iterations for the Newton-Raphson routine.

Member Function Documentation

◆ execute()

void PorousFlowFluidStateFlash::execute ( )
inlinefinal

Definition at line 37 of file PorousFlowFluidStateFlash.h.

37 {};

◆ finalize()

void PorousFlowFluidStateFlash::finalize ( )
inlinefinal

Definition at line 38 of file PorousFlowFluidStateFlash.h.

38 {};

◆ initialize()

void PorousFlowFluidStateFlash::initialize ( )
inlinefinal

Definition at line 36 of file PorousFlowFluidStateFlash.h.

36 {};

◆ phaseState()

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

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

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 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

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 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 }

◆ vaporMassFraction() [1/2]

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

Referenced by PorousFlowWaterNCG::saturationTwoPhase(), PorousFlowBrineCO2::saturationTwoPhase(), and 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

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

◆ _nr_max_its

const Real PorousFlowFluidStateFlash::_nr_max_its
protected

Maximum number of iterations for the Newton-Raphson routine.

Definition at line 101 of file PorousFlowFluidStateFlash.h.

Referenced by vaporMassFraction().

◆ _nr_tol

const Real PorousFlowFluidStateFlash::_nr_tol
protected

Tolerance for Newton-Raphson iterations.

Definition at line 103 of file PorousFlowFluidStateFlash.h.

Referenced by vaporMassFraction().


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