LCOV - code coverage report
Current view: top level - src/materials - PorousFlowBrine.C (source / functions) Hit Total Coverage
Test: porous_flow Test Coverage Lines: 123 123 100.0 %
Date: 2017-11-17 17:48:31 Functions: 6 6 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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
      12           3 : validParams<PorousFlowBrine>()
      13             : {
      14           3 :   InputParameters params = validParams<PorousFlowFluidPropertiesBase>();
      15           9 :   params.addParam<bool>(
      16           3 :       "compute_density_and_viscosity", true, "Compute the fluid density and viscosity");
      17           9 :   params.addParam<bool>("compute_internal_energy", true, "Compute the fluid internal energy");
      18           9 :   params.addParam<bool>("compute_enthalpy", true, "Compute the fluid enthalpy");
      19           9 :   params.addCoupledVar("xnacl", 0, "The salt mass fraction in the brine (kg/kg)");
      20           6 :   params.addClassDescription(
      21           3 :       "This Material calculates fluid properties for brine at the quadpoints or nodes");
      22           3 :   return params;
      23             : }
      24             : 
      25           9 : PorousFlowBrine::PorousFlowBrine(const InputParameters & parameters)
      26             :   : PorousFlowFluidPropertiesBase(parameters),
      27          27 :     _compute_rho_mu(getParam<bool>("compute_density_and_viscosity")),
      28          27 :     _compute_internal_energy(getParam<bool>("compute_internal_energy")),
      29          27 :     _compute_enthalpy(getParam<bool>("compute_enthalpy")),
      30           9 :     _density(_compute_rho_mu
      31           9 :                  ? (_nodal_material
      32          27 :                         ? &declareProperty<Real>("PorousFlow_fluid_phase_density_nodal" + _phase)
      33          21 :                         : &declareProperty<Real>("PorousFlow_fluid_phase_density_qp" + _phase))
      34             :                  : nullptr),
      35             :     _ddensity_dp(
      36           9 :         _compute_rho_mu
      37           9 :             ? (_nodal_material
      38          18 :                    ? &declarePropertyDerivative<Real>(
      39          21 :                          "PorousFlow_fluid_phase_density_nodal" + _phase, _pressure_variable_name)
      40          21 :                    : &declarePropertyDerivative<Real>("PorousFlow_fluid_phase_density_qp" + _phase,
      41          33 :                                                       _pressure_variable_name))
      42             :             : nullptr),
      43             :     _ddensity_dT(
      44           9 :         _compute_rho_mu
      45           9 :             ? (_nodal_material
      46          33 :                    ? &declarePropertyDerivative<Real>("PorousFlow_fluid_phase_density_nodal" +
      47             :                                                           _phase,
      48          21 :                                                       _temperature_variable_name)
      49          21 :                    : &declarePropertyDerivative<Real>("PorousFlow_fluid_phase_density_qp" + _phase,
      50          33 :                                                       _temperature_variable_name))
      51             :             : nullptr),
      52             : 
      53           9 :     _viscosity(_compute_rho_mu
      54           9 :                    ? (_nodal_material
      55          27 :                           ? &declareProperty<Real>("PorousFlow_viscosity_nodal" + _phase)
      56          21 :                           : &declareProperty<Real>("PorousFlow_viscosity_qp" + _phase))
      57             :                    : nullptr),
      58           9 :     _dviscosity_dp(_compute_rho_mu
      59           9 :                        ? (_nodal_material
      60          18 :                               ? &declarePropertyDerivative<Real>(
      61          21 :                                     "PorousFlow_viscosity_nodal" + _phase, _pressure_variable_name)
      62          21 :                               : &declarePropertyDerivative<Real>("PorousFlow_viscosity_qp" + _phase,
      63          33 :                                                                  _pressure_variable_name))
      64             :                        : nullptr),
      65             :     _dviscosity_dT(
      66           9 :         _compute_rho_mu
      67           9 :             ? (_nodal_material
      68          33 :                    ? &declarePropertyDerivative<Real>("PorousFlow_viscosity_nodal" + _phase,
      69          21 :                                                       _temperature_variable_name)
      70          21 :                    : &declarePropertyDerivative<Real>("PorousFlow_viscosity_qp" + _phase,
      71          33 :                                                       _temperature_variable_name))
      72             :             : nullptr),
      73             : 
      74             :     _internal_energy(
      75           9 :         _compute_internal_energy
      76           9 :             ? (_nodal_material
      77          27 :                    ? &declareProperty<Real>("PorousFlow_fluid_phase_internal_energy_nodal" + _phase)
      78          21 :                    : &declareProperty<Real>("PorousFlow_fluid_phase_internal_energy_qp" + _phase))
      79             :             : nullptr),
      80           9 :     _dinternal_energy_dp(_compute_internal_energy
      81           9 :                              ? (_nodal_material
      82          18 :                                     ? &declarePropertyDerivative<Real>(
      83          15 :                                           "PorousFlow_fluid_phase_internal_energy_nodal" + _phase,
      84          21 :                                           _pressure_variable_name)
      85             :                                     : &declarePropertyDerivative<Real>(
      86          21 :                                           "PorousFlow_fluid_phase_internal_energy_qp" + _phase,
      87          33 :                                           _pressure_variable_name))
      88             :                              : nullptr),
      89           9 :     _dinternal_energy_dT(_compute_internal_energy
      90           9 :                              ? (_nodal_material
      91          18 :                                     ? &declarePropertyDerivative<Real>(
      92          15 :                                           "PorousFlow_fluid_phase_internal_energy_nodal" + _phase,
      93          21 :                                           _temperature_variable_name)
      94             :                                     : &declarePropertyDerivative<Real>(
      95          21 :                                           "PorousFlow_fluid_phase_internal_energy_qp" + _phase,
      96          33 :                                           _temperature_variable_name))
      97             :                              : nullptr),
      98             : 
      99           9 :     _enthalpy(_compute_enthalpy
     100           9 :                   ? (_nodal_material
     101          21 :                          ? &declareProperty<Real>("PorousFlow_fluid_phase_enthalpy_nodal" + _phase)
     102          21 :                          : &declareProperty<Real>("PorousFlow_fluid_phase_enthalpy_qp" + _phase))
     103             :                   : nullptr),
     104             :     _denthalpy_dp(
     105           9 :         _compute_enthalpy
     106           9 :             ? (_nodal_material
     107          12 :                    ? &declarePropertyDerivative<Real>(
     108           9 :                          "PorousFlow_fluid_phase_enthalpy_nodal" + _phase, _pressure_variable_name)
     109          21 :                    : &declarePropertyDerivative<Real>("PorousFlow_fluid_phase_enthalpy_qp" + _phase,
     110          33 :                                                       _pressure_variable_name))
     111             :             : nullptr),
     112             :     _denthalpy_dT(
     113           9 :         _compute_enthalpy
     114           9 :             ? (_nodal_material
     115          21 :                    ? &declarePropertyDerivative<Real>("PorousFlow_fluid_phase_enthalpy_nodal" +
     116             :                                                           _phase,
     117           9 :                                                       _temperature_variable_name)
     118          21 :                    : &declarePropertyDerivative<Real>("PorousFlow_fluid_phase_enthalpy_qp" + _phase,
     119          33 :                                                       _temperature_variable_name))
     120             :             : nullptr),
     121             : 
     122         243 :     _xnacl(_nodal_material ? coupledNodalValue("xnacl") : coupledValue("xnacl"))
     123             : {
     124             :   // BrineFluidProperties UserObject
     125           9 :   std::string brine_name = name() + ":brine";
     126             :   {
     127           9 :     std::string class_name = "BrineFluidProperties";
     128          27 :     InputParameters params = _app.getFactory().getValidParams(class_name);
     129          27 :     _fe_problem.addUserObject(class_name, brine_name, params);
     130             :   }
     131           9 :   _brine_fp = &_fe_problem.getUserObject<BrineFluidProperties>(brine_name);
     132             : 
     133             :   // Water properties UserObject
     134           9 :   _water_fp = &_brine_fp->getComponent(BrineFluidProperties::WATER);
     135           9 : }
     136             : 
     137             : void
     138           8 : PorousFlowBrine::initQpStatefulProperties()
     139             : {
     140           8 :   if (_compute_rho_mu)
     141          16 :     (*_density)[_qp] =
     142          32 :         _brine_fp->rho(_porepressure[_qp][_phase_num], _temperature[_qp] + _t_c2k, _xnacl[_qp]);
     143           8 :   if (_compute_internal_energy)
     144          16 :     (*_internal_energy)[_qp] =
     145          32 :         _brine_fp->e(_porepressure[_qp][_phase_num], _temperature[_qp] + _t_c2k, _xnacl[_qp]);
     146           8 :   if (_compute_enthalpy)
     147           8 :     (*_enthalpy)[_qp] =
     148          16 :         _brine_fp->h(_porepressure[_qp][_phase_num], _temperature[_qp] + _t_c2k, _xnacl[_qp]);
     149           8 : }
     150             : 
     151             : void
     152          22 : PorousFlowBrine::computeQpProperties()
     153             : {
     154          44 :   const Real Tk = _temperature[_qp] + _t_c2k;
     155             : 
     156          22 :   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;
     160          66 :     _brine_fp->rho_dpTx(
     161          66 :         _porepressure[_qp][_phase_num], Tk, _xnacl[_qp], rho, drho_dp, drho_dT, drho_dx);
     162          44 :     (*_density)[_qp] = rho;
     163          44 :     (*_ddensity_dp)[_qp] = drho_dp;
     164          44 :     (*_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          44 :     _water_fp->rho_dpT(_porepressure[_qp][_phase_num], Tk, rhow, drhow_dp, drhow_dT);
     172          44 :     _brine_fp->mu_drhoTx(rhow, Tk, _xnacl[_qp], drhow_dT, mu, dmu_drho, dmu_dT, dmu_dx);
     173          44 :     (*_viscosity)[_qp] = mu;
     174          44 :     (*_dviscosity_dp)[_qp] = dmu_drho * drhow_dp;
     175          44 :     (*_dviscosity_dT)[_qp] = dmu_dT;
     176             :   }
     177             : 
     178             :   // Internal energy and derivatives wrt pressure and temperature at the nodes
     179          22 :   if (_compute_internal_energy)
     180             :   {
     181             :     Real e, de_dp, de_dT, de_dx;
     182          66 :     _brine_fp->e_dpTx(_porepressure[_qp][_phase_num], Tk, _xnacl[_qp], e, de_dp, de_dT, de_dx);
     183          44 :     (*_internal_energy)[_qp] = e;
     184          44 :     (*_dinternal_energy_dp)[_qp] = de_dp;
     185          44 :     (*_dinternal_energy_dT)[_qp] = de_dT;
     186             :   }
     187             : 
     188             :   // Enthalpy and derivatives wrt pressure and temperature at the nodes
     189          22 :   if (_compute_enthalpy)
     190             :   {
     191             :     Real h, dh_dp, dh_dT, dh_dx;
     192          42 :     _brine_fp->h_dpTx(_porepressure[_qp][_phase_num], Tk, _xnacl[_qp], h, dh_dp, dh_dT, dh_dx);
     193          28 :     (*_enthalpy)[_qp] = h;
     194          28 :     (*_denthalpy_dp)[_qp] = dh_dp;
     195          28 :     (*_denthalpy_dT)[_qp] = dh_dT;
     196             :   }
     197        2521 : }

Generated by: LCOV version 1.11