www.mooseframework.org
PorousFlowWaterVapor.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 
10 #include "PorousFlowWaterVapor.h"
12 #include "Conversion.h"
13 #include "MooseUtils.h"
14 
16 
19 {
21  params.addRequiredParam<UserObjectName>("water_fp", "The name of the user object for water");
22  params.addClassDescription("Fluid state class for water and vapor");
23  return params;
24 }
25 
28  _water_fp(getUserObject<SinglePhaseFluidProperties>("water_fp")),
29  _Mh2o(_water_fp.molarMass()),
30  _p_triple(_water_fp.triplePointPressure()),
31  _p_critical(_water_fp.criticalPressure()),
32  _T_triple(_water_fp.triplePointTemperature()),
33  _T_critical(_water_fp.criticalTemperature())
34 {
35  // Check that the correct FluidProperties UserObjects have been provided
36  if (_water_fp.fluidName() != "water")
37  paramError("water_fp", "A valid water FluidProperties UserObject must be provided in water_fp");
38 
39  // Set the number of phases and components, and their indexes
40  _num_phases = 2;
41  _num_components = 1;
43 
44  // Check that _aqueous_phase_number is <= total number of phases
46  paramError("liquid_phase_number",
47  "This value is larger than the possible number of phases ",
48  _num_phases);
49 
50  // Check that _fluid_component is <= total number of fluid components
52  paramError("fluid_component",
53  "This value is larger than the possible number of fluid components",
55 
57 }
58 
59 std::string
61 {
62  return "water-vapor";
63 }
64 
65 void
67  Real enthalpy,
68  unsigned int qp,
69  std::vector<FluidStateProperties> & fsp) const
70 {
71  // AD versions of primary variables
72  ADReal p = pressure;
73  Moose::derivInsert(p.derivatives(), _pidx, 1.0);
74  ADReal h = enthalpy;
75  Moose::derivInsert(h.derivatives(), _hidx, 1.0);
76 
77  thermophysicalProperties(p, h, qp, fsp);
78 }
79 
80 void
82  const ADReal & enthalpy,
83  unsigned int qp,
84  std::vector<FluidStateProperties> & fsp) const
85 {
86  FluidStatePhaseEnum phase_state;
87 
88  thermophysicalProperties(pressure, enthalpy, qp, phase_state, fsp);
89 }
90 
91 void
93  const ADReal & enthalpy,
94  unsigned int qp,
95  FluidStatePhaseEnum & phase_state,
96  std::vector<FluidStateProperties> & fsp) const
97 {
100 
101  ADReal Tsat = 0.0;
102  ADReal hl = 0.0;
103  ADReal hv = 0.0;
104 
105  // Determine the phase state of the system
106  if (pressure.value() >= _p_triple && pressure.value() <= _p_critical)
107  {
108  // Saturation temperature at the given pressure
110 
111  // Enthalpy of saturated liquid and saturated vapor
112  hl = _water_fp.h_from_p_T(pressure, Tsat - _dT);
113  hv = _water_fp.h_from_p_T(pressure, Tsat + _dT);
114 
115  if (enthalpy.value() < hl.value())
116  phase_state = FluidStatePhaseEnum::LIQUID;
117 
118  else if (enthalpy.value() >= hl.value() && enthalpy.value() <= hv.value())
119  phase_state = FluidStatePhaseEnum::TWOPHASE;
120 
121  else // h > hv
122  phase_state = FluidStatePhaseEnum::GAS;
123  }
124  else // p.value() > _p_critical
125  {
126  // Check whether the phase point is in the liquid or vapor state
127  const ADReal T = _water_fp.T_from_p_h(pressure, enthalpy);
128 
129  if (T.value() <= _T_critical)
130  phase_state = FluidStatePhaseEnum::LIQUID;
131  else
132  {
133  // The supercritical state is treated as a gas
134  phase_state = FluidStatePhaseEnum::GAS;
135  }
136  }
137 
138  // Calculate the properties for each phase as required
139  switch (phase_state)
140  {
142  {
143  gas.pressure = pressure + _pc.capillaryPressure(0.0, qp);
144  gas.saturation = 1.0;
145 
146  const ADReal T = _water_fp.T_from_p_h(gas.pressure, enthalpy);
147 
148  gas.temperature = T;
149  liquid.temperature = T;
150 
151  gas.density = _water_fp.rho_from_p_T(gas.pressure, T);
152  gas.viscosity = _water_fp.mu_from_p_T(gas.pressure, T);
153  gas.enthalpy = enthalpy;
154  gas.internal_energy = _water_fp.e_from_p_T(gas.pressure, T);
155  gas.mass_fraction[_fluid_component] = 1.0;
156 
157  break;
158  }
159 
161  {
162  const ADReal T = _water_fp.T_from_p_h(pressure, enthalpy);
163 
164  liquid.pressure = pressure;
165  liquid.temperature = T;
166  liquid.density = _water_fp.rho_from_p_T(pressure, T);
167  liquid.viscosity = _water_fp.mu_from_p_T(pressure, T);
168  liquid.enthalpy = enthalpy;
169  liquid.internal_energy = _water_fp.e_from_p_T(pressure, T);
170  liquid.saturation = 1.0;
171  liquid.mass_fraction[_fluid_component] = 1.0;
172 
173  break;
174  }
175 
177  {
178  // Latent heat of vaporization
179  const ADReal hvl = hv - hl;
180 
181  // Vapor quality
182  const ADReal X = (enthalpy - hl) / hvl;
183 
184  // Perturbed saturation temperature to ensure that the correct
185  // phase properties are calculated
186  const ADReal Tsatl = Tsat - _dT;
187  const ADReal Tsatv = Tsat + _dT;
188 
189  // Density
190  const ADReal rhol = _water_fp.rho_from_p_T(pressure, Tsatl);
191  const ADReal rhov = _water_fp.rho_from_p_T(pressure, Tsatv);
192 
193  // Vapor (gas) saturation
194  const ADReal satv = X * rhol / (rhov + X * (rhol - rhov));
195 
196  gas.temperature = Tsat;
197  gas.density = rhov;
198  gas.viscosity = _water_fp.mu_from_p_T(pressure, Tsatv);
199  gas.enthalpy = hv;
200  gas.internal_energy = _water_fp.e_from_p_T(pressure, Tsatv);
201  gas.saturation = satv;
202 
203  liquid.temperature = Tsat;
204  liquid.density = rhol;
205  liquid.viscosity = _water_fp.mu_from_p_T(pressure, Tsatl);
206  liquid.enthalpy = hl;
207  liquid.internal_energy = _water_fp.e_from_p_T(pressure, Tsatl);
208  liquid.saturation = 1.0 - satv;
209 
210  liquid.pressure = pressure;
211  gas.pressure = pressure + _pc.capillaryPressure(liquid.saturation, qp);
212 
213  gas.mass_fraction[_fluid_component] = 1.0;
214  liquid.mass_fraction[_fluid_component] = 1.0;
215 
216  break;
217  }
218  }
219 }
const unsigned int _pidx
Index of derivative wrt pressure.
const unsigned int _aqueous_phase_number
Phase number of the aqueous phase.
unsigned int _num_phases
Number of phases.
const unsigned int _hidx
Index of derivative wrt enthalpy.
static InputParameters validParams()
unsigned int _gas_phase_number
Phase number of the gas phase.
unsigned int _num_components
Number of components.
const Real _p_critical
Critical pressure of water (Pa)
void addRequiredParam(const std::string &name, const std::string &doc_string)
const Real _T_critical
Critical temperature of water (K)
virtual Real vaporTemperature(Real p) const
Vapor temperature.
virtual Real capillaryPressure(Real saturation, unsigned qp=0) const
Capillary pressure is calculated as a function of true saturation.
AD data structure to pass calculated thermophysical properties.
Common class for single phase fluid properties.
FluidStatePhaseEnum
Phase state enum.
void paramError(const std::string &param, Args... args) const
const Real _p_triple
Triple point pressure of water (Pa)
PorousFlowWaterVapor(const InputParameters &parameters)
const SinglePhaseFluidProperties & _water_fp
Fluid properties UserObject for water.
const PorousFlowCapillaryPressure & _pc
Capillary pressure UserObject.
const Real _dT
Perturbation applied to saturation temperature to move to gas/liquid phase.
static const std::string pressure
Definition: NS.h:56
virtual std::string fluidStateName() const override
Name of FluidState.
registerMooseObject("PorousFlowApp", PorousFlowWaterVapor)
void addClassDescription(const std::string &doc_string)
void derivInsert(NumberArray< N, Real > &derivs, dof_id_type index, Real value)
FluidStateProperties _empty_fsp
Empty FluidStateProperties object.
void thermophysicalProperties(Real pressure, Real enthalpy, unsigned int qp, std::vector< FluidStateProperties > &fsp) const override
Determines the complete thermophysical state of the system for a given set of primary variables...
const unsigned int _fluid_component
Fluid component number (only one fluid component in all phases)
Specialized class for water and vapor mixture using pressure and enthalpy.
std::vector< ADReal > mass_fraction
Base class for miscible multiphase flow classes with a single fluid component using a pressure and en...