https://mooseframework.inl.gov
HeatConductionMaterial.C
Go to the documentation of this file.
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 
17 
18 template <bool is_ad>
21 {
23 
24  params.addCoupledVar("temp", "Coupled Temperature");
25  params.deprecateCoupledVar("temp", "temperature", "01/12/2027");
26 
27  params.addParam<Real>("thermal_conductivity", "The thermal conductivity value");
28  params.addParam<FunctionName>("thermal_conductivity_temperature_function",
29  "",
30  "Thermal conductivity as a function of temperature.");
31  params.addParam<Real>("min_T",
32  "Minimum allowable value for temperature for evaluating properties "
33  "when provided by functions");
34 
35  params.addParam<Real>("specific_heat", "The specific heat value");
36  params.addParam<FunctionName>(
37  "specific_heat_temperature_function", "", "Specific heat as a function of temperature.");
38  params.addClassDescription("General-purpose material model for heat conduction");
39 
40  return params;
41 }
42 
43 template <bool is_ad>
45  : Material(parameters),
46  _has_temp(isCoupled("temp")),
47  _temperature(_has_temp ? coupledGenericValue<is_ad>("temp") : genericZeroValue<is_ad>()),
48  _my_thermal_conductivity(
49  isParamValid("thermal_conductivity") ? getParam<Real>("thermal_conductivity") : 0),
50  _my_specific_heat(isParamValid("specific_heat") ? getParam<Real>("specific_heat") : 0),
51 
52  _thermal_conductivity(declareGenericProperty<Real, is_ad>("thermal_conductivity")),
53  _thermal_conductivity_dT(declareProperty<Real>("thermal_conductivity_dT")),
54  _thermal_conductivity_temperature_function(
55  getParam<FunctionName>("thermal_conductivity_temperature_function") != ""
56  ? &getFunction("thermal_conductivity_temperature_function")
57  : nullptr),
58 
59  _specific_heat(declareGenericProperty<Real, is_ad>("specific_heat")),
60  _specific_heat_temperature_function(
61  getParam<FunctionName>("specific_heat_temperature_function") != ""
62  ? &getFunction("specific_heat_temperature_function")
63  : nullptr),
64  _specific_heat_dT(is_ad && !_specific_heat_temperature_function
65  ? nullptr
66  : &declareGenericProperty<Real, is_ad>("specific_heat_dT")),
67  _min_T(isParamValid("min_T") ? &getParam<Real>("min_T") : nullptr)
68 {
70  paramError("thermal_conductivity_temperature_function",
71  "Must couple with temperature if using thermal conductivity function");
72 
73  if (isParamValid("thermal_conductivity") && _thermal_conductivity_temperature_function)
74  mooseError(
75  "Cannot define both thermal conductivity and thermal conductivity temperature function");
76 
78  paramError("specific_heat_temperature_function",
79  "Must couple with temperature if using specific heat function");
80 
81  if (isParamValid("specific_heat") && _specific_heat_temperature_function)
82  mooseError("Cannot define both specific heat and specific heat temperature function");
83 }
84 
85 template <bool is_ad>
86 void
88 {
89  auto qp_temperature = _temperature[_qp];
90 
91  if (_has_temp && _min_T)
92  {
93  if (_temperature[_qp] < *_min_T)
94  {
95  flagSolutionWarning("Temperature below specified minimum (" + std::to_string(*_min_T) +
96  "). min_T will be used instead.");
97  qp_temperature = *_min_T;
98  }
99  }
100 
101  if (_thermal_conductivity_temperature_function)
102  {
103  _thermal_conductivity[_qp] = _thermal_conductivity_temperature_function->value(qp_temperature);
104  _thermal_conductivity_dT[_qp] = _thermal_conductivity_temperature_function->timeDerivative(
105  MetaPhysicL::raw_value(qp_temperature));
106  }
107  else
108  {
109  _thermal_conductivity[_qp] = _my_thermal_conductivity;
110  _thermal_conductivity_dT[_qp] = 0;
111  }
112 
113  if (_specific_heat_temperature_function)
114  {
115  _specific_heat[_qp] = _specific_heat_temperature_function->value(qp_temperature);
116  if (_specific_heat_dT)
117  (*_specific_heat_dT)[_qp] = _specific_heat_temperature_function->timeDerivative(
118  MetaPhysicL::raw_value(qp_temperature));
119  }
120  else
121  _specific_heat[_qp] = _my_specific_heat;
122 }
123 
125 template class HeatConductionMaterialTempl<true>;
void paramError(const std::string &param, Args... args) const
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
registerMooseObject("HeatTransferApp", HeatConductionMaterial)
HeatConductionMaterialTempl(const InputParameters &parameters)
const Function *const _thermal_conductivity_temperature_function
auto raw_value(const Eigen::Map< T > &in)
const Function *const _specific_heat_temperature_function
static InputParameters validParams()
void deprecateCoupledVar(const std::string &old_name, const std::string &new_name, const std::string &removal_date)
Simple material with properties set as constants or by functions.
void addCoupledVar(const std::string &name, const std::string &doc_string)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void mooseError(Args &&... args) const
void addClassDescription(const std::string &doc_string)
bool isParamValid(const std::string &name) const
virtual void computeQpProperties() override
static InputParameters validParams()