www.mooseframework.org
PorousFlowFluidStateFlash.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
11 
12 template <>
13 InputParameters
15 {
16  InputParameters params = validParams<PorousFlowFluidStateBase>();
17  params.addClassDescription("Compositional flash calculations for use in fluid state classes");
18  return params;
19 }
20 
21 PorousFlowFluidStateFlash::PorousFlowFluidStateFlash(const InputParameters & parameters)
22  : PorousFlowFluidStateBase(parameters), _nr_max_its(42), _nr_tol(1.0e-12)
23 {
24 }
25 
26 Real
28  std::vector<Real> & Zi,
29  std::vector<Real> & Ki) const
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 }
51 
52 Real
54  std::vector<Real> & Zi,
55  std::vector<Real> & Ki) const
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 }
79 
80 Real
81 PorousFlowFluidStateFlash::vaporMassFraction(Real Z0, Real K0, Real K1) const
82 {
83  return (Z0 * (K1 - K0) - (K1 - 1.0)) / ((K0 - 1.0) * (K1 - 1.0));
84 }
85 
86 DualReal
88  const DualReal & K0,
89  const DualReal & K1) const
90 {
91  return (Z0 * (K1 - K0) - (K1 - 1.0)) / ((K0 - 1.0) * (K1 - 1.0));
92 }
93 
94 Real
95 PorousFlowFluidStateFlash::vaporMassFraction(std::vector<Real> & Zi, std::vector<Real> & Ki) const
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 }
PorousFlowFluidStateFlash.h
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
PorousFlowFluidStateBase
Base class for fluid states for miscible multiphase flow in porous media.
Definition: PorousFlowFluidStateBase.h:55
validParams< PorousFlowFluidStateBase >
InputParameters validParams< PorousFlowFluidStateBase >()
Definition: PorousFlowFluidStateBase.C:14
PorousFlowFluidStateFlash::vaporMassFraction
Real vaporMassFraction(Real Z0, Real K0, Real K1) const
Solves Rachford-Rice equation to provide vapor mass fraction.
Definition: PorousFlowFluidStateFlash.C:81
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
validParams< PorousFlowFluidStateFlash >
InputParameters validParams< PorousFlowFluidStateFlash >()
Definition: PorousFlowFluidStateFlash.C:14
PorousFlowFluidStateFlash::PorousFlowFluidStateFlash
PorousFlowFluidStateFlash(const InputParameters &parameters)
Definition: PorousFlowFluidStateFlash.C:21
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