LCOV - code coverage report
Current view: top level - src/fvkernels - PINSFVEnergyTimeDerivative.C (source / functions) Hit Total Coverage
Test: idaholab/moose navier_stokes: #32971 (54bef8) with base c6cf66 Lines: 40 46 87.0 %
Date: 2026-05-29 20:37:52 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 "PINSFVEnergyTimeDerivative.h"
      11             : #include "INSFVEnergyVariable.h"
      12             : 
      13             : #include "NS.h"
      14             : 
      15             : registerMooseObject("NavierStokesApp", PINSFVEnergyTimeDerivative);
      16             : 
      17             : InputParameters
      18         275 : PINSFVEnergyTimeDerivative::validParams()
      19             : {
      20         275 :   InputParameters params = FVFunctorTimeKernel::validParams();
      21         275 :   params.addClassDescription(
      22             :       "Adds the time derivative term to the Navier-Stokes energy equation: "
      23             :       "for fluids: d(eps * rho * cp * T)/dt, for solids: (1 - eps) * d(rho * cp * T)/dt"
      24             :       "Material property derivatives are ignored if not provided.");
      25         275 :   params.addRequiredParam<MooseFunctorName>(NS::density, "Density");
      26         550 :   params.addParam<MooseFunctorName>(NS::time_deriv(NS::density), "Density time derivative functor");
      27         275 :   params.addParam<MooseFunctorName>(NS::cp, "Specific heat capacity");
      28         275 :   params.addParam<MooseFunctorName>(NS::specific_enthalpy, "Specific enthalpy");
      29         550 :   params.addParam<MooseFunctorName>(NS::time_deriv(NS::specific_enthalpy),
      30             :                                     "Time derivative of the specific enthalpy");
      31         275 :   params.addRequiredParam<MooseFunctorName>(NS::porosity, "Porosity");
      32             : 
      33         550 :   params.addRequiredParam<bool>("is_solid", "Whether this kernel acts on the solid temperature");
      34         550 :   params.addRangeCheckedParam<Real>("scaling",
      35             :                                     1,
      36             :                                     "scaling >= 0.0",
      37             :                                     "scaling factor to reduce the thermal mass during pseudo "
      38             :                                     "transients; this can accelerate convergence to steady state");
      39         275 :   return params;
      40           0 : }
      41             : 
      42         146 : PINSFVEnergyTimeDerivative::PINSFVEnergyTimeDerivative(const InputParameters & params)
      43             :   : FVFunctorTimeKernel(params),
      44         292 :     _rho(getFunctor<ADReal>(NS::density)),
      45         292 :     _rho_dot(isParamValid(NS::time_deriv(NS::density))
      46         300 :                  ? &getFunctor<ADReal>(NS::time_deriv(NS::density))
      47             :                  : nullptr),
      48         222 :     _cp(isParamValid(NS::cp) ? &getFunctor<ADReal>(NS::cp) : nullptr),
      49         146 :     _h(isParamValid(NS::specific_enthalpy) ? &getFunctor<ADReal>(NS::specific_enthalpy) : nullptr),
      50         292 :     _h_dot(isParamValid(NS::time_deriv(NS::specific_enthalpy))
      51         286 :                ? &getFunctor<ADReal>(NS::time_deriv(NS::specific_enthalpy))
      52             :                : nullptr),
      53         146 :     _eps(getFunctor<ADReal>(NS::porosity)),
      54         292 :     _is_solid(getParam<bool>("is_solid")),
      55         292 :     _scaling(getParam<Real>("scaling")),
      56         146 :     _zero_scaling(_scaling < 1e-8)
      57             : {
      58         146 :   if (_h_dot && _cp)
      59           0 :     paramError(NS::time_deriv(NS::specific_enthalpy),
      60             :                "If specifying the specific enthalpy time derivative, no need to specify the "
      61             :                "specific heat");
      62         146 :   if (!_h_dot && !_cp)
      63           0 :     paramError(
      64           0 :         NS::time_deriv(NS::specific_enthalpy),
      65             :         "One of either the specific heat or the time derivative of the enthalpy must be specified");
      66         146 :   if (_rho_dot && (!_cp && !_h))
      67           0 :     paramError(NS::time_deriv(NS::density),
      68             :                "If specifying the time derivative of the density, either the specific heat or the "
      69             :                "specific enthalpy must be specified");
      70         146 : }
      71             : 
      72             : ADReal
      73      996524 : PINSFVEnergyTimeDerivative::computeQpResidual()
      74             : {
      75      996524 :   if (_zero_scaling)
      76           0 :     return 0.0;
      77             :   else
      78             :   {
      79      996524 :     auto elem_arg = makeElemArg(_current_elem);
      80      996524 :     const auto state = determineState();
      81             :     ADReal time_derivative;
      82      996524 :     if (_h_dot)
      83             :     {
      84      604176 :       time_derivative = _rho(elem_arg, state) * (*_h_dot)(elem_arg, state);
      85      302088 :       if (_rho_dot)
      86      580176 :         time_derivative += (*_rho_dot)(elem_arg, state) * (*_h)(elem_arg, state);
      87             :     }
      88             :     else
      89             :     {
      90     1388872 :       time_derivative = _rho(elem_arg, state) * (*_cp)(elem_arg, state) * _var.dot(elem_arg, state);
      91      694436 :       if (_rho_dot)
      92             :         time_derivative +=
      93       26336 :             (*_rho_dot)(elem_arg, state) * (*_cp)(elem_arg, state) * _var(elem_arg, state);
      94             :     }
      95             : 
      96     2959584 :     return _scaling * (_is_solid ? 1 - _eps(elem_arg, state) : _eps(elem_arg, state)) *
      97             :            time_derivative;
      98             :   }
      99             : }

Generated by: LCOV version 1.14