www.mooseframework.org
PorousFlowBrine.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
3 /* */
4 /* All contents are licensed under LGPL V2.1 */
5 /* See LICENSE for full restrictions */
6 /****************************************************************/
7 
8 #include "PorousFlowBrine.h"
9 
10 template <>
11 InputParameters
13 {
14  InputParameters params = validParams<PorousFlowFluidPropertiesBase>();
15  params.addParam<bool>(
16  "compute_density_and_viscosity", true, "Compute the fluid density and viscosity");
17  params.addParam<bool>("compute_internal_energy", true, "Compute the fluid internal energy");
18  params.addParam<bool>("compute_enthalpy", true, "Compute the fluid enthalpy");
19  params.addCoupledVar("xnacl", 0, "The salt mass fraction in the brine (kg/kg)");
20  params.addClassDescription(
21  "This Material calculates fluid properties for brine at the quadpoints or nodes");
22  return params;
23 }
24 
25 PorousFlowBrine::PorousFlowBrine(const InputParameters & parameters)
26  : PorousFlowFluidPropertiesBase(parameters),
27  _compute_rho_mu(getParam<bool>("compute_density_and_viscosity")),
28  _compute_internal_energy(getParam<bool>("compute_internal_energy")),
29  _compute_enthalpy(getParam<bool>("compute_enthalpy")),
30  _density(_compute_rho_mu
31  ? (_nodal_material
32  ? &declareProperty<Real>("PorousFlow_fluid_phase_density_nodal" + _phase)
33  : &declareProperty<Real>("PorousFlow_fluid_phase_density_qp" + _phase))
34  : nullptr),
35  _ddensity_dp(
36  _compute_rho_mu
37  ? (_nodal_material
38  ? &declarePropertyDerivative<Real>(
39  "PorousFlow_fluid_phase_density_nodal" + _phase, _pressure_variable_name)
40  : &declarePropertyDerivative<Real>("PorousFlow_fluid_phase_density_qp" + _phase,
41  _pressure_variable_name))
42  : nullptr),
43  _ddensity_dT(
44  _compute_rho_mu
45  ? (_nodal_material
46  ? &declarePropertyDerivative<Real>("PorousFlow_fluid_phase_density_nodal" +
47  _phase,
48  _temperature_variable_name)
49  : &declarePropertyDerivative<Real>("PorousFlow_fluid_phase_density_qp" + _phase,
50  _temperature_variable_name))
51  : nullptr),
52 
53  _viscosity(_compute_rho_mu
54  ? (_nodal_material
55  ? &declareProperty<Real>("PorousFlow_viscosity_nodal" + _phase)
56  : &declareProperty<Real>("PorousFlow_viscosity_qp" + _phase))
57  : nullptr),
58  _dviscosity_dp(_compute_rho_mu
59  ? (_nodal_material
60  ? &declarePropertyDerivative<Real>(
61  "PorousFlow_viscosity_nodal" + _phase, _pressure_variable_name)
62  : &declarePropertyDerivative<Real>("PorousFlow_viscosity_qp" + _phase,
63  _pressure_variable_name))
64  : nullptr),
65  _dviscosity_dT(
66  _compute_rho_mu
67  ? (_nodal_material
68  ? &declarePropertyDerivative<Real>("PorousFlow_viscosity_nodal" + _phase,
69  _temperature_variable_name)
70  : &declarePropertyDerivative<Real>("PorousFlow_viscosity_qp" + _phase,
71  _temperature_variable_name))
72  : nullptr),
73 
74  _internal_energy(
75  _compute_internal_energy
76  ? (_nodal_material
77  ? &declareProperty<Real>("PorousFlow_fluid_phase_internal_energy_nodal" + _phase)
78  : &declareProperty<Real>("PorousFlow_fluid_phase_internal_energy_qp" + _phase))
79  : nullptr),
80  _dinternal_energy_dp(_compute_internal_energy
81  ? (_nodal_material
82  ? &declarePropertyDerivative<Real>(
83  "PorousFlow_fluid_phase_internal_energy_nodal" + _phase,
84  _pressure_variable_name)
85  : &declarePropertyDerivative<Real>(
86  "PorousFlow_fluid_phase_internal_energy_qp" + _phase,
87  _pressure_variable_name))
88  : nullptr),
89  _dinternal_energy_dT(_compute_internal_energy
90  ? (_nodal_material
91  ? &declarePropertyDerivative<Real>(
92  "PorousFlow_fluid_phase_internal_energy_nodal" + _phase,
93  _temperature_variable_name)
94  : &declarePropertyDerivative<Real>(
95  "PorousFlow_fluid_phase_internal_energy_qp" + _phase,
96  _temperature_variable_name))
97  : nullptr),
98 
99  _enthalpy(_compute_enthalpy
100  ? (_nodal_material
101  ? &declareProperty<Real>("PorousFlow_fluid_phase_enthalpy_nodal" + _phase)
102  : &declareProperty<Real>("PorousFlow_fluid_phase_enthalpy_qp" + _phase))
103  : nullptr),
104  _denthalpy_dp(
105  _compute_enthalpy
106  ? (_nodal_material
107  ? &declarePropertyDerivative<Real>(
108  "PorousFlow_fluid_phase_enthalpy_nodal" + _phase, _pressure_variable_name)
109  : &declarePropertyDerivative<Real>("PorousFlow_fluid_phase_enthalpy_qp" + _phase,
110  _pressure_variable_name))
111  : nullptr),
112  _denthalpy_dT(
113  _compute_enthalpy
114  ? (_nodal_material
115  ? &declarePropertyDerivative<Real>("PorousFlow_fluid_phase_enthalpy_nodal" +
116  _phase,
117  _temperature_variable_name)
118  : &declarePropertyDerivative<Real>("PorousFlow_fluid_phase_enthalpy_qp" + _phase,
119  _temperature_variable_name))
120  : nullptr),
121 
122  _xnacl(_nodal_material ? coupledNodalValue("xnacl") : coupledValue("xnacl"))
123 {
124  // BrineFluidProperties UserObject
125  std::string brine_name = name() + ":brine";
126  {
127  std::string class_name = "BrineFluidProperties";
128  InputParameters params = _app.getFactory().getValidParams(class_name);
129  _fe_problem.addUserObject(class_name, brine_name, params);
130  }
131  _brine_fp = &_fe_problem.getUserObject<BrineFluidProperties>(brine_name);
132 
133  // Water properties UserObject
135 }
136 
137 void
139 {
140  if (_compute_rho_mu)
141  (*_density)[_qp] =
144  (*_internal_energy)[_qp] =
145  _brine_fp->e(_porepressure[_qp][_phase_num], _temperature[_qp] + _t_c2k, _xnacl[_qp]);
146  if (_compute_enthalpy)
147  (*_enthalpy)[_qp] =
148  _brine_fp->h(_porepressure[_qp][_phase_num], _temperature[_qp] + _t_c2k, _xnacl[_qp]);
149 }
150 
151 void
153 {
154  const Real Tk = _temperature[_qp] + _t_c2k;
155 
156  if (_compute_rho_mu)
157  {
158  // Density and derivatives wrt pressure and temperature at the nodes
159  Real rho, drho_dp, drho_dT, drho_dx;
161  _porepressure[_qp][_phase_num], Tk, _xnacl[_qp], rho, drho_dp, drho_dT, drho_dx);
162  (*_density)[_qp] = rho;
163  (*_ddensity_dp)[_qp] = drho_dp;
164  (*_ddensity_dT)[_qp] = drho_dT;
165 
166  // Viscosity and derivatives wrt pressure and temperature at the nodes.
167  // Note that dmu_dp = dmu_drho * drho_dp
168  Real mu, dmu_drho, dmu_dT, dmu_dx;
169  // Viscosity calculation requires water density
170  Real rhow, drhow_dp, drhow_dT;
171  _water_fp->rho_dpT(_porepressure[_qp][_phase_num], Tk, rhow, drhow_dp, drhow_dT);
172  _brine_fp->mu_drhoTx(rhow, Tk, _xnacl[_qp], drhow_dT, mu, dmu_drho, dmu_dT, dmu_dx);
173  (*_viscosity)[_qp] = mu;
174  (*_dviscosity_dp)[_qp] = dmu_drho * drhow_dp;
175  (*_dviscosity_dT)[_qp] = dmu_dT;
176  }
177 
178  // Internal energy and derivatives wrt pressure and temperature at the nodes
180  {
181  Real e, de_dp, de_dT, de_dx;
182  _brine_fp->e_dpTx(_porepressure[_qp][_phase_num], Tk, _xnacl[_qp], e, de_dp, de_dT, de_dx);
183  (*_internal_energy)[_qp] = e;
184  (*_dinternal_energy_dp)[_qp] = de_dp;
185  (*_dinternal_energy_dT)[_qp] = de_dT;
186  }
187 
188  // Enthalpy and derivatives wrt pressure and temperature at the nodes
189  if (_compute_enthalpy)
190  {
191  Real h, dh_dp, dh_dT, dh_dx;
192  _brine_fp->h_dpTx(_porepressure[_qp][_phase_num], Tk, _xnacl[_qp], h, dh_dp, dh_dT, dh_dx);
193  (*_enthalpy)[_qp] = h;
194  (*_denthalpy_dp)[_qp] = dh_dp;
195  (*_denthalpy_dT)[_qp] = dh_dT;
196  }
197 }
virtual void rho_dpTx(Real pressure, Real temperature, Real xnacl, Real &rho, Real &drho_dp, Real &drho_dT, Real &drho_dx) const override
Density and its derivatives wrt pressure, temperature and mass fraction.
const BrineFluidProperties * _brine_fp
Brine Fluid properties UserObject.
virtual void rho_dpT(Real pressure, Real temperature, Real &rho, Real &drho_dp, Real &drho_dT) const =0
Density and its derivatives wrt pressure and temperature.
virtual void initQpStatefulProperties() override
InputParameters validParams< PorousFlowFluidPropertiesBase >()
const bool _compute_enthalpy
If true, this Material will compute enthalpy and its derivatives.
Brine (NaCl in H2O) fluid properties as a function of pressure (Pa), temperature (K) and NaCl mass fr...
virtual void h_dpTx(Real pressure, Real temperature, Real xnacl, Real &h, Real &dh_dp, Real &dh_dT, Real &dh_dx) const override
Enthalpy and derivatives wrt pressure, temperature and mass fraction.
virtual Real rho(Real pressure, Real temperature, Real xnacl) const override
Density.
const unsigned int _phase_num
Phase number of fluid.
const SinglePhaseFluidPropertiesPT * _water_fp
Water Fluid properties UserObject.
PorousFlowBrine(const InputParameters &parameters)
const bool _compute_rho_mu
If true, this Material will compute density and viscosity, and their derivatives. ...
virtual Real e(Real pressure, Real temperature, Real xnacl) const override
Internal energy.
Base class for fluid properties materials.
const bool _compute_internal_energy
If true, this Material will compute internal energy and its derivatives.
virtual void computeQpProperties() override
InputParameters validParams< PorousFlowBrine >()
virtual const SinglePhaseFluidPropertiesPT & getComponent(unsigned int component) const override
Get UserObject for specified component.
virtual Real h(Real pressure, Real temperature, Real xnacl) const override
Enthalpy.
virtual void mu_drhoTx(Real water_density, Real temperature, Real xnacl, Real dwater_density_dT, Real &mu, Real &dmu_drho, Real &dmu_dT, Real &dmu_dx) const override
Dynamic viscosity and its derivatives wrt density, temperature and mass fraction. ...
const VariableValue & _xnacl
NaCl mass fraction at the qps or nodes.
const MaterialProperty< Real > & _temperature
Fluid temperature at the nodes or quadpoints.
virtual void e_dpTx(Real pressure, Real temperature, Real xnacl, Real &e, Real &de_dp, Real &de_dT, Real &de_dx) const override
Internal energy and its derivatives wrt pressure, temperature and mass fraction.
const Real _t_c2k
Conversion from degrees Celsius to degrees Kelvin.
static const unsigned int WATER
Fluid component numbers for water and NaCl.
const MaterialProperty< std::vector< Real > > & _porepressure
Pore pressure at the nodes or quadpoints.