LCOV - code coverage report
Current view: top level - src/materials - HeatConductionMaterial.C (source / functions) Hit Total Coverage
Test: idaholab/moose heat_transfer: #32971 (54bef8) with base c6cf66 Lines: 54 59 91.5 %
Date: 2026-05-29 20:37:03 Functions: 6 6 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 "HeatConductionMaterial.h"
      11             : #include "Function.h"
      12             : 
      13             : #include "libmesh/quadrature.h"
      14             : 
      15             : registerMooseObject("HeatTransferApp", HeatConductionMaterial);
      16             : registerMooseObject("HeatTransferApp", ADHeatConductionMaterial);
      17             : 
      18             : template <bool is_ad>
      19             : InputParameters
      20        4762 : HeatConductionMaterialTempl<is_ad>::validParams()
      21             : {
      22        4762 :   InputParameters params = Material::validParams();
      23             : 
      24        9524 :   params.addCoupledVar("temp", "Coupled Temperature");
      25        9524 :   params.deprecateCoupledVar("temp", "temperature", "01/12/2027");
      26             : 
      27        9524 :   params.addParam<Real>("thermal_conductivity", "The thermal conductivity value");
      28        9524 :   params.addParam<FunctionName>("thermal_conductivity_temperature_function",
      29             :                                 "",
      30             :                                 "Thermal conductivity as a function of temperature.");
      31        9524 :   params.addParam<Real>("min_T",
      32             :                         "Minimum allowable value for temperature for evaluating properties "
      33             :                         "when provided by functions");
      34             : 
      35        9524 :   params.addParam<Real>("specific_heat", "The specific heat value");
      36        9524 :   params.addParam<FunctionName>(
      37             :       "specific_heat_temperature_function", "", "Specific heat as a function of temperature.");
      38        4762 :   params.addClassDescription("General-purpose material model for heat conduction");
      39             : 
      40        4762 :   return params;
      41           0 : }
      42             : 
      43             : template <bool is_ad>
      44        3657 : HeatConductionMaterialTempl<is_ad>::HeatConductionMaterialTempl(const InputParameters & parameters)
      45             :   : Material(parameters),
      46        3657 :     _has_temp(isCoupled("temp")),
      47        3657 :     _temperature(_has_temp ? coupledGenericValue<is_ad>("temp") : genericZeroValue<is_ad>()),
      48        3657 :     _my_thermal_conductivity(
      49       14526 :         isParamValid("thermal_conductivity") ? getParam<Real>("thermal_conductivity") : 0),
      50       13386 :     _my_specific_heat(isParamValid("specific_heat") ? getParam<Real>("specific_heat") : 0),
      51             : 
      52        7314 :     _thermal_conductivity(declareGenericProperty<Real, is_ad>("thermal_conductivity")),
      53        3657 :     _thermal_conductivity_dT(declareProperty<Real>("thermal_conductivity_dT")),
      54        3657 :     _thermal_conductivity_temperature_function(
      55        7314 :         getParam<FunctionName>("thermal_conductivity_temperature_function") != ""
      56        3708 :             ? &getFunction("thermal_conductivity_temperature_function")
      57             :             : nullptr),
      58             : 
      59        7314 :     _specific_heat(declareGenericProperty<Real, is_ad>("specific_heat")),
      60        3657 :     _specific_heat_temperature_function(
      61        7314 :         getParam<FunctionName>("specific_heat_temperature_function") != ""
      62        3708 :             ? &getFunction("specific_heat_temperature_function")
      63             :             : nullptr),
      64        4851 :     _specific_heat_dT(is_ad && !_specific_heat_temperature_function
      65        1194 :                           ? nullptr
      66        3657 :                           : &declareGenericProperty<Real, is_ad>("specific_heat_dT")),
      67       11013 :     _min_T(isParamValid("min_T") ? &getParam<Real>("min_T") : nullptr)
      68             : {
      69        3657 :   if (_thermal_conductivity_temperature_function && !_has_temp)
      70           0 :     paramError("thermal_conductivity_temperature_function",
      71             :                "Must couple with temperature if using thermal conductivity function");
      72             : 
      73       10971 :   if (isParamValid("thermal_conductivity") && _thermal_conductivity_temperature_function)
      74           0 :     mooseError(
      75             :         "Cannot define both thermal conductivity and thermal conductivity temperature function");
      76             : 
      77        3657 :   if (_specific_heat_temperature_function && !_has_temp)
      78           0 :     paramError("specific_heat_temperature_function",
      79             :                "Must couple with temperature if using specific heat function");
      80             : 
      81       10971 :   if (isParamValid("specific_heat") && _specific_heat_temperature_function)
      82           0 :     mooseError("Cannot define both specific heat and specific heat temperature function");
      83        3657 : }
      84             : 
      85             : template <bool is_ad>
      86             : void
      87    51867139 : HeatConductionMaterialTempl<is_ad>::computeQpProperties()
      88             : {
      89    51867139 :   auto qp_temperature = _temperature[_qp];
      90             : 
      91    51867139 :   if (_has_temp && _min_T)
      92             :   {
      93       35200 :     if (_temperature[_qp] < *_min_T)
      94             :     {
      95       35212 :       flagSolutionWarning("Temperature below specified minimum (" + std::to_string(*_min_T) +
      96             :                           "). min_T will be used instead.");
      97       35200 :       qp_temperature = *_min_T;
      98             :     }
      99             :   }
     100             : 
     101    51867139 :   if (_thermal_conductivity_temperature_function)
     102             :   {
     103       66000 :     _thermal_conductivity[_qp] = _thermal_conductivity_temperature_function->value(qp_temperature);
     104       66000 :     _thermal_conductivity_dT[_qp] = _thermal_conductivity_temperature_function->timeDerivative(
     105       66000 :         MetaPhysicL::raw_value(qp_temperature));
     106             :   }
     107             :   else
     108             :   {
     109    51801139 :     _thermal_conductivity[_qp] = _my_thermal_conductivity;
     110    51801139 :     _thermal_conductivity_dT[_qp] = 0;
     111             :   }
     112             : 
     113    51867139 :   if (_specific_heat_temperature_function)
     114             :   {
     115       66000 :     _specific_heat[_qp] = _specific_heat_temperature_function->value(qp_temperature);
     116       66000 :     if (_specific_heat_dT)
     117       66000 :       (*_specific_heat_dT)[_qp] = _specific_heat_temperature_function->timeDerivative(
     118       66000 :           MetaPhysicL::raw_value(qp_temperature));
     119             :   }
     120             :   else
     121    51801139 :     _specific_heat[_qp] = _my_specific_heat;
     122    51867139 : }
     123             : 
     124             : template class HeatConductionMaterialTempl<false>;
     125             : template class HeatConductionMaterialTempl<true>;

Generated by: LCOV version 1.14