LCOV - code coverage report
Current view: top level - src/fvbcs - WCNSFVEnergyFluxBC.C (source / functions) Hit Total Coverage
Test: idaholab/moose navier_stokes: 9fc4b0 Lines: 41 46 89.1 %
Date: 2025-08-14 10:14: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 "WCNSFVEnergyFluxBC.h"
      11             : #include "INSFVEnergyVariable.h"
      12             : #include "NS.h"
      13             : 
      14             : registerMooseObject("NavierStokesApp", WCNSFVEnergyFluxBC);
      15             : 
      16             : InputParameters
      17         323 : WCNSFVEnergyFluxBC::validParams()
      18             : {
      19         323 :   InputParameters params = WCNSFVFluxBCBase::validParams();
      20         323 :   params.addClassDescription("Flux boundary conditions for energy advection.");
      21             : 
      22             :   // Three different ways to input an advected energy flux
      23             :   // 1) Postprocessor with the energy flow rate directly
      24             :   // 2) Postprocessors for velocity and energy, functors for specific heat and density
      25             :   // 3) Postprocessors for mass flow rate and energy, functor for specific heat
      26         646 :   params.addParam<PostprocessorName>("energy_pp", "Postprocessor with the inlet energy flow rate");
      27         646 :   params.addParam<PostprocessorName>("temperature_pp", "Postprocessor with the inlet temperature");
      28         323 :   params.addRequiredParam<MooseFunctorName>(NS::cp, "specific heat capacity functor");
      29         323 :   params.addRequiredParam<MooseFunctorName>(NS::T_fluid, "temperature functor");
      30         323 :   return params;
      31           0 : }
      32             : 
      33         185 : WCNSFVEnergyFluxBC::WCNSFVEnergyFluxBC(const InputParameters & params)
      34             :   : WCNSFVFluxBCBase(params),
      35         347 :     _temperature_pp(isParamValid("temperature_pp") ? &getPostprocessorValue("temperature_pp")
      36             :                                                    : nullptr),
      37         383 :     _energy_pp(isParamValid("energy_pp") ? &getPostprocessorValue("energy_pp") : nullptr),
      38         183 :     _cp(getFunctor<ADReal>(NS::cp)),
      39         185 :     _temperature(getFunctor<ADReal>(NS::T_fluid))
      40             : {
      41         183 :   if (!dynamic_cast<INSFVEnergyVariable *>(&_var))
      42           0 :     paramError("variable",
      43             :                "The variable argument to WCNSFVEnergyFluxBC must be of type INSFVEnergyVariable");
      44             : 
      45             :   // Density is often set as global parameters so it is not checked
      46         183 :   if (_energy_pp && (_velocity_pp || _direction_specified_by_user || _mdot_pp || _temperature_pp))
      47           2 :     mooseWarning("If setting the energy flow rate directly, "
      48             :                  "no need for inlet velocity (magnitude or direction), mass flow or temperature");
      49             : 
      50             :   // Need enough information if trying to use a mass flow rate postprocessor
      51         181 :   if (!_energy_pp)
      52             :   {
      53         166 :     if (!_temperature_pp)
      54           2 :       mooseError("If not providing the energy flow rate, "
      55             :                  "the inlet temperature should be provided");
      56         164 :     if (!_velocity_pp && !_mdot_pp)
      57           2 :       mooseError("If not providing the inlet energy flow rate, the inlet velocity or mass flow "
      58             :                  "should be provided");
      59         162 :     if (_mdot_pp && !_area_pp)
      60           0 :       mooseError("If providing the inlet mass flow rate, the flow"
      61             :                  " area should be provided as well");
      62             :   }
      63          15 :   else if (!_area_pp)
      64           0 :     paramError("energy_pp",
      65             :                "If supplying the energy flow rate, the flow area should be provided as well");
      66         177 : }
      67             : 
      68             : ADReal
      69        8694 : WCNSFVEnergyFluxBC::computeQpResidual()
      70             : {
      71        8694 :   const auto state = determineState();
      72             : 
      73        8694 :   if (!isInflow())
      74             :   {
      75         579 :     const auto fa = singleSidedFaceArg();
      76         579 :     return varVelocity(state) * _normal * _rho(fa, state) * _cp(fa, state) *
      77        1158 :            _temperature(fa, state);
      78             :   }
      79        8115 :   else if (_energy_pp)
      80        1075 :     return -_scaling_factor * *_energy_pp / *_area_pp;
      81             : 
      82       14077 :   return -_scaling_factor * inflowMassFlux(state) * _cp(singleSidedFaceArg(), state) *
      83        7040 :          (*_temperature_pp);
      84             : }
      85             : 
      86             : bool
      87        8694 : WCNSFVEnergyFluxBC::isInflow() const
      88             : {
      89        8694 :   if (_mdot_pp)
      90        4983 :     return *_mdot_pp >= 0;
      91        3711 :   else if (_velocity_pp)
      92        2636 :     return *_velocity_pp >= 0;
      93        1075 :   else if (_energy_pp)
      94        1075 :     return *_energy_pp >= 0;
      95             : 
      96           0 :   mooseError(
      97             :       "Either mdot_pp or velocity_pp or energy_pp need to be provided OR this function must be "
      98             :       "overridden in derived classes if other input parameter combinations are valid. "
      99             :       "Neither mdot_pp nor velocity_pp are provided.");
     100             :   return true;
     101             : }

Generated by: LCOV version 1.14