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