www.mooseframework.org
ConstitutiveModel.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 "ConstitutiveModel.h"
11 #include "SolidModel.h"
12 #include "Function.h"
13 
14 template <>
15 InputParameters
17 {
18  InputParameters params = validParams<SolidModel>();
19 
20  params.addCoupledVar("temp", "Coupled Temperature");
21 
22  params.addParam<Real>("thermal_expansion", "The thermal expansion coefficient.");
23  params.addParam<FunctionName>("thermal_expansion_function",
24  "Thermal expansion coefficient as a function of temperature.");
25  params.addParam<Real>(
26  "stress_free_temperature",
27  "The stress-free temperature. If not specified, the initial temperature is used.");
28  params.addParam<Real>("thermal_expansion_reference_temperature",
29  "Reference temperature for mean thermal expansion function.");
30  MooseEnum cte_function_type("instantaneous mean");
31  params.addParam<MooseEnum>("thermal_expansion_function_type",
32  cte_function_type,
33  "Type of thermal expansion function. Choices are: " +
34  cte_function_type.getRawNames());
35 
36  return params;
37 }
38 
39 ConstitutiveModel::ConstitutiveModel(const InputParameters & parameters)
40  : Material(parameters),
41  _has_temp(isCoupled("temp")),
42  _temperature(_has_temp ? coupledValue("temp") : _zero),
43  _temperature_old(_has_temp ? coupledValueOld("temp") : _zero),
44  _alpha(parameters.isParamValid("thermal_expansion") ? getParam<Real>("thermal_expansion") : 0.),
45  _alpha_function(parameters.isParamValid("thermal_expansion_function")
46  ? &getFunction("thermal_expansion_function")
47  : NULL),
48  _has_stress_free_temp(isParamValid("stress_free_temperature")),
49  _stress_free_temp(_has_stress_free_temp ? getParam<Real>("stress_free_temperature") : 0.0),
50  _ref_temp(0.0),
51  _step_zero_cm(declareRestartableData<bool>("step_zero_cm", true)),
52  _step_one_cm(declareRestartableData<bool>("step_one_cm", true))
53 {
54  if (parameters.isParamValid("thermal_expansion_function_type"))
55  {
56  if (!_alpha_function)
57  mooseError("thermal_expansion_function_type can only be set when thermal_expansion_function "
58  "is used");
59  MooseEnum tec = getParam<MooseEnum>("thermal_expansion_function_type");
60  if (tec == "mean")
61  _mean_alpha_function = true;
62  else if (tec == "instantaneous")
63  _mean_alpha_function = false;
64  else
65  mooseError("Invalid option for thermal_expansion_function_type");
66  }
67  else
68  _mean_alpha_function = false;
69 
70  if (parameters.isParamValid("thermal_expansion_reference_temperature"))
71  {
72  if (!_alpha_function)
73  mooseError("thermal_expansion_reference_temperature can only be set when "
74  "thermal_expansion_function is used");
76  mooseError("thermal_expansion_reference_temperature can only be set when "
77  "thermal_expansion_function_type = mean");
78  _ref_temp = getParam<Real>("thermal_expansion_reference_temperature");
79  if (!_has_temp)
80  mooseError(
81  "Cannot specify thermal_expansion_reference_temperature without coupling to temperature");
82  }
83  else if (_mean_alpha_function)
84  mooseError("Must specify thermal_expansion_reference_temperature if "
85  "thermal_expansion_function_type = mean");
86 }
87 
88 void
89 ConstitutiveModel::setQp(unsigned int qp)
90 {
91  _qp = qp;
92 }
93 
94 void
95 ConstitutiveModel::computeStress(const Elem & /*current_elem*/,
96  const SymmElasticityTensor & elasticityTensor,
97  const SymmTensor & stress_old,
98  SymmTensor & strain_increment,
99  SymmTensor & stress_new)
100 {
101  stress_new = elasticityTensor * strain_increment;
102  stress_new += stress_old;
103 }
104 
105 bool
107 {
108  if (_t_step >= 1)
109  _step_zero_cm = false;
110 
111  if (_t_step >= 2)
112  _step_one_cm = false;
113 
114  if (_has_temp && !_step_zero_cm)
115  {
116  Real inc_thermal_strain;
117  Real d_thermal_strain_d_temp;
118 
119  Real old_temp;
121  old_temp = _stress_free_temp;
122  else
123  old_temp = _temperature_old[_qp];
124 
125  Real current_temp = _temperature[_qp];
126 
127  Real delta_t = current_temp - old_temp;
128 
129  Real alpha = _alpha;
130 
131  if (_alpha_function)
132  {
133  Point p;
134  Real alpha_current_temp = _alpha_function->value(current_temp, p);
135  Real alpha_old_temp = _alpha_function->value(old_temp, p);
136  Real alpha_stress_free_temperature = _alpha_function->value(_stress_free_temp, p);
137 
139  {
140  Real small(1e-6);
141 
142  Real numerator = alpha_current_temp * (current_temp - _ref_temp) -
143  alpha_old_temp * (old_temp - _ref_temp);
144  Real denominator = 1.0 + alpha_stress_free_temperature * (_stress_free_temp - _ref_temp);
145  if (denominator < small)
146  mooseError("Denominator too small in thermal strain calculation");
147  inc_thermal_strain = numerator / denominator;
148  d_thermal_strain_d_temp = alpha_current_temp * (current_temp - _ref_temp);
149  }
150  else
151  {
152  inc_thermal_strain = delta_t * 0.5 * (alpha_current_temp + alpha_old_temp);
153  d_thermal_strain_d_temp = alpha_current_temp;
154  }
155  }
156  else
157  {
158  inc_thermal_strain = delta_t * alpha;
159  d_thermal_strain_d_temp = alpha;
160  }
161 
162  strain_increment.addDiag(-inc_thermal_strain);
163  d_strain_dT.addDiag(-d_thermal_strain_d_temp);
164  }
165 
166  bool modified = true;
167  return modified;
168 }
validParams< ConstitutiveModel >
InputParameters validParams< ConstitutiveModel >()
Definition: ConstitutiveModel.C:16
ConstitutiveModel.h
ConstitutiveModel::_step_one_cm
bool & _step_one_cm
Definition: ConstitutiveModel.h:61
ConstitutiveModel::_alpha
const Real _alpha
Definition: ConstitutiveModel.h:52
ConstitutiveModel::_mean_alpha_function
bool _mean_alpha_function
Definition: ConstitutiveModel.h:56
ConstitutiveModel::applyThermalStrain
virtual bool applyThermalStrain(SymmTensor &strain_increment, SymmTensor &d_strain_dT)
Definition: ConstitutiveModel.C:106
ConstitutiveModel::_stress_free_temp
Real _stress_free_temp
Definition: ConstitutiveModel.h:55
SymmElasticityTensor
This class defines a basic set of capabilities any elasticity tensor should have.
Definition: SymmElasticityTensor.h:55
SymmTensor::addDiag
void addDiag(Real value)
Definition: SymmTensor.h:281
ConstitutiveModel::_ref_temp
Real _ref_temp
Definition: ConstitutiveModel.h:57
ConstitutiveModel::_step_zero_cm
bool & _step_zero_cm
Restartable data to check for the zeroth and first time steps.
Definition: ConstitutiveModel.h:60
SymmTensor
Definition: SymmTensor.h:21
ConstitutiveModel::_temperature_old
const VariableValue & _temperature_old
Definition: ConstitutiveModel.h:51
ConstitutiveModel::_has_stress_free_temp
bool _has_stress_free_temp
Definition: ConstitutiveModel.h:54
ConstitutiveModel::computeStress
virtual void computeStress(const Elem &, const SymmElasticityTensor &elasticityTensor, const SymmTensor &stress_old, SymmTensor &strain_increment, SymmTensor &stress_new)
Definition: ConstitutiveModel.C:95
ConstitutiveModel::_temperature
const VariableValue & _temperature
Definition: ConstitutiveModel.h:50
validParams< SolidModel >
InputParameters validParams< SolidModel >()
Definition: SolidModel.C:31
ConstitutiveModel::_alpha_function
const Function * _alpha_function
Definition: ConstitutiveModel.h:53
ConstitutiveModel::_has_temp
const bool _has_temp
Definition: ConstitutiveModel.h:49
SolidModel.h
ConstitutiveModel::ConstitutiveModel
ConstitutiveModel(const InputParameters &parameters)
Definition: ConstitutiveModel.C:39
ConstitutiveModel::setQp
void setQp(unsigned int qp)
Sets the value of the variable _qp for inheriting classes.
Definition: ConstitutiveModel.C:89