LCOV - code coverage report
Current view: top level - src/materials - GeneralFluidProps.C (source / functions) Hit Total Coverage
Test: idaholab/moose navier_stokes: 9fc4b0 Lines: 77 78 98.7 %
Date: 2025-08-14 10:14:56 Functions: 3 3 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 "GeneralFluidProps.h"
      11             : #include "NS.h" // Variable Term Names
      12             : #include "HeatTransferUtils.h"
      13             : #include "NavierStokesMethods.h"
      14             : #include "SinglePhaseFluidProperties.h"
      15             : 
      16             : registerMooseObject("NavierStokesApp", GeneralFluidProps);
      17             : 
      18             : InputParameters
      19          85 : GeneralFluidProps::validParams()
      20             : {
      21          85 :   auto params = Material::validParams();
      22          85 :   params.addRequiredParam<UserObjectName>(NS::fluid, "Fluid properties userobject");
      23          85 :   params.addClassDescription("Computes fluid properties using a (P, T) formulation");
      24             : 
      25          85 :   params.addRequiredCoupledVar(NS::porosity, "porosity");
      26         170 :   params.addRequiredRangeCheckedParam<Real>(
      27             :       "characteristic_length",
      28             :       "characteristic_length > 0.0 ",
      29             :       "characteristic length for Reynolds number calculation");
      30          85 :   return params;
      31           0 : }
      32             : 
      33          66 : GeneralFluidProps::GeneralFluidProps(const InputParameters & parameters)
      34             :   : DerivativeMaterialInterface<Material>(parameters),
      35         132 :     _fluid(UserObjectInterface::getUserObject<SinglePhaseFluidProperties>(NS::fluid)),
      36          66 :     _eps(coupledValue(NS::porosity)),
      37         132 :     _d(getParam<Real>("characteristic_length")),
      38             : 
      39          66 :     _pressure(getADMaterialProperty<Real>(NS::pressure)),
      40          66 :     _T_fluid(getADMaterialProperty<Real>(NS::T_fluid)),
      41          66 :     _rho(getADMaterialProperty<Real>(NS::density)),
      42          66 :     _speed(getADMaterialProperty<Real>(NS::speed)),
      43             : 
      44          66 :     _drho_dp(declarePropertyDerivative<Real>(NS::density, NS::pressure)),
      45          66 :     _drho_dT(declarePropertyDerivative<Real>(NS::density, NS::T_fluid)),
      46             : 
      47          66 :     _cp(declareADProperty<Real>(NS::cp)),
      48          66 :     _dcp_dp(declarePropertyDerivative<Real>(NS::cp, NS::pressure)),
      49          66 :     _dcp_dT(declarePropertyDerivative<Real>(NS::cp, NS::T_fluid)),
      50             : 
      51          66 :     _cv(declareADProperty<Real>(NS::cv)),
      52             : 
      53          66 :     _mu(declareADProperty<Real>(NS::mu)),
      54          66 :     _dmu_dp(declarePropertyDerivative<Real>(NS::mu, NS::pressure)),
      55          66 :     _dmu_dT(declarePropertyDerivative<Real>(NS::mu, NS::T_fluid)),
      56             : 
      57          66 :     _k(declareADProperty<Real>(NS::k)),
      58          66 :     _dk_dp(declarePropertyDerivative<Real>(NS::k, NS::pressure)),
      59          66 :     _dk_dT(declarePropertyDerivative<Real>(NS::k, NS::T_fluid)),
      60             : 
      61          66 :     _Pr(declareADProperty<Real>(NS::Prandtl)),
      62          66 :     _dPr_dp(declarePropertyDerivative<Real>(NS::Prandtl, NS::pressure)),
      63          66 :     _dPr_dT(declarePropertyDerivative<Real>(NS::Prandtl, NS::T_fluid)),
      64             : 
      65          66 :     _Re(declareADProperty<Real>(NS::Reynolds)),
      66          66 :     _dRe_dp(declarePropertyDerivative<Real>(NS::Reynolds, NS::pressure)),
      67          66 :     _dRe_dT(declarePropertyDerivative<Real>(NS::Reynolds, NS::T_fluid)),
      68             : 
      69          66 :     _Re_h(declareADProperty<Real>(NS::Reynolds_hydraulic)),
      70         132 :     _Re_i(declareADProperty<Real>(NS::Reynolds_interstitial))
      71             : {
      72          66 : }
      73             : 
      74             : void
      75      177894 : GeneralFluidProps::computeQpProperties()
      76             : {
      77      177894 :   auto raw_pressure = MetaPhysicL::raw_value(_pressure[_qp]);
      78      177894 :   auto raw_T_fluid = MetaPhysicL::raw_value(_T_fluid[_qp]);
      79             : 
      80             :   // Density is not a material property because we will calculate it using
      81             :   // FluidDensityAux as needed.
      82      177894 :   Real dummy = 0;
      83      177894 :   _fluid.rho_from_p_T(raw_pressure, raw_T_fluid, dummy, _drho_dp[_qp], _drho_dT[_qp]);
      84             : 
      85      177894 :   _cv[_qp] = _fluid.cv_from_p_T(_pressure[_qp], _T_fluid[_qp]);
      86      177894 :   _cp[_qp] = _fluid.cp_from_p_T(_pressure[_qp], _T_fluid[_qp]);
      87      177894 :   _mu[_qp] = _fluid.mu_from_p_T(_pressure[_qp], _T_fluid[_qp]);
      88      177894 :   _k[_qp] = _fluid.k_from_p_T(_pressure[_qp], _T_fluid[_qp]);
      89      177894 :   _fluid.cp_from_p_T(raw_pressure, raw_T_fluid, dummy, _dcp_dp[_qp], _dcp_dT[_qp]);
      90      177894 :   _fluid.mu_from_p_T(raw_pressure, raw_T_fluid, dummy, _dmu_dp[_qp], _dmu_dT[_qp]);
      91      177894 :   _fluid.k_from_p_T(raw_pressure, raw_T_fluid, dummy, _dk_dp[_qp], _dk_dT[_qp]);
      92             : 
      93             :   static constexpr Real small_number = 1e-8;
      94             : 
      95      177894 :   _Pr[_qp] = HeatTransferUtils::prandtl(_cp[_qp], _mu[_qp], std::max(_k[_qp], small_number));
      96      177894 :   _dPr_dp[_qp] = NS::prandtlPropertyDerivative(MetaPhysicL::raw_value(_mu[_qp]),
      97      177894 :                                                MetaPhysicL::raw_value(_cp[_qp]),
      98      355788 :                                                MetaPhysicL::raw_value(_k[_qp]),
      99      177894 :                                                _dmu_dp[_qp],
     100      177894 :                                                _dcp_dp[_qp],
     101      177894 :                                                _dk_dp[_qp]);
     102      177894 :   _dPr_dT[_qp] = NS::prandtlPropertyDerivative(MetaPhysicL::raw_value(_mu[_qp]),
     103      177894 :                                                MetaPhysicL::raw_value(_cp[_qp]),
     104      355788 :                                                MetaPhysicL::raw_value(_k[_qp]),
     105      177894 :                                                _dmu_dT[_qp],
     106      177894 :                                                _dcp_dT[_qp],
     107      177894 :                                                _dk_dT[_qp]);
     108             : 
     109             :   // (pore / particle) Reynolds number based on superficial velocity and
     110             :   // characteristic length. Only call Reynolds() one time to compute all three so that
     111             :   // we don't redundantly check that viscosity is not too close to zero.
     112      177894 :   _Re[_qp] = std::max(HeatTransferUtils::reynolds(
     113      355788 :                           _rho[_qp], _eps[_qp] * _speed[_qp], _d, std::max(_mu[_qp], small_number)),
     114      355788 :                       1.0);
     115      177894 :   _dRe_dp[_qp] = NS::reynoldsPropertyDerivative(MetaPhysicL::raw_value(_Re[_qp]),
     116      177894 :                                                 MetaPhysicL::raw_value(_rho[_qp]),
     117      355788 :                                                 MetaPhysicL::raw_value(_mu[_qp]),
     118      177894 :                                                 _drho_dp[_qp],
     119      177894 :                                                 _dmu_dp[_qp]);
     120      177894 :   _dRe_dT[_qp] = NS::reynoldsPropertyDerivative(MetaPhysicL::raw_value(_Re[_qp]),
     121      177894 :                                                 MetaPhysicL::raw_value(_rho[_qp]),
     122      355788 :                                                 MetaPhysicL::raw_value(_mu[_qp]),
     123      177894 :                                                 _drho_dT[_qp],
     124      177894 :                                                 _dmu_dT[_qp]);
     125             : 
     126             :   // (hydraulic) Reynolds number
     127      533682 :   _Re_h[_qp] = _Re[_qp] / std::max(1 - _eps[_qp], small_number);
     128             : 
     129             :   // (interstitial) Reynolds number
     130      177894 :   _Re_i[_qp] = _Re[_qp] / _eps[_qp];
     131      177894 : }

Generated by: LCOV version 1.14