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 
16 {
18  params.addParam<UserObjectName>("water_fp",
19  "The name of the FluidProperties UserObject for water");
20  params.addCoupledVar("xnacl", 0, "The salt mass fraction in the brine (kg/kg)");
21  params.addClassDescription(
22  "This Material calculates fluid properties for brine at the quadpoints or nodes");
23  return params;
24 }
25 
27  : PorousFlowFluidPropertiesBase(parameters),
28  _ddensity_dX(_compute_rho_mu
29  ? (_nodal_material ? &declarePropertyDerivative<Real>(
30  "PorousFlow_fluid_phase_density_nodal" + _phase,
31  _mass_fraction_variable_name)
32  : &declarePropertyDerivative<Real>(
33  "PorousFlow_fluid_phase_density_qp" + _phase,
34  _mass_fraction_variable_name))
35  : nullptr),
36  _dviscosity_dX(
37  _compute_rho_mu
38  ? (_nodal_material
39  ? &declarePropertyDerivative<Real>("PorousFlow_viscosity_nodal" + _phase,
40  _mass_fraction_variable_name)
41  : &declarePropertyDerivative<Real>("PorousFlow_viscosity_qp" + _phase,
42  _mass_fraction_variable_name))
43  : nullptr),
44  _dinternal_energy_dX(_compute_internal_energy
45  ? (_nodal_material
46  ? &declarePropertyDerivative<Real>(
47  "PorousFlow_fluid_phase_internal_energy_nodal" + _phase,
48  _mass_fraction_variable_name)
49  : &declarePropertyDerivative<Real>(
50  "PorousFlow_fluid_phase_internal_energy_qp" + _phase,
51  _mass_fraction_variable_name))
52  : nullptr),
53  _denthalpy_dX(_compute_enthalpy
54  ? (_nodal_material ? &declarePropertyDerivative<Real>(
55  "PorousFlow_fluid_phase_enthalpy_nodal" + _phase,
56  _mass_fraction_variable_name)
57  : &declarePropertyDerivative<Real>(
58  "PorousFlow_fluid_phase_enthalpy_qp" + _phase,
59  _mass_fraction_variable_name))
60  : nullptr),
61  _is_xnacl_nodal(isCoupled("xnacl") ? getFieldVar("xnacl", 0)->isNodal() : false),
62  _xnacl(_nodal_material && _is_xnacl_nodal ? coupledDofValues("xnacl") : coupledValue("xnacl"))
63 {
64  if (parameters.isParamSetByUser("water_fp"))
65  {
66  _water_fp = &getUserObject<SinglePhaseFluidProperties>("water_fp");
67 
68  // Check that a water userobject has actually been supplied
69  if (_water_fp->fluidName() != "water")
70  paramError("water_fp", "A water FluidProperties UserObject must be supplied");
71  }
72 
73  // BrineFluidProperties UserObject
74  const std::string brine_name = name() + ":brine";
75  {
76  const std::string class_name = "BrineFluidProperties";
77  InputParameters params = _app.getFactory().getValidParams(class_name);
78 
79  if (parameters.isParamSetByUser("water_fp"))
80  params.set<UserObjectName>("water_fp") = _water_fp->name();
81 
82  if (_tid == 0)
83  _fe_problem.addUserObject(class_name, brine_name, params);
84  }
85  _brine_fp = &_fe_problem.getUserObject<BrineFluidProperties>(brine_name);
86 }
87 
88 void
90 {
91  if (_compute_rho_mu)
92  (*_density)[_qp] = _brine_fp->rho_from_p_T_X(
93  _porepressure[_qp][_phase_num], _temperature[_qp] + _t_c2k, _xnacl[_qp]);
95  (*_internal_energy)[_qp] = _brine_fp->e_from_p_T_X(
96  _porepressure[_qp][_phase_num], _temperature[_qp] + _t_c2k, _xnacl[_qp]);
98  (*_enthalpy)[_qp] = _brine_fp->h_from_p_T_X(
99  _porepressure[_qp][_phase_num], _temperature[_qp] + _t_c2k, _xnacl[_qp]);
100 }
101 
102 void
104 {
105  const Real Tk = _temperature[_qp] + _t_c2k;
106 
107  if (_compute_rho_mu)
108  {
109  // Density and derivatives wrt pressure and temperature
110  Real rho, drho_dp, drho_dT, drho_dx;
112  _porepressure[_qp][_phase_num], Tk, _xnacl[_qp], rho, drho_dp, drho_dT, drho_dx);
113  (*_density)[_qp] = rho;
114  (*_ddensity_dp)[_qp] = drho_dp;
115  (*_ddensity_dT)[_qp] = drho_dT;
116  (*_ddensity_dX)[_qp] = drho_dx;
117 
118  // Viscosity and derivatives wrt pressure and temperature
119  Real mu, dmu_dp, dmu_dT, dmu_dx;
121  _porepressure[_qp][_phase_num], Tk, _xnacl[_qp], mu, dmu_dp, dmu_dT, dmu_dx);
122  (*_viscosity)[_qp] = mu;
123  (*_dviscosity_dp)[_qp] = dmu_dp;
124  (*_dviscosity_dT)[_qp] = dmu_dT;
125  (*_dviscosity_dX)[_qp] = dmu_dx;
126  }
127 
128  // Internal energy and derivatives wrt pressure and temperature
130  {
131  Real e, de_dp, de_dT, de_dx;
133  _porepressure[_qp][_phase_num], Tk, _xnacl[_qp], e, de_dp, de_dT, de_dx);
134  (*_internal_energy)[_qp] = e;
135  (*_dinternal_energy_dp)[_qp] = de_dp;
136  (*_dinternal_energy_dT)[_qp] = de_dT;
137  (*_dinternal_energy_dX)[_qp] = de_dx;
138  }
139 
140  // Enthalpy and derivatives wrt pressure and temperature
141  if (_compute_enthalpy)
142  {
143  Real h, dh_dp, dh_dT, dh_dx;
145  _porepressure[_qp][_phase_num], Tk, _xnacl[_qp], h, dh_dp, dh_dT, dh_dx);
146  (*_enthalpy)[_qp] = h;
147  (*_denthalpy_dp)[_qp] = dh_dp;
148  (*_denthalpy_dT)[_qp] = dh_dT;
149  (*_denthalpy_dX)[_qp] = dh_dx;
150  }
151 }
const bool _compute_internal_energy
If true, this Material will compute internal energy and its derivatives.
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
virtual Real rho_from_p_T_X(Real pressure, Real temperature, Real xnacl) const override
const BrineFluidProperties * _brine_fp
Brine fluid properties UserObject.
T & set(const std::string &name, bool quiet_mode=false)
virtual void initQpStatefulProperties() override
Base class for fluid properties materials.
virtual Real mu_from_p_T_X(Real pressure, Real temperature, Real xnacl) const override
Brine (NaCl in H2O) fluid properties as a function of pressure (Pa), temperature (K) and NaCl mass fr...
static InputParameters validParams()
virtual const std::string & name() const
const unsigned int _phase_num
Phase number of fluid.
const Real _t_c2k
Conversion from degrees Celsius to degrees Kelvin.
const SinglePhaseFluidProperties * _water_fp
Water fluid properties UserObject.
static const std::string mu
Definition: NS.h:122
const std::string name
Definition: Setup.h:20
PorousFlowBrine(const InputParameters &parameters)
const GenericMaterialProperty< Real, is_ad > & _temperature
Fluid temperature at the nodes or quadpoints.
registerMooseObject("PorousFlowApp", PorousFlowBrine)
const bool _compute_enthalpy
If true, this Material will compute enthalpy and its derivatives.
const T & getUserObject(const std::string &param_name, bool is_dependency=true) const
void addCoupledVar(const std::string &name, const std::string &doc_string)
Fluid properties of Brine.
bool isParamSetByUser(const std::string &name) const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual void computeQpProperties() override
void addClassDescription(const std::string &doc_string)
FPDualReal e_from_p_T_X(const FPDualReal &pressure, const FPDualReal &temperature, const FPDualReal &xnacl) const
FPDualReal h_from_p_T_X(const FPDualReal &pressure, const FPDualReal &temperature, const FPDualReal &xnacl) const
const VariableValue & _xnacl
NaCl mass fraction at the qps or nodes.
const GenericMaterialProperty< std::vector< Real >, is_ad > & _porepressure
Pore pressure at the nodes or quadpoints.
const bool _compute_rho_mu
If true, this Material will compute density and viscosity, and their derivatives. ...