www.mooseframework.org
SolidMechanicsAction.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 "SolidMechanicsAction.h"
9 #include "Factory.h"
10 #include "FEProblem.h"
11 #include "Parser.h"
12 #include "MooseMesh.h"
13 
14 template <>
15 InputParameters
17 {
18  InputParameters params = validParams<Action>();
19  MooseEnum elemType("truss undefined", "undefined");
20  params.addParam<MooseEnum>("type", elemType, "The element type: " + elemType.getRawNames());
21  params.addParam<NonlinearVariableName>("disp_x", "", "The x displacement");
22  params.addParam<NonlinearVariableName>("disp_y", "", "The y displacement");
23  params.addParam<NonlinearVariableName>("disp_z", "", "The z displacement");
24  params.addParam<NonlinearVariableName>("disp_r", "", "The r displacement");
25  params.addParam<NonlinearVariableName>("temp", "", "The temperature");
26  params.addParam<Real>("zeta", 0.0, "Stiffness dependent damping parameter for Rayleigh damping");
27  params.addParam<Real>("alpha", 0.0, "alpha parameter for HHT time integration");
28  params.addParam<std::string>(
29  "appended_property_name", "", "Name appended to material properties to make them unique");
30  params.set<bool>("use_displaced_mesh") = true;
31  params.addParam<std::vector<SubdomainName>>(
32  "block", "The list of ids of the blocks (subdomain) that these kernels will be applied to");
33  params.addParam<bool>("volumetric_locking_correction",
34  true,
35  "Set to false to turn off volumetric locking correction");
36 
37  params.addParam<std::vector<AuxVariableName>>(
38  "save_in_disp_x", "Auxiliary variables to save the x displacement residuals.");
39  params.addParam<std::vector<AuxVariableName>>(
40  "save_in_disp_y", "Auxiliary variables to save the y displacement residuals.");
41  params.addParam<std::vector<AuxVariableName>>(
42  "save_in_disp_z", "Auxiliary variables to save the z displacement residuals.");
43  params.addParam<std::vector<AuxVariableName>>(
44  "save_in_disp_r", "Auxiliary variables to save the r displacement residuals.");
45  params.addParam<std::vector<AuxVariableName>>(
46  "diag_save_in_disp_x",
47  "Auxiliary variables to save the x displacement diagonal preconditioner terms.");
48  params.addParam<std::vector<AuxVariableName>>(
49  "diag_save_in_disp_y",
50  "Auxiliary variables to save the y displacement diagonal preconditioner terms.");
51  params.addParam<std::vector<AuxVariableName>>(
52  "diag_save_in_disp_z",
53  "Auxiliary variables to save the z displacement diagonal preconditioner terms.");
54  params.addParam<std::vector<AuxVariableName>>(
55  "diag_save_in_disp_r",
56  "Auxiliary variables to save the r displacement diagonal preconditioner terms.");
57  return params;
58 }
59 
60 SolidMechanicsAction::SolidMechanicsAction(const InputParameters & params)
61  : Action(params),
62  _disp_x(getParam<NonlinearVariableName>("disp_x")),
63  _disp_y(getParam<NonlinearVariableName>("disp_y")),
64  _disp_z(getParam<NonlinearVariableName>("disp_z")),
65  _disp_r(getParam<NonlinearVariableName>("disp_r")),
66  _temp(getParam<NonlinearVariableName>("temp")),
67  _zeta(getParam<Real>("zeta")),
68  _alpha(getParam<Real>("alpha"))
69 {
70 }
71 
72 void
74 {
75  // list of subdomains IDs per coordinate system
76  std::map<Moose::CoordinateSystemType, std::vector<SubdomainName>> coord_map;
77  std::set<SubdomainID> subdomains;
78 
79  if (isParamValid("block")) // Should it be restricted to certain blocks?
80  {
81  Moose::out << "Restricting to blocks!" << std::endl;
82  std::vector<SubdomainName> block = getParam<std::vector<SubdomainName>>("block");
83  for (unsigned int i = 0; i < block.size(); i++)
84  subdomains.insert(_problem->mesh().getSubdomainID(block[i]));
85  }
86  else // Put it everywhere
87  subdomains = _problem->mesh().meshSubdomains();
88 
89  for (std::set<SubdomainID>::const_iterator it = subdomains.begin(); it != subdomains.end(); ++it)
90  {
91  SubdomainID sid = *it;
92  Moose::CoordinateSystemType coord_type = _problem->getCoordSystem(sid);
93 
94  // Convert the SubdomainID into SubdomainName since kernel params take SubdomainNames (this is
95  // retarded...)
96  std::stringstream ss;
97  ss << sid;
98  SubdomainName sname = ss.str();
99 
100  coord_map[coord_type].push_back(sname);
101  }
102 
103  for (std::map<Moose::CoordinateSystemType, std::vector<SubdomainName>>::iterator it =
104  coord_map.begin();
105  it != coord_map.end();
106  ++it)
107  {
108  Moose::CoordinateSystemType coord_type = (*it).first;
109  std::vector<SubdomainName> & blocks = (*it).second;
110 
111  // Determine whether RZ or RSPHERICAL
112  bool rz(false);
113  bool rspherical(false);
114  unsigned int dim(1);
115  std::vector<std::string> keys;
116  std::vector<VariableName> vars;
117  std::vector<std::vector<AuxVariableName>> save_in;
118  std::vector<std::vector<AuxVariableName>> diag_save_in;
119  std::string type("StressDivergence");
120  if (getParam<MooseEnum>("type") == 0) // truss
121  {
122  type = "StressDivergenceTruss";
123  }
124  else if (coord_type == Moose::COORD_RZ)
125  {
126  rz = true;
127  type = "StressDivergenceRZ";
128  dim = 2;
129  keys.push_back("disp_r");
130  keys.push_back("disp_z");
131  vars.push_back(_disp_r);
132  vars.push_back(_disp_z);
133  save_in.resize(dim);
134  if (isParamValid("save_in_disp_r"))
135  save_in[0] = getParam<std::vector<AuxVariableName>>("save_in_disp_r");
136 
137  if (isParamValid("save_in_disp_z"))
138  save_in[1] = getParam<std::vector<AuxVariableName>>("save_in_disp_z");
139 
140  diag_save_in.resize(dim);
141  if (isParamValid("diag_save_in_disp_r"))
142  diag_save_in[0] = getParam<std::vector<AuxVariableName>>("diag_save_in_disp_r");
143 
144  if (isParamValid("diag_save_in_disp_z"))
145  diag_save_in[1] = getParam<std::vector<AuxVariableName>>("diag_save_in_disp_z");
146  }
147  else if (coord_type == Moose::COORD_RSPHERICAL)
148  {
149  rspherical = true;
150  type = "StressDivergenceRSpherical";
151  dim = 1;
152  keys.push_back("disp_r");
153  vars.push_back(_disp_r);
154  save_in.resize(dim);
155  if (isParamValid("save_in_disp_r"))
156  save_in[0] = getParam<std::vector<AuxVariableName>>("save_in_disp_r");
157 
158  diag_save_in.resize(dim);
159  if (isParamValid("diag_save_in_disp_r"))
160  diag_save_in[0] = getParam<std::vector<AuxVariableName>>("diag_save_in_disp_r");
161  }
162 
163  if (!rz && !rspherical && _disp_x == "")
164  {
165  mooseError("disp_x must be specified");
166  }
167 
168  if (!rz && !rspherical)
169  {
170  keys.push_back("disp_x");
171  vars.push_back(_disp_x);
172  if (_disp_y != "")
173  {
174  ++dim;
175  keys.push_back("disp_y");
176  vars.push_back(_disp_y);
177  if (_disp_z != "")
178  {
179  ++dim;
180  keys.push_back("disp_z");
181  vars.push_back(_disp_z);
182  }
183  }
184 
185  save_in.resize(dim);
186  if (isParamValid("save_in_disp_x"))
187  save_in[0] = getParam<std::vector<AuxVariableName>>("save_in_disp_x");
188 
189  if (isParamValid("save_in_disp_y"))
190  save_in[1] = getParam<std::vector<AuxVariableName>>("save_in_disp_y");
191 
192  if (isParamValid("save_in_disp_z"))
193  save_in[2] = getParam<std::vector<AuxVariableName>>("save_in_disp_z");
194 
195  diag_save_in.resize(dim);
196  if (isParamValid("diag_save_in_disp_x"))
197  diag_save_in[0] = getParam<std::vector<AuxVariableName>>("diag_save_in_disp_x");
198 
199  if (isParamValid("diag_save_in_disp_y"))
200  diag_save_in[1] = getParam<std::vector<AuxVariableName>>("diag_save_in_disp_y");
201 
202  if (isParamValid("diag_save_in_disp_z"))
203  diag_save_in[2] = getParam<std::vector<AuxVariableName>>("diag_save_in_disp_z");
204  }
205 
206  unsigned int num_coupled(dim);
207  if (_temp != "")
208  {
209  ++num_coupled;
210  keys.push_back("temp");
211  vars.push_back(_temp);
212  }
213 
214  InputParameters params = _factory.getValidParams(type);
215  for (unsigned j(0); j < num_coupled; ++j)
216  {
217  params.addCoupledVar(keys[j], "");
218  params.set<std::vector<VariableName>>(keys[j]) = {vars[j]};
219  }
220 
221  params.set<bool>("use_displaced_mesh") = getParam<bool>("use_displaced_mesh");
222  params.set<std::string>("appended_property_name") =
223  getParam<std::string>("appended_property_name");
224 
225  for (unsigned int i(0); i < dim; ++i)
226  {
227  std::stringstream name;
228  name << _name;
229  name << i;
230 
231  params.set<unsigned int>("component") = i;
232 
233  params.set<NonlinearVariableName>("variable") = vars[i];
234  params.set<std::vector<SubdomainName>>("block") = blocks;
235  params.set<std::vector<AuxVariableName>>("save_in") = save_in[i];
236  params.set<std::vector<AuxVariableName>>("diag_save_in") = diag_save_in[i];
237  params.set<Real>("zeta") = _zeta;
238  params.set<Real>("alpha") = _alpha;
239  params.set<bool>("volumetric_locking_correction") =
240  getParam<bool>("volumetric_locking_correction");
241  _problem->addKernel(type, name.str(), params);
242  }
243  }
244 }
const NonlinearVariableName _disp_x
const NonlinearVariableName _disp_r
const NonlinearVariableName _disp_z
const NonlinearVariableName _temp
SolidMechanicsAction(const InputParameters &params)
InputParameters validParams< SolidMechanicsAction >()
const NonlinearVariableName _disp_y