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