LCOV - code coverage report
Current view: top level - src/fvbcs - WCNSFVEnergyFluxBC.C (source / functions) Hit Total Coverage
Test: idaholab/moose navier_stokes: #32971 (54bef8) with base c6cf66 Lines: 58 66 87.9 %
Date: 2026-05-29 20:37:52 Functions: 5 5 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 "WCNSFVEnergyFluxBC.h"
      11             : #include "INSFVEnergyVariable.h"
      12             : #include "SinglePhaseFluidProperties.h"
      13             : #include "NS.h"
      14             : 
      15             : registerMooseObject("NavierStokesApp", WCNSFVEnergyFluxBC);
      16             : 
      17             : InputParameters
      18         289 : WCNSFVEnergyFluxBC::validParams()
      19             : {
      20         289 :   InputParameters params = WCNSFVFluxBCBase::validParams();
      21         289 :   params.addClassDescription("Flux boundary conditions for energy advection.");
      22             : 
      23             :   // Three different ways to input an advected energy flux
      24             :   // 1) Postprocessor with the energy flow rate directly
      25             :   // 2) Postprocessors for velocity and energy, functors for specific heat and density
      26             :   // 3) Postprocessors for mass flow rate and energy, functor for specific heat
      27         578 :   params.addParam<PostprocessorName>("energy_pp", "Postprocessor with the inlet energy flow rate");
      28         578 :   params.addParam<PostprocessorName>("temperature_pp", "Postprocessor with the inlet temperature");
      29         289 :   params.addParam<MooseFunctorName>(NS::cp, "specific heat capacity functor");
      30         289 :   params.addRequiredParam<MooseFunctorName>(NS::T_fluid, "temperature functor");
      31             : 
      32             :   // Parameters to solve with the specific enthalpy variable
      33         289 :   params.addParam<MooseFunctorName>(NS::pressure, "pressure functor");
      34         289 :   params.addParam<MooseFunctorName>(NS::specific_enthalpy,
      35             :                                     "Fluid specific enthalpy functor. This can be specified to "
      36             :                                     "avoid using cp * T as the enthalpy");
      37         289 :   params.addParam<UserObjectName>(NS::fluid, "Fluid properties object");
      38         289 :   return params;
      39           0 : }
      40             : 
      41         157 : WCNSFVEnergyFluxBC::WCNSFVEnergyFluxBC(const InputParameters & params)
      42             :   : WCNSFVFluxBCBase(params),
      43         295 :     _temperature_pp(isParamValid("temperature_pp") ? &getPostprocessorValue("temperature_pp")
      44             :                                                    : nullptr),
      45         323 :     _energy_pp(isParamValid("energy_pp") ? &getPostprocessorValue("energy_pp") : nullptr),
      46         155 :     _cp(isParamValid(NS::cp) ? &getFunctor<ADReal>(NS::cp) : nullptr),
      47         155 :     _temperature(getFunctor<ADReal>(NS::T_fluid)),
      48         175 :     _pressure(isParamValid(NS::pressure) ? &getFunctor<ADReal>(NS::pressure) : nullptr),
      49         175 :     _h_fluid(isParamValid(NS::specific_enthalpy) ? &getFunctor<ADReal>(NS::specific_enthalpy)
      50             :                                                  : nullptr),
      51         155 :     _fluid(isParamValid(NS::fluid)
      52         155 :                ? &UserObjectInterface::getUserObject<SinglePhaseFluidProperties>(NS::fluid)
      53         157 :                : nullptr)
      54             : {
      55         155 :   if (!dynamic_cast<INSFVEnergyVariable *>(&_var))
      56           0 :     paramError("variable",
      57             :                "The variable argument to WCNSFVEnergyFluxBC must be of type INSFVEnergyVariable");
      58             : 
      59             :   // Density is often set as global parameters so it is not checked
      60         155 :   if (_energy_pp && (_velocity_pp || _direction_specified_by_user || _mdot_pp || _temperature_pp))
      61           2 :     mooseWarning("If setting the energy flow rate directly, "
      62             :                  "no need for inlet velocity (magnitude or direction), mass flow or temperature");
      63             : 
      64             :   // Need enough information if trying to use a mass flow rate postprocessor
      65         153 :   if (!_energy_pp)
      66             :   {
      67         142 :     if (!_temperature_pp)
      68           2 :       mooseError("If not providing the energy flow rate, "
      69             :                  "the inlet temperature should be provided");
      70         140 :     if (!_velocity_pp && !_mdot_pp)
      71           2 :       mooseError("If not providing the inlet energy flow rate, the inlet velocity or mass flow "
      72             :                  "should be provided");
      73         138 :     if (_mdot_pp && !_area_pp)
      74           0 :       mooseError("If providing the inlet mass flow rate, the flow"
      75             :                  " area should be provided as well");
      76             :   }
      77          11 :   else if (!_area_pp)
      78           0 :     paramError("energy_pp",
      79             :                "If supplying the energy flow rate, the flow area should be provided as well");
      80         149 : }
      81             : 
      82             : ADReal
      83        7956 : WCNSFVEnergyFluxBC::computeQpResidual()
      84             : {
      85        7956 :   const auto state = determineState();
      86             : 
      87             :   // Currently an outlet
      88        7956 :   if (!isInflow())
      89             :   {
      90         483 :     const auto fa = singleSidedFaceArg();
      91         966 :     return varVelocity(state) * _normal * _rho(fa, state) * enthalpy(fa, state, false);
      92             :   }
      93             :   // Currently an inlet with a set enthalpy
      94        7473 :   else if (_energy_pp)
      95         900 :     return -_scaling_factor * *_energy_pp / *_area_pp;
      96             :   // Currently an inlet, compute the enthalpy
      97       13143 :   return -_scaling_factor * inflowMassFlux(state) * enthalpy(singleSidedFaceArg(), state, true);
      98             : }
      99             : 
     100             : bool
     101        7956 : WCNSFVEnergyFluxBC::isInflow() const
     102             : {
     103        7956 :   if (_mdot_pp)
     104        4166 :     return *_mdot_pp >= 0;
     105        3790 :   else if (_velocity_pp)
     106        2890 :     return *_velocity_pp >= 0;
     107         900 :   else if (_energy_pp)
     108         900 :     return *_energy_pp >= 0;
     109             : 
     110           0 :   mooseError(
     111             :       "Either mdot_pp or velocity_pp or energy_pp need to be provided OR this function must be "
     112             :       "overridden in derived classes if other input parameter combinations are valid. "
     113             :       "Neither mdot_pp nor velocity_pp are provided.");
     114             :   return true;
     115             : }
     116             : 
     117             : template <typename T>
     118             : ADReal
     119        7056 : WCNSFVEnergyFluxBC::enthalpy(const T & loc_arg,
     120             :                              const Moose::StateArg & state,
     121             :                              const bool inflow) const
     122             : {
     123             :   // Outlet, use interior values
     124        7056 :   if (!inflow)
     125             :   {
     126         483 :     if (_h_fluid)
     127           0 :       return (*_h_fluid)(loc_arg, state);
     128         483 :     else if (_fluid)
     129           0 :       return _fluid->h_from_p_T((*_pressure)(loc_arg, state), _temperature(loc_arg, state));
     130         483 :     else if (_temperature_pp)
     131         966 :       return (*_cp)(loc_arg, state) * _temperature(loc_arg, state);
     132             :   }
     133             :   else
     134             :   {
     135        6573 :     if (_temperature_pp)
     136             :     {
     137             :       // Preferable to use the fluid property if we know it
     138        6573 :       if (_fluid)
     139         684 :         return _fluid->h_from_p_T((*_pressure)(loc_arg, state), (*_temperature_pp));
     140        5889 :       else if (_cp)
     141       11778 :         return (*_cp)(loc_arg, state) * (*_temperature_pp);
     142             :     }
     143             :   }
     144           0 :   mooseError("Should not reach here, constructor checks required functor inputs to flux BC");
     145             : }

Generated by: LCOV version 1.14