LCOV - code coverage report
Current view: top level - src/fvkernels - PINSFVEnergyDiffusion.C (source / functions) Hit Total Coverage
Test: idaholab/moose navier_stokes: #31706 (f8ed4a) with base bb0a08 Lines: 40 47 85.1 %
Date: 2025-11-03 17:26:04 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 "PINSFVEnergyDiffusion.h"
      11             : #include "INSFVEnergyVariable.h"
      12             : #include "NS.h"
      13             : 
      14             : registerMooseObject("NavierStokesApp", PINSFVEnergyDiffusion);
      15             : 
      16             : InputParameters
      17         979 : PINSFVEnergyDiffusion::validParams()
      18             : {
      19         979 :   auto params = FVFluxKernel::validParams();
      20         979 :   params += FVDiffusionInterpolationInterface::validParams();
      21         979 :   params.addClassDescription("Diffusion term in the porous media incompressible Navier-Stokes "
      22             :                              "fluid energy equations :  $-div(eps * k * grad(T))$");
      23         979 :   params.addRequiredParam<MooseFunctorName>(NS::porosity, "Porosity");
      24         979 :   params.addRequiredParam<MooseFunctorName>(NS::k, "Thermal conductivity");
      25        1958 :   params.addParam<bool>(
      26             :       "effective_diffusivity",
      27        1958 :       false,
      28             :       "Whether the conductivity should be multiplied by porosity, or whether the provided "
      29             :       "conductivity is an effective conductivity taking porosity effects into account");
      30        1958 :   params.renameParam("effective_diffusivity", "effective_conductivity", "");
      31        1958 :   MooseEnum coeff_interp_method("average harmonic", "harmonic");
      32        1958 :   params.addParam<MooseEnum>(
      33             :       "kappa_interp_method",
      34             :       coeff_interp_method,
      35             :       "Switch that can select face interpolation method for the thermal conductivity.");
      36             : 
      37             :   // We add the relationship manager here, this will select the right number of
      38             :   // ghosting layers depending on the chosen interpolation method
      39        1958 :   params.addRelationshipManager(
      40             :       "ElementSideNeighborLayers",
      41             :       Moose::RelationshipManagerType::GEOMETRIC | Moose::RelationshipManagerType::ALGEBRAIC |
      42             :           Moose::RelationshipManagerType::COUPLING,
      43             :       [](const InputParameters & obj_params, InputParameters & rm_params)
      44         552 :       { FVRelationshipManagerInterface::setRMParamsDiffusion(obj_params, rm_params, 3); });
      45             : 
      46         979 :   params.set<unsigned short>("ghost_layers") = 2;
      47         979 :   return params;
      48         979 : }
      49             : 
      50         531 : PINSFVEnergyDiffusion::PINSFVEnergyDiffusion(const InputParameters & params)
      51             :   : FVFluxKernel(params),
      52             :     FVDiffusionInterpolationInterface(params),
      53         531 :     _k(getFunctor<ADReal>(NS::k)),
      54         531 :     _eps(getFunctor<ADReal>(NS::porosity)),
      55        1062 :     _porosity_factored_in(getParam<bool>("effective_conductivity")),
      56         531 :     _k_interp_method(
      57        1593 :         Moose::FV::selectInterpolationMethod(getParam<MooseEnum>("kappa_interp_method")))
      58             : {
      59         531 :   if (!dynamic_cast<INSFVEnergyVariable *>(&_var))
      60           0 :     mooseError("PINSFVEnergyDiffusion may only be used with a fluid temperature variable, "
      61             :                "of variable type INSFVEnergyVariable.");
      62         531 : }
      63             : 
      64             : ADReal
      65     4712654 : PINSFVEnergyDiffusion::computeQpResidual()
      66             : {
      67             :   // Interpolate thermal conductivity times porosity on the face
      68             :   ADReal k_eps_face;
      69     4712654 :   const auto state = determineState();
      70             : 
      71     4712654 :   if (onBoundary(*_face_info))
      72             :   {
      73       20927 :     const auto ssf = singleSidedFaceArg();
      74       71063 :     k_eps_face = _porosity_factored_in ? _k(ssf, state) : _k(ssf, state) * _eps(ssf, state);
      75             :   }
      76             :   else
      77             :   {
      78     4691727 :     const auto face_elem = elemArg();
      79     4691727 :     const auto face_neighbor = neighborArg();
      80             : 
      81     4691727 :     auto value1 = _porosity_factored_in ? _k(face_elem, state)
      82     9230656 :                                         : _k(face_elem, state) * _eps(face_elem, state);
      83     4691727 :     auto value2 = _porosity_factored_in ? _k(face_neighbor, state)
      84     9230656 :                                         : _k(face_neighbor, state) * _eps(face_neighbor, state);
      85             : 
      86             :     // Adapt to users either passing 0 thermal conductivity, 0 porosity, or k correlations going
      87             :     // negative. The solution is invalid only for the latter case.
      88     4691727 :     auto k_interp_method = _k_interp_method;
      89     4691727 :     if (value1 <= 0 || value2 <= 0)
      90             :     {
      91           0 :       flagInvalidSolution(
      92             :           "Negative or null thermal conductivity value. If this is on purpose use arithmetic mean "
      93             :           "interpolation instead of the default harmonic interpolation.");
      94           0 :       if (_k_interp_method == Moose::FV::InterpMethod::HarmonicAverage)
      95             :         k_interp_method = Moose::FV::InterpMethod::Average;
      96           0 :       if (value1 < 0)
      97           0 :         value1 = 0;
      98           0 :       if (value2 < 0)
      99           0 :         value2 = 0;
     100             :     }
     101             : 
     102     4691727 :     Moose::FV::interpolate(k_interp_method, k_eps_face, value1, value2, *_face_info, true);
     103             :   }
     104             : 
     105             :   // Compute the temperature gradient dotted with the surface normal
     106     4712654 :   auto dTdn = gradUDotNormal(state, _correct_skewness);
     107             : 
     108     9425308 :   return -k_eps_face * dTdn;
     109             : }

Generated by: LCOV version 1.14