https://mooseframework.inl.gov
Loading...
Searching...
No Matches
PorousFlowBrine.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
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
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)");
22 "This Material calculates fluid properties for brine at the quadpoints or nodes");
23 return params;
24}
25
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 _is_xnacl_pfvar(_dictator.isPorousFlowVariable(coupled("xnacl")))
64{
65 if (parameters.isParamSetByUser("water_fp"))
66 {
67 _water_fp = &getUserObject<SinglePhaseFluidProperties>("water_fp");
68
69 // Check that a water userobject has actually been supplied
70 if (_water_fp->fluidName() != "water")
71 paramError("water_fp", "A water FluidProperties UserObject must be supplied");
72 }
73
74 // BrineFluidProperties UserObject
75 const std::string brine_name = name() + ":brine";
76 {
77 const std::string class_name = "BrineFluidProperties";
78 InputParameters params = _app.getFactory().getValidParams(class_name);
79
80 if (parameters.isParamSetByUser("water_fp"))
81 params.set<UserObjectName>("water_fp") = _water_fp->name();
82
83 if (_tid == 0)
84 _fe_problem.addUserObject(class_name, brine_name, params);
85 }
86 _brine_fp = &_fe_problem.getUserObject<BrineFluidProperties>(brine_name);
87}
88
89void
91{
93 (*_density)[_qp] = _brine_fp->rho_from_p_T_X(
96 (*_internal_energy)[_qp] = _brine_fp->e_from_p_T_X(
99 (*_enthalpy)[_qp] = _brine_fp->h_from_p_T_X(
101}
102
103void
105{
106 const Real Tk = _temperature[_qp] + _t_c2k;
107
108 if (_compute_rho_mu)
109 {
110 // Density and derivatives wrt pressure and temperature
111 Real rho, drho_dp, drho_dT, drho_dx;
113 _porepressure[_qp][_phase_num], Tk, _xnacl[_qp], rho, drho_dp, drho_dT, drho_dx);
114 (*_density)[_qp] = rho;
115 (*_ddensity_dp)[_qp] = drho_dp;
116 (*_ddensity_dT)[_qp] = drho_dT;
117 if (_is_xnacl_pfvar)
118 (*_ddensity_dX)[_qp] = drho_dx;
119
120 // Viscosity and derivatives wrt pressure and temperature
121 Real mu, dmu_dp, dmu_dT, dmu_dx;
123 _porepressure[_qp][_phase_num], Tk, _xnacl[_qp], mu, dmu_dp, dmu_dT, dmu_dx);
124 (*_viscosity)[_qp] = mu;
125 (*_dviscosity_dp)[_qp] = dmu_dp;
126 (*_dviscosity_dT)[_qp] = dmu_dT;
127 if (_is_xnacl_pfvar)
128 (*_dviscosity_dX)[_qp] = dmu_dx;
129 }
130
131 // Internal energy and derivatives wrt pressure and temperature
133 {
134 Real e, de_dp, de_dT, de_dx;
136 _porepressure[_qp][_phase_num], Tk, _xnacl[_qp], e, de_dp, de_dT, de_dx);
137 (*_internal_energy)[_qp] = e;
138 (*_dinternal_energy_dp)[_qp] = de_dp;
139 (*_dinternal_energy_dT)[_qp] = de_dT;
140 if (_is_xnacl_pfvar)
141 (*_dinternal_energy_dX)[_qp] = de_dx;
142 }
143
144 // Enthalpy and derivatives wrt pressure and temperature
146 {
147 Real h, dh_dp, dh_dT, dh_dx;
149 _porepressure[_qp][_phase_num], Tk, _xnacl[_qp], h, dh_dp, dh_dT, dh_dx);
150 (*_enthalpy)[_qp] = h;
151 (*_denthalpy_dp)[_qp] = dh_dp;
152 (*_denthalpy_dT)[_qp] = dh_dT;
153 if (_is_xnacl_pfvar)
154 (*_denthalpy_dX)[_qp] = dh_dx;
155 }
156}
const double mu
const double rho
registerMooseObject("PorousFlowApp", PorousFlowBrine)
const std::string name
Definition Setup.h:21
Brine (NaCl in H2O) fluid properties as a function of pressure (Pa), temperature (K) and NaCl mass fr...
virtual Real mu_from_p_T_X(Real pressure, Real temperature, Real xnacl) const override
virtual Real rho_from_p_T_X(Real pressure, Real temperature, Real xnacl) const override
FPADReal e_from_p_T_X(const FPADReal &pressure, const FPADReal &temperature, const FPADReal &xnacl) const
FPADReal h_from_p_T_X(const FPADReal &pressure, const FPADReal &temperature, const FPADReal &xnacl) const
bool isParamSetByUser(const std::string &name) const
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
T & set(const std::string &name, bool quiet_mode=false)
void addCoupledVar(const std::string &name, const std::string &doc_string)
const std::string & name() const
Fluid properties of Brine.
const VariableValue & _xnacl
NaCl mass fraction at the qps or nodes.
const BrineFluidProperties * _brine_fp
Brine fluid properties UserObject.
const SinglePhaseFluidProperties * _water_fp
Water fluid properties UserObject.
virtual void computeQpProperties() override
virtual void initQpStatefulProperties() override
static InputParameters validParams()
PorousFlowBrine(const InputParameters &parameters)
const bool _is_xnacl_pfvar
Flag to denote whether NaCl mass fraction is a nonlinear variable.
Base class for fluid properties materials.
const GenericMaterialProperty< Real, is_ad > & _temperature
Fluid temperature at the nodes or quadpoints.
const bool _compute_rho_mu
If true, this Material will compute density and viscosity, and their derivatives.
const bool _compute_enthalpy
If true, this Material will compute enthalpy and its derivatives.
const Real _t_c2k
Conversion from degrees Celsius to degrees Kelvin.
const GenericMaterialProperty< std::vector< Real >, is_ad > & _porepressure
Pore pressure at the nodes or quadpoints.
const bool _compute_internal_energy
If true, this Material will compute internal energy and its derivatives.
const unsigned int _phase_num
Phase number of fluid.
e e e e s T T T T T rho v v T e p T T virtual T std::string fluidName() const
Fluid name.
const T & getUserObject(const std::string &param_name, bool is_dependency=true) const