www.mooseframework.org
PorousFlowBrine.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 "PorousFlowBrine.h"
11 
12 registerMooseObject("PorousFlowApp", PorousFlowBrine);
13 
14 template <>
15 InputParameters
17 {
18  InputParameters params = validParams<PorousFlowFluidPropertiesBase>();
19  params.addParam<bool>(
20  "compute_density_and_viscosity", true, "Compute the fluid density and viscosity");
21  params.addParam<bool>("compute_internal_energy", true, "Compute the fluid internal energy");
22  params.addParam<bool>("compute_enthalpy", true, "Compute the fluid enthalpy");
23  params.addParam<UserObjectName>("water_fp",
24  "The name of the FluidProperties UserObject for water");
25  params.addCoupledVar("xnacl", 0, "The salt mass fraction in the brine (kg/kg)");
26  params.addClassDescription(
27  "This Material calculates fluid properties for brine at the quadpoints or nodes");
28  return params;
29 }
30 
31 PorousFlowBrine::PorousFlowBrine(const InputParameters & parameters)
32  : PorousFlowFluidPropertiesBase(parameters),
33  _compute_rho_mu(getParam<bool>("compute_density_and_viscosity")),
34  _compute_internal_energy(getParam<bool>("compute_internal_energy")),
35  _compute_enthalpy(getParam<bool>("compute_enthalpy")),
36  _density(_compute_rho_mu
37  ? (_nodal_material
38  ? &declareProperty<Real>("PorousFlow_fluid_phase_density_nodal" + _phase)
39  : &declareProperty<Real>("PorousFlow_fluid_phase_density_qp" + _phase))
40  : nullptr),
41  _ddensity_dp(
42  _compute_rho_mu
43  ? (_nodal_material
44  ? &declarePropertyDerivative<Real>(
45  "PorousFlow_fluid_phase_density_nodal" + _phase, _pressure_variable_name)
46  : &declarePropertyDerivative<Real>("PorousFlow_fluid_phase_density_qp" + _phase,
47  _pressure_variable_name))
48  : nullptr),
49  _ddensity_dT(_compute_rho_mu
50  ? (_nodal_material ? &declarePropertyDerivative<Real>(
51  "PorousFlow_fluid_phase_density_nodal" + _phase,
52  _temperature_variable_name)
53  : &declarePropertyDerivative<Real>(
54  "PorousFlow_fluid_phase_density_qp" + _phase,
55  _temperature_variable_name))
56  : nullptr),
57 
58  _viscosity(_compute_rho_mu
59  ? (_nodal_material
60  ? &declareProperty<Real>("PorousFlow_viscosity_nodal" + _phase)
61  : &declareProperty<Real>("PorousFlow_viscosity_qp" + _phase))
62  : nullptr),
63  _dviscosity_dp(_compute_rho_mu
64  ? (_nodal_material
65  ? &declarePropertyDerivative<Real>(
66  "PorousFlow_viscosity_nodal" + _phase, _pressure_variable_name)
67  : &declarePropertyDerivative<Real>("PorousFlow_viscosity_qp" + _phase,
68  _pressure_variable_name))
69  : nullptr),
70  _dviscosity_dT(
71  _compute_rho_mu
72  ? (_nodal_material
73  ? &declarePropertyDerivative<Real>("PorousFlow_viscosity_nodal" + _phase,
74  _temperature_variable_name)
75  : &declarePropertyDerivative<Real>("PorousFlow_viscosity_qp" + _phase,
76  _temperature_variable_name))
77  : nullptr),
78 
79  _internal_energy(
80  _compute_internal_energy
81  ? (_nodal_material
82  ? &declareProperty<Real>("PorousFlow_fluid_phase_internal_energy_nodal" + _phase)
83  : &declareProperty<Real>("PorousFlow_fluid_phase_internal_energy_qp" + _phase))
84  : nullptr),
85  _dinternal_energy_dp(_compute_internal_energy
86  ? (_nodal_material
87  ? &declarePropertyDerivative<Real>(
88  "PorousFlow_fluid_phase_internal_energy_nodal" + _phase,
89  _pressure_variable_name)
90  : &declarePropertyDerivative<Real>(
91  "PorousFlow_fluid_phase_internal_energy_qp" + _phase,
92  _pressure_variable_name))
93  : nullptr),
94  _dinternal_energy_dT(_compute_internal_energy
95  ? (_nodal_material
96  ? &declarePropertyDerivative<Real>(
97  "PorousFlow_fluid_phase_internal_energy_nodal" + _phase,
98  _temperature_variable_name)
99  : &declarePropertyDerivative<Real>(
100  "PorousFlow_fluid_phase_internal_energy_qp" + _phase,
101  _temperature_variable_name))
102  : nullptr),
103 
104  _enthalpy(_compute_enthalpy
105  ? (_nodal_material
106  ? &declareProperty<Real>("PorousFlow_fluid_phase_enthalpy_nodal" + _phase)
107  : &declareProperty<Real>("PorousFlow_fluid_phase_enthalpy_qp" + _phase))
108  : nullptr),
109  _denthalpy_dp(
110  _compute_enthalpy
111  ? (_nodal_material
112  ? &declarePropertyDerivative<Real>(
113  "PorousFlow_fluid_phase_enthalpy_nodal" + _phase, _pressure_variable_name)
114  : &declarePropertyDerivative<Real>("PorousFlow_fluid_phase_enthalpy_qp" + _phase,
115  _pressure_variable_name))
116  : nullptr),
117  _denthalpy_dT(_compute_enthalpy
118  ? (_nodal_material ? &declarePropertyDerivative<Real>(
119  "PorousFlow_fluid_phase_enthalpy_nodal" + _phase,
120  _temperature_variable_name)
121  : &declarePropertyDerivative<Real>(
122  "PorousFlow_fluid_phase_enthalpy_qp" + _phase,
123  _temperature_variable_name))
124  : nullptr),
125 
126  _xnacl(_nodal_material ? coupledDofValues("xnacl") : coupledValue("xnacl"))
127 {
128  if (parameters.isParamSetByUser("water_fp"))
129  {
130  _water_fp = &getUserObject<SinglePhaseFluidProperties>("water_fp");
131 
132  // Check that a water userobject has actually been supplied
133  if (_water_fp->fluidName() != "water")
134  paramError("water_fp", "A water FluidProperties UserObject must be supplied");
135  }
136 
137  // BrineFluidProperties UserObject
138  const std::string brine_name = name() + ":brine";
139  {
140  const std::string class_name = "BrineFluidProperties";
141  InputParameters params = _app.getFactory().getValidParams(class_name);
142 
143  if (parameters.isParamSetByUser("water_fp"))
144  params.set<UserObjectName>("water_fp") = _water_fp->name();
145 
146  if (_tid == 0)
147  _fe_problem.addUserObject(class_name, brine_name, params);
148  }
149  _brine_fp = &_fe_problem.getUserObjectTempl<BrineFluidProperties>(brine_name);
150 }
151 
152 void
154 {
155  if (_compute_rho_mu)
156  (*_density)[_qp] = _brine_fp->rho_from_p_T_X(
157  _porepressure[_qp][_phase_num], _temperature[_qp] + _t_c2k, _xnacl[_qp]);
159  (*_internal_energy)[_qp] = _brine_fp->e_from_p_T_X(
160  _porepressure[_qp][_phase_num], _temperature[_qp] + _t_c2k, _xnacl[_qp]);
161  if (_compute_enthalpy)
162  (*_enthalpy)[_qp] = _brine_fp->h_from_p_T_X(
163  _porepressure[_qp][_phase_num], _temperature[_qp] + _t_c2k, _xnacl[_qp]);
164 }
165 
166 void
168 {
169  const Real Tk = _temperature[_qp] + _t_c2k;
170 
171  if (_compute_rho_mu)
172  {
173  // Density and derivatives wrt pressure and temperature
174  Real rho, drho_dp, drho_dT, drho_dx;
176  _porepressure[_qp][_phase_num], Tk, _xnacl[_qp], rho, drho_dp, drho_dT, drho_dx);
177  (*_density)[_qp] = rho;
178  (*_ddensity_dp)[_qp] = drho_dp;
179  (*_ddensity_dT)[_qp] = drho_dT;
180 
181  // Viscosity and derivatives wrt pressure and temperature
182  Real mu, dmu_dp, dmu_dT, dmu_dx;
184  _porepressure[_qp][_phase_num], Tk, _xnacl[_qp], mu, dmu_dp, dmu_dT, dmu_dx);
185  (*_viscosity)[_qp] = mu;
186  (*_dviscosity_dp)[_qp] = dmu_dp;
187  (*_dviscosity_dT)[_qp] = dmu_dT;
188  }
189 
190  // Internal energy and derivatives wrt pressure and temperature
192  {
193  Real e, de_dp, de_dT, de_dx;
195  _porepressure[_qp][_phase_num], Tk, _xnacl[_qp], e, de_dp, de_dT, de_dx);
196  (*_internal_energy)[_qp] = e;
197  (*_dinternal_energy_dp)[_qp] = de_dp;
198  (*_dinternal_energy_dT)[_qp] = de_dT;
199  }
200 
201  // Enthalpy and derivatives wrt pressure and temperature
202  if (_compute_enthalpy)
203  {
204  Real h, dh_dp, dh_dT, dh_dx;
206  _porepressure[_qp][_phase_num], Tk, _xnacl[_qp], h, dh_dp, dh_dT, dh_dx);
207  (*_enthalpy)[_qp] = h;
208  (*_denthalpy_dp)[_qp] = dh_dp;
209  (*_denthalpy_dT)[_qp] = dh_dT;
210  }
211 }
validParams< PorousFlowFluidPropertiesBase >
InputParameters validParams< PorousFlowFluidPropertiesBase >()
Definition: PorousFlowFluidPropertiesBase.C:14
PorousFlowFluidPropertiesBase::_t_c2k
const Real _t_c2k
Conversion from degrees Celsius to degrees Kelvin.
Definition: PorousFlowFluidPropertiesBase.h:39
PorousFlowFluidPropertiesBase::_porepressure
const MaterialProperty< std::vector< Real > > & _porepressure
Pore pressure at the nodes or quadpoints.
Definition: PorousFlowFluidPropertiesBase.h:33
PorousFlowBrine::_compute_enthalpy
const bool _compute_enthalpy
If true, this Material will compute enthalpy and its derivatives.
Definition: PorousFlowBrine.h:40
validParams< PorousFlowBrine >
InputParameters validParams< PorousFlowBrine >()
Definition: PorousFlowBrine.C:16
registerMooseObject
registerMooseObject("PorousFlowApp", PorousFlowBrine)
PorousFlowFluidPropertiesBase
Base class for fluid properties materials.
Definition: PorousFlowFluidPropertiesBase.h:24
BrineFluidProperties::e_from_p_T_X
FPDualReal e_from_p_T_X(const FPDualReal &pressure, const FPDualReal &temperature, const FPDualReal &xnacl) const
Definition: BrineFluidProperties.C:389
PorousFlowBrine::computeQpProperties
virtual void computeQpProperties() override
Definition: PorousFlowBrine.C:167
PorousFlowBrine::_compute_rho_mu
const bool _compute_rho_mu
If true, this Material will compute density and viscosity, and their derivatives.
Definition: PorousFlowBrine.h:34
BrineFluidProperties::mu_from_p_T_X
virtual Real mu_from_p_T_X(Real pressure, Real temperature, Real xnacl) const override
Definition: BrineFluidProperties.C:211
PorousFlowBrine::_compute_internal_energy
const bool _compute_internal_energy
If true, this Material will compute internal energy and its derivatives.
Definition: PorousFlowBrine.h:37
PorousFlowBrine
Fluid properties of Brine.
Definition: PorousFlowBrine.h:24
PorousFlowBrine::_water_fp
const SinglePhaseFluidProperties * _water_fp
Water fluid properties UserObject.
Definition: PorousFlowBrine.h:82
name
const std::string name
Definition: Setup.h:21
PorousFlowBrine.h
BrineFluidProperties::rho_from_p_T_X
virtual Real rho_from_p_T_X(Real pressure, Real temperature, Real xnacl) const override
Definition: BrineFluidProperties.C:171
BrineFluidProperties::h_from_p_T_X
FPDualReal h_from_p_T_X(const FPDualReal &pressure, const FPDualReal &temperature, const FPDualReal &xnacl) const
Definition: BrineFluidProperties.C:264
PorousFlowBrine::_xnacl
const VariableValue & _xnacl
NaCl mass fraction at the qps or nodes.
Definition: PorousFlowBrine.h:85
PorousFlowFluidPropertiesBase::_temperature
const MaterialProperty< Real > & _temperature
Fluid temperature at the nodes or quadpoints.
Definition: PorousFlowFluidPropertiesBase.h:36
PorousFlowMaterialBase::_phase_num
const unsigned int _phase_num
Phase number of fluid.
Definition: PorousFlowMaterialBase.h:34
PorousFlowBrine::PorousFlowBrine
PorousFlowBrine(const InputParameters &parameters)
Definition: PorousFlowBrine.C:31
PorousFlowBrine::_brine_fp
const BrineFluidProperties * _brine_fp
Brine fluid properties UserObject.
Definition: PorousFlowBrine.h:79
BrineFluidProperties
Brine (NaCl in H2O) fluid properties as a function of pressure (Pa), temperature (K) and NaCl mass fr...
Definition: BrineFluidProperties.h:38
PorousFlowBrine::initQpStatefulProperties
virtual void initQpStatefulProperties() override
Definition: PorousFlowBrine.C:153