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