LCOV - code coverage report
Current view: top level - src/materials - HeatConductionMaterial.C (source / functions) Hit Total Coverage
Test: idaholab/moose heat_transfer: #31405 (292dce) with base fef103 Lines: 53 58 91.4 %
Date: 2025-09-04 07:53:51 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       10078 : HeatConductionMaterialTempl<is_ad>::validParams()
      21             : {
      22       10078 :   InputParameters params = Material::validParams();
      23             : 
      24       20156 :   params.addCoupledVar("temp", "Coupled Temperature");
      25             : 
      26       20156 :   params.addParam<Real>("thermal_conductivity", "The thermal conductivity value");
      27       20156 :   params.addParam<FunctionName>("thermal_conductivity_temperature_function",
      28             :                                 "",
      29             :                                 "Thermal conductivity as a function of temperature.");
      30       20156 :   params.addParam<Real>("min_T",
      31             :                         "Minimum allowable value for temperature for evaluating properties "
      32             :                         "when provided by functions");
      33             : 
      34       20156 :   params.addParam<Real>("specific_heat", "The specific heat value");
      35       20156 :   params.addParam<FunctionName>(
      36             :       "specific_heat_temperature_function", "", "Specific heat as a function of temperature.");
      37       10078 :   params.addClassDescription("General-purpose material model for heat conduction");
      38             : 
      39       10078 :   return params;
      40           0 : }
      41             : 
      42             : template <bool is_ad>
      43        7815 : HeatConductionMaterialTempl<is_ad>::HeatConductionMaterialTempl(const InputParameters & parameters)
      44             :   : Material(parameters),
      45        7815 :     _has_temp(isCoupled("temp")),
      46        7815 :     _temperature(_has_temp ? coupledGenericValue<is_ad>("temp") : genericZeroValue<is_ad>()),
      47        7815 :     _my_thermal_conductivity(
      48       31062 :         isParamValid("thermal_conductivity") ? getParam<Real>("thermal_conductivity") : 0),
      49       28554 :     _my_specific_heat(isParamValid("specific_heat") ? getParam<Real>("specific_heat") : 0),
      50             : 
      51       15630 :     _thermal_conductivity(declareGenericProperty<Real, is_ad>("thermal_conductivity")),
      52        7815 :     _thermal_conductivity_dT(declareProperty<Real>("thermal_conductivity_dT")),
      53        7815 :     _thermal_conductivity_temperature_function(
      54       15630 :         getParam<FunctionName>("thermal_conductivity_temperature_function") != ""
      55        7914 :             ? &getFunction("thermal_conductivity_temperature_function")
      56             :             : nullptr),
      57             : 
      58       15630 :     _specific_heat(declareGenericProperty<Real, is_ad>("specific_heat")),
      59        7815 :     _specific_heat_temperature_function(
      60       15630 :         getParam<FunctionName>("specific_heat_temperature_function") != ""
      61        7914 :             ? &getFunction("specific_heat_temperature_function")
      62             :             : nullptr),
      63       10449 :     _specific_heat_dT(is_ad && !_specific_heat_temperature_function
      64        2634 :                           ? nullptr
      65        7815 :                           : &declareGenericProperty<Real, is_ad>("specific_heat_dT")),
      66       23511 :     _min_T(isParamValid("min_T") ? &getParam<Real>("min_T") : nullptr)
      67             : {
      68        7815 :   if (_thermal_conductivity_temperature_function && !_has_temp)
      69           0 :     paramError("thermal_conductivity_temperature_function",
      70             :                "Must couple with temperature if using thermal conductivity function");
      71             : 
      72       23445 :   if (isParamValid("thermal_conductivity") && _thermal_conductivity_temperature_function)
      73           0 :     mooseError(
      74             :         "Cannot define both thermal conductivity and thermal conductivity temperature function");
      75             : 
      76        7815 :   if (_specific_heat_temperature_function && !_has_temp)
      77           0 :     paramError("specific_heat_temperature_function",
      78             :                "Must couple with temperature if using specific heat function");
      79             : 
      80       23445 :   if (isParamValid("specific_heat") && _specific_heat_temperature_function)
      81           0 :     mooseError("Cannot define both specific heat and specific heat temperature function");
      82        7815 : }
      83             : 
      84             : template <bool is_ad>
      85             : void
      86    74758117 : HeatConductionMaterialTempl<is_ad>::computeQpProperties()
      87             : {
      88    74758117 :   auto qp_temperature = _temperature[_qp];
      89             : 
      90    74758117 :   if (_has_temp && _min_T)
      91             :   {
      92       44000 :     if (_temperature[_qp] < *_min_T)
      93             :     {
      94       44016 :       flagSolutionWarning("Temperature below specified minimum (" + std::to_string(*_min_T) +
      95             :                           "). min_T will be used instead.");
      96       44000 :       qp_temperature = *_min_T;
      97             :     }
      98             :   }
      99             : 
     100    74758117 :   if (_thermal_conductivity_temperature_function)
     101             :   {
     102       88000 :     _thermal_conductivity[_qp] = _thermal_conductivity_temperature_function->value(qp_temperature);
     103       88000 :     _thermal_conductivity_dT[_qp] = _thermal_conductivity_temperature_function->timeDerivative(
     104       88000 :         MetaPhysicL::raw_value(qp_temperature));
     105             :   }
     106             :   else
     107             :   {
     108    74670117 :     _thermal_conductivity[_qp] = _my_thermal_conductivity;
     109    74670117 :     _thermal_conductivity_dT[_qp] = 0;
     110             :   }
     111             : 
     112    74758117 :   if (_specific_heat_temperature_function)
     113             :   {
     114       88000 :     _specific_heat[_qp] = _specific_heat_temperature_function->value(qp_temperature);
     115       88000 :     if (_specific_heat_dT)
     116       88000 :       (*_specific_heat_dT)[_qp] = _specific_heat_temperature_function->timeDerivative(
     117       88000 :           MetaPhysicL::raw_value(qp_temperature));
     118             :   }
     119             :   else
     120    74670117 :     _specific_heat[_qp] = _my_specific_heat;
     121    74758117 : }
     122             : 
     123             : template class HeatConductionMaterialTempl<false>;
     124             : template class HeatConductionMaterialTempl<true>;

Generated by: LCOV version 1.14