Line data Source code
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 :
12 : registerMooseObject("PorousFlowApp", PorousFlowBrine);
13 :
14 : InputParameters
15 1359 : PorousFlowBrine::validParams()
16 : {
17 1359 : InputParameters params = PorousFlowFluidPropertiesBase::validParams();
18 2718 : params.addParam<UserObjectName>("water_fp",
19 : "The name of the FluidProperties UserObject for water");
20 2718 : params.addCoupledVar("xnacl", 0, "The salt mass fraction in the brine (kg/kg)");
21 1359 : params.addClassDescription(
22 : "This Material calculates fluid properties for brine at the quadpoints or nodes");
23 1359 : return params;
24 0 : }
25 :
26 1062 : PorousFlowBrine::PorousFlowBrine(const InputParameters & parameters)
27 : : PorousFlowFluidPropertiesBase(parameters),
28 2124 : _ddensity_dX(_compute_rho_mu
29 2556 : ? (_nodal_material ? &declarePropertyDerivative<Real>(
30 1494 : "PorousFlow_fluid_phase_density_nodal" + _phase,
31 : _mass_fraction_variable_name)
32 2952 : : &declarePropertyDerivative<Real>(
33 2322 : "PorousFlow_fluid_phase_density_qp" + _phase,
34 : _mass_fraction_variable_name))
35 : : nullptr),
36 1062 : _dviscosity_dX(
37 1062 : _compute_rho_mu
38 1062 : ? (_nodal_material
39 2556 : ? &declarePropertyDerivative<Real>("PorousFlow_viscosity_nodal" + _phase,
40 : _mass_fraction_variable_name)
41 2952 : : &declarePropertyDerivative<Real>("PorousFlow_viscosity_qp" + _phase,
42 : _mass_fraction_variable_name))
43 : : nullptr),
44 2124 : _dinternal_energy_dX(_compute_internal_energy
45 1062 : ? (_nodal_material
46 1590 : ? &declarePropertyDerivative<Real>(
47 1194 : "PorousFlow_fluid_phase_internal_energy_nodal" + _phase,
48 : _mass_fraction_variable_name)
49 1854 : : &declarePropertyDerivative<Real>(
50 1590 : "PorousFlow_fluid_phase_internal_energy_qp" + _phase,
51 : _mass_fraction_variable_name))
52 : : nullptr),
53 2124 : _denthalpy_dX(_compute_enthalpy
54 2256 : ? (_nodal_material ? &declarePropertyDerivative<Real>(
55 1194 : "PorousFlow_fluid_phase_enthalpy_nodal" + _phase,
56 : _mass_fraction_variable_name)
57 2052 : : &declarePropertyDerivative<Real>(
58 1722 : "PorousFlow_fluid_phase_enthalpy_qp" + _phase,
59 : _mass_fraction_variable_name))
60 : : nullptr),
61 1992 : _is_xnacl_nodal(isCoupled("xnacl") ? getFieldVar("xnacl", 0)->isNodal() : false),
62 1725 : _xnacl(_nodal_material && _is_xnacl_nodal ? coupledDofValues("xnacl") : coupledValue("xnacl")),
63 2124 : _is_xnacl_pfvar(_dictator.isPorousFlowVariable(coupled("xnacl")))
64 : {
65 2124 : if (parameters.isParamSetByUser("water_fp"))
66 : {
67 330 : _water_fp = &getUserObject<SinglePhaseFluidProperties>("water_fp");
68 :
69 : // Check that a water userobject has actually been supplied
70 660 : if (_water_fp->fluidName() != "water")
71 0 : paramError("water_fp", "A water FluidProperties UserObject must be supplied");
72 : }
73 :
74 : // BrineFluidProperties UserObject
75 1062 : const std::string brine_name = name() + ":brine";
76 : {
77 1062 : const std::string class_name = "BrineFluidProperties";
78 1062 : InputParameters params = _app.getFactory().getValidParams(class_name);
79 :
80 2124 : if (parameters.isParamSetByUser("water_fp"))
81 660 : params.set<UserObjectName>("water_fp") = _water_fp->name();
82 :
83 1062 : if (_tid == 0)
84 891 : _fe_problem.addUserObject(class_name, brine_name, params);
85 1062 : }
86 1062 : _brine_fp = &_fe_problem.getUserObject<BrineFluidProperties>(brine_name);
87 1062 : }
88 :
89 : void
90 201844 : PorousFlowBrine::initQpStatefulProperties()
91 : {
92 201844 : if (_compute_rho_mu)
93 201844 : (*_density)[_qp] = _brine_fp->rho_from_p_T_X(
94 201844 : _porepressure[_qp][_phase_num], _temperature[_qp] + _t_c2k, _xnacl[_qp]);
95 201844 : if (_compute_internal_energy)
96 202 : (*_internal_energy)[_qp] = _brine_fp->e_from_p_T_X(
97 202 : _porepressure[_qp][_phase_num], _temperature[_qp] + _t_c2k, _xnacl[_qp]);
98 201844 : if (_compute_enthalpy)
99 244 : (*_enthalpy)[_qp] = _brine_fp->h_from_p_T_X(
100 244 : _porepressure[_qp][_phase_num], _temperature[_qp] + _t_c2k, _xnacl[_qp]);
101 201844 : }
102 :
103 : void
104 1240468 : PorousFlowBrine::computeQpProperties()
105 : {
106 1240468 : const Real Tk = _temperature[_qp] + _t_c2k;
107 :
108 1240468 : if (_compute_rho_mu)
109 : {
110 : // Density and derivatives wrt pressure and temperature
111 : Real rho, drho_dp, drho_dT, drho_dx;
112 1240468 : _brine_fp->rho_from_p_T_X(
113 1240468 : _porepressure[_qp][_phase_num], Tk, _xnacl[_qp], rho, drho_dp, drho_dT, drho_dx);
114 1240468 : (*_density)[_qp] = rho;
115 1240468 : (*_ddensity_dp)[_qp] = drho_dp;
116 1240468 : (*_ddensity_dT)[_qp] = drho_dT;
117 1240468 : if (_is_xnacl_pfvar)
118 640 : (*_ddensity_dX)[_qp] = drho_dx;
119 :
120 : // Viscosity and derivatives wrt pressure and temperature
121 : Real mu, dmu_dp, dmu_dT, dmu_dx;
122 1240468 : _brine_fp->mu_from_p_T_X(
123 1240468 : _porepressure[_qp][_phase_num], Tk, _xnacl[_qp], mu, dmu_dp, dmu_dT, dmu_dx);
124 1240468 : (*_viscosity)[_qp] = mu;
125 1240468 : (*_dviscosity_dp)[_qp] = dmu_dp;
126 1240468 : (*_dviscosity_dT)[_qp] = dmu_dT;
127 1240468 : if (_is_xnacl_pfvar)
128 640 : (*_dviscosity_dX)[_qp] = dmu_dx;
129 : }
130 :
131 : // Internal energy and derivatives wrt pressure and temperature
132 1240468 : if (_compute_internal_energy)
133 : {
134 : Real e, de_dp, de_dT, de_dx;
135 1208 : _brine_fp->e_from_p_T_X(
136 1208 : _porepressure[_qp][_phase_num], Tk, _xnacl[_qp], e, de_dp, de_dT, de_dx);
137 1208 : (*_internal_energy)[_qp] = e;
138 1208 : (*_dinternal_energy_dp)[_qp] = de_dp;
139 1208 : (*_dinternal_energy_dT)[_qp] = de_dT;
140 1208 : if (_is_xnacl_pfvar)
141 580 : (*_dinternal_energy_dX)[_qp] = de_dx;
142 : }
143 :
144 : // Enthalpy and derivatives wrt pressure and temperature
145 1240468 : if (_compute_enthalpy)
146 : {
147 : Real h, dh_dp, dh_dT, dh_dx;
148 1268 : _brine_fp->h_from_p_T_X(
149 1268 : _porepressure[_qp][_phase_num], Tk, _xnacl[_qp], h, dh_dp, dh_dT, dh_dx);
150 1268 : (*_enthalpy)[_qp] = h;
151 1268 : (*_denthalpy_dp)[_qp] = dh_dp;
152 1268 : (*_denthalpy_dT)[_qp] = dh_dT;
153 1268 : if (_is_xnacl_pfvar)
154 640 : (*_denthalpy_dX)[_qp] = dh_dx;
155 : }
156 1240468 : }
|