LCOV - code coverage report
Current view: top level - src/fvbcs - WCNSFVInletTemperatureBC.C (source / functions) Hit Total Coverage
Test: idaholab/moose navier_stokes: 9fc4b0 Lines: 38 49 77.6 %
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 "WCNSFVInletTemperatureBC.h"
      11             : #include "INSFVEnergyVariable.h"
      12             : #include "NS.h"
      13             : 
      14             : registerMooseObject("NavierStokesApp", WCNSFVInletTemperatureBC);
      15             : 
      16             : InputParameters
      17         100 : WCNSFVInletTemperatureBC::validParams()
      18             : {
      19         100 :   InputParameters params = FVDirichletBCBase::validParams();
      20         100 :   params += INSFVFlowBC::validParams();
      21             : 
      22         200 :   params.addParam<Real>("scaling_factor", 1, "To scale the velocity");
      23             : 
      24             :   // Three different ways to input temperature
      25             :   // 1) Postprocessor with the temperature value directly
      26         200 :   params.addParam<PostprocessorName>("temperature_pp", "Postprocessor with the inlet temperature");
      27             : 
      28             :   // 2) Postprocessors for velocity and energy, functors for specific heat and density
      29         200 :   params.addParam<PostprocessorName>("energy_pp", "Postprocessor with the inlet energy flow rate");
      30         200 :   params.addParam<PostprocessorName>("velocity_pp", "Postprocessor with the inlet velocity norm");
      31         100 :   params.addParam<MooseFunctorName>(NS::density, "Density functor");
      32         100 :   params.addParam<MooseFunctorName>(NS::cp, "specific heat capacity functor");
      33             : 
      34             :   // 3) Postprocessors for mass flow rate and energy, functor for specific heat
      35         200 :   params.addParam<PostprocessorName>("mdot_pp", "Postprocessor with the inlet mass flow rate");
      36             : 
      37         100 :   return params;
      38           0 : }
      39             : 
      40          59 : WCNSFVInletTemperatureBC::WCNSFVInletTemperatureBC(const InputParameters & params)
      41             :   : FVDirichletBCBase(params),
      42             :     INSFVFlowBC(params),
      43          59 :     _scaling_factor(getParam<Real>("scaling_factor")),
      44         169 :     _temperature_pp(isParamValid("temperature_pp") ? &getPostprocessorValue("temperature_pp")
      45             :                                                    : nullptr),
      46         124 :     _energy_pp(isParamValid("energy_pp") ? &getPostprocessorValue("energy_pp") : nullptr),
      47         120 :     _velocity_pp(isParamValid("velocity_pp") ? &getPostprocessorValue("velocity_pp") : nullptr),
      48         122 :     _mdot_pp(isParamValid("mdot_pp") ? &getPostprocessorValue("mdot_pp") : nullptr),
      49         118 :     _area_pp(isParamValid("area_pp") ? &getPostprocessorValue("area_pp") : nullptr),
      50          59 :     _rho(isParamValid(NS::density) ? &getFunctor<ADReal>(NS::density) : nullptr),
      51         118 :     _cp(isParamValid(NS::cp) ? &getFunctor<ADReal>(NS::cp) : nullptr)
      52             : {
      53          59 :   if (!dynamic_cast<INSFVEnergyVariable *>(&_var))
      54           0 :     paramError(
      55             :         "variable",
      56             :         "The variable argument to WCNSFVInletTemperatureBC must be of type INSFVEnergyVariable");
      57             : 
      58             :   // Density is often set as global parameters so it is not checked
      59          59 :   if (_temperature_pp && (_velocity_pp || _mdot_pp || _energy_pp))
      60           2 :     mooseWarning(
      61             :         "If setting the temperature directly, no need for inlet velocity, mass flow or energy");
      62             : 
      63             :   // Need enough information if trying to use a mass flow rate postprocessor
      64          57 :   if (!_temperature_pp)
      65             :   {
      66           8 :     if (!_energy_pp)
      67           2 :       mooseError("If not providing the temperature, the energy flow rate should be provided");
      68           6 :     if (!_velocity_pp && !_mdot_pp)
      69           2 :       mooseError("If not providing the inlet temperature, the inlet velocity or mass flow should "
      70             :                  "be provided");
      71           4 :     if (_velocity_pp && (!_rho || !_cp || !_area_pp))
      72           2 :       mooseError("If providing the inlet velocity, the density, the area and the specific heat "
      73             :                  "capacity should be provided as well");
      74           2 :     if (_mdot_pp && !_cp)
      75           2 :       mooseError("If providing the inlet mass flow rate, the inlet specific heat capacity should "
      76             :                  "be provided as well");
      77             :   }
      78          98 :   else if (params.isParamSetByUser("scaling_factor"))
      79           0 :     paramError("scaling_factor",
      80             :                "The scaling factor is meant to adjust for a different area or "
      81             :                "mass flow rate, it should not be set if the temperature is set directly");
      82          49 : }
      83             : 
      84             : ADReal
      85      286722 : WCNSFVInletTemperatureBC::boundaryValue(const FaceInfo & fi, const Moose::StateArg & state) const
      86             : {
      87             : 
      88      286722 :   if (_area_pp)
      89           0 :     if (MooseUtils::absoluteFuzzyEqual(*_area_pp, 0))
      90           0 :       mooseError("Surface area is 0");
      91             : 
      92      286722 :   if (_temperature_pp)
      93      286722 :     return *_temperature_pp;
      94           0 :   else if (_velocity_pp)
      95             :   {
      96           0 :     ADReal rho = (*_rho)(singleSidedFaceArg(&fi), state);
      97           0 :     ADReal cp = (*_cp)(singleSidedFaceArg(&fi), state);
      98             : 
      99           0 :     return _scaling_factor * (*_energy_pp) / (*_area_pp * rho * *_velocity_pp * cp);
     100             :   }
     101             :   else
     102             :   {
     103           0 :     ADReal cp = (*_cp)(singleSidedFaceArg(&fi), state);
     104             : 
     105           0 :     return _scaling_factor * (*_energy_pp) / (*_mdot_pp * cp);
     106             :   }
     107             : }

Generated by: LCOV version 1.14