LCOV - code coverage report
Current view: top level - src/materials - PorousFlowBrine.C (source / functions) Hit Total Coverage
Test: idaholab/moose porous_flow: #32971 (54bef8) with base c6cf66 Lines: 89 91 97.8 %
Date: 2026-05-29 20:38:56 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.14