www.mooseframework.org
CrystalPlasticityStateVariable.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 /****************************************************************/
8 
9 #include <fstream>
10 
11 template <>
12 InputParameters
14 {
15  InputParameters params = validParams<CrystalPlasticityUOBase>();
16  params.addParam<FileName>(
17  "state_variable_file_name",
18  "",
19  "Name of the file containing the initial values of slip system resistances");
20  MooseEnum intvar_read_options("file_input inline_input user_input", "inline_input");
21  params.addParam<MooseEnum>(
22  "intvar_read_type",
23  intvar_read_options,
24  "Read from options for initial value of internal variables: Default from .i file");
25  params.addParam<std::vector<unsigned int>>("groups",
26  "To group the initial values on different "
27  "slip systems 'format: [start end)', i.e.'0 "
28  "4 8 11' groups 0-3, 4-7 and 8-11 ");
29  params.addParam<std::vector<Real>>("group_values",
30  "The initial values correspoinding to each "
31  "group, i.e. '0.0 1.0 2.0' means 0-4 = 0.0, "
32  "4-8 = 1.0 and 8-12 = 2.0 ");
33  params.addParam<std::vector<std::string>>("uo_state_var_evol_rate_comp_name",
34  "Name of state variable evolution rate component "
35  "property: Same as state variable evolution rate "
36  "component user object specified in input file.");
37  params.addParam<Real>("zero", 0.0, "Numerical zero for interval variable");
38  params.addParam<std::vector<Real>>("scale_factor", "Scale factor of individual component.");
39  params.addClassDescription(
40  "Crystal plasticity state variable class. Override the virtual functions in your class");
41  return params;
42 }
43 
45  : CrystalPlasticityUOBase(parameters),
46  _num_mat_state_var_evol_rate_comps(
47  parameters.get<std::vector<std::string>>("uo_state_var_evol_rate_comp_name").size()),
48  _mat_prop_state_var(getMaterialProperty<std::vector<Real>>(_name)),
49  _mat_prop_state_var_old(getMaterialPropertyOld<std::vector<Real>>(_name)),
50  _state_variable_file_name(getParam<FileName>("state_variable_file_name")),
51  _intvar_read_type(getParam<MooseEnum>("intvar_read_type")),
52  _groups(getParam<std::vector<unsigned int>>("groups")),
53  _group_values(getParam<std::vector<Real>>("group_values")),
54  _zero(getParam<Real>("zero")),
55  _scale_factor(getParam<std::vector<Real>>("scale_factor"))
56 {
58  mooseError("CrystalPlasticityStateVariable: Scale factor should be have the same size of "
59  "evolution rate components.");
60 
62 
63  for (unsigned int i = 0; i < _num_mat_state_var_evol_rate_comps; ++i)
64  _mat_prop_state_var_evol_rate_comps[i] = &getMaterialProperty<std::vector<Real>>(
65  parameters.get<std::vector<std::string>>("uo_state_var_evol_rate_comp_name")[i]);
66 }
67 
68 void
70  const Point & q_point) const
71 {
72  switch (_intvar_read_type)
73  {
74  case 0:
76  break;
77  case 1:
79  break;
80  case 2:
81  provideInitialValueByUser(val, q_point);
82  break;
83  default:
84  mooseError("CrystalPlasticityStateVariable: Read option for initial value of internal "
85  "variables is not supported.");
86  }
87 
88  for (unsigned int i = 0; i < _variable_size; ++i)
89  if (val[i] <= 0.0)
90  mooseError("CrystalPlasticityStateVariable: Value of state variables ", i, " non positive");
91 }
92 
93 void
95 {
96  MooseUtils::checkFileReadable(_state_variable_file_name);
97 
98  std::ifstream file;
99  file.open(_state_variable_file_name.c_str());
100 
101  for (unsigned int i = 0; i < _variable_size; ++i)
102  if (!(file >> val[i]))
103  mooseError("Error CrystalPlasticityStateVariable: Premature end of state_variable file");
104 
105  file.close();
106 }
107 
108 void
110 {
111  if (_groups.size() <= 0)
112  mooseError("CrystalPlasticityStateVariable: Error in reading initial state variable values: "
113  "Specify input in .i file or in state_variable file");
114  else if (_groups.size() != (_group_values.size() + 1))
115  mooseError(
116  "CrystalPlasticityStateVariable: The size of the groups and group_values does not match.");
117 
118  for (unsigned int i = 0; i < _groups.size() - 1; ++i)
119  {
120  unsigned int is, ie;
121 
122  is = _groups[i];
123  ie = _groups[i + 1] - 1;
124 
125  if (is > ie)
126  mooseError("CrystalPlasticityStateVariable: Start index is = ",
127  is,
128  " should be greater than end index ie = ",
129  ie,
130  " in state variable read");
131 
132  for (unsigned int j = is; j <= ie; ++j)
133  val[j] = _group_values[i];
134  }
135 }
136 
137 void
139  const Point & /*q_point*/) const
140 {
141  mooseError("Error CrystalPlasticityStateVariable: User has to overwrite "
142  "'provideInitialValueByUser' function"
143  "in order to provide specific initial values based on quadrature point location.");
144 }
145 
146 bool
148  Real dt,
149  std::vector<Real> & val) const
150 {
151  for (unsigned int i = 0; i < _variable_size; ++i)
152  {
153  val[i] = 0.0;
154  for (unsigned int j = 0; j < _num_mat_state_var_evol_rate_comps; j++)
155  val[i] += (*_mat_prop_state_var_evol_rate_comps[j])[qp][i] * dt * _scale_factor[j];
156  }
157 
158  for (unsigned int i = 0; i < _variable_size; ++i)
159  {
160  if (_mat_prop_state_var_old[qp][i] < _zero && val[i] < 0.0)
161  val[i] = _mat_prop_state_var_old[qp][i];
162  else
163  val[i] = _mat_prop_state_var_old[qp][i] + val[i];
164 
165  if (val[i] < 0.0)
166  return false;
167  }
168  return true;
169 }
MooseEnum _intvar_read_type
Read from options for initial values of internal variables.
const MaterialProperty< std::vector< Real > > & _mat_prop_state_var_old
virtual bool updateStateVariable(unsigned int qp, Real dt, std::vector< Real > &val) const
InputParameters validParams< CrystalPlasticityUOBase >()
std::vector< unsigned int > _groups
The _groups variable is used to group slip systems and assign the initial values to each group...
virtual void provideInitialValueByUser(std::vector< Real > &, const Point &) const
Crystal plasticity system userobject base class.
CrystalPlasticityStateVariable(const InputParameters &parameters)
std::vector< Real > _scale_factor
Scale factor of individual component.
std::vector< const MaterialProperty< std::vector< Real > > * > _mat_prop_state_var_evol_rate_comps
virtual void readInitialValueFromInline(std::vector< Real > &val) const
FileName _state_variable_file_name
File should contain initial values of the state variable.
std::vector< Real > _group_values
The _group_values are the initial values corresponding to each group.
InputParameters validParams< CrystalPlasticityStateVariable >()
virtual void readInitialValueFromFile(std::vector< Real > &val) const
virtual void initSlipSysProps(std::vector< Real > &val, const Point &q_point) const
Real _zero
Numerical zero for internal variable.