www.mooseframework.org
RigidBodyModes3D.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 "RigidBodyModes3D.h"
9 #include "NonlinearSystem.h"
10 
11 template <>
12 InputParameters
14 {
15  InputParameters params = validParams<NodalUserObject>();
16  params.addRequiredParam<std::string>("subspace_name",
17  "FEProblemBase subspace containing rigid body mode vectors");
18  params.addParam<std::vector<unsigned int>>(
19  "subspace_indices",
20  std::vector<unsigned int>(),
21  "Indices of FEProblemBase subspace vectors containing rigid body modes");
22  params.addParam<std::vector<std::string>>("modes",
23  std::vector<std::string>(),
24  "Names of the RigidBody3D modes computed here. Select "
25  "from: trans_x, trans_y, trans_z, rot_x, rot_y, rot_z");
26  params.addRequiredCoupledVar("disp_x", "x-displacement");
27  params.addRequiredCoupledVar("disp_y", "y-displacement");
28  params.addRequiredCoupledVar("disp_z", "z-displacement");
29  // params.addRequiredParam<AuxVariableName>("trans_x_disp_x", "x-displacement's x-component");
30  // params.addRequiredParam<AuxVariableName>("trans_x_disp_y", "x-displacement's y-component");
31  // params.addRequiredParam<AuxVariableName>("trans_x_disp_z", "x-displacement's z-component");
32  // params.addRequiredParam<AuxVariableName>("trans_y_disp_x", "x-displacement's x-component");
33  // params.addRequiredParam<AuxVariableName>("trans_y_disp_y", "y-displacement's y-component");
34  // params.addRequiredParam<AuxVariableName>("trans_y_disp_z", "z-displacement's z-component");
35  // params.addRequiredParam<AuxVariableName>("trans_z_disp_x", "x-displacement's x-component");
36  // params.addRequiredParam<AuxVariableName>("trans_z_disp_y", "y-displacement's y-component");
37  // params.addRequiredParam<AuxVariableName>("trans_z_disp_z", "z-displacement's z-component");
38  // params.addRequiredParam<AuxVariableName>("rot_x_disp_x", "x-rotation's x-component");
39  // params.addRequiredParam<AuxVariableName>("rot_x_disp_y", "x-rotation's y-component");
40  // params.addRequiredParam<AuxVariableName>("rot_x_disp_z", "x-rotation's z-component");
41  // params.addRequiredParam<AuxVariableName>("rot_y_disp_x", "y-rotation's x-component");
42  // params.addRequiredParam<AuxVariableName>("rot_y_disp_y", "y-rotation's y-component");
43  // params.addRequiredParam<AuxVariableName>("rot_y_disp_z", "y-rotation's z-component");
44  // params.addRequiredParam<AuxVariableName>("rot_z_disp_x", "z-rotation's x-component");
45  // params.addRequiredParam<AuxVariableName>("rot_z_disp_y", "z-rotation's y-component");
46  // params.addRequiredParam<AuxVariableName>("rot_z_disp_z", "z-rotation's z-component");
47  return params;
48 }
49 
50 RigidBodyModes3D::RigidBodyModes3D(const InputParameters & parameters)
51  : NodalUserObject(parameters),
52  _subspace_name(parameters.get<std::string>("subspace_name")),
53  _subspace_indices(parameters.get<std::vector<unsigned int>>("subspace_indices")),
54  _modes(parameters.get<std::vector<std::string>>("modes").begin(),
55  parameters.get<std::vector<std::string>>("modes").end()),
56  _disp_x_i(coupled("disp_x")),
57  _disp_y_i(coupled("disp_y")),
58  _disp_z_i(coupled("disp_z"))
59 {
60  const char * all_modes_array[6] = {"trans_x", "trans_y", "trans_z", "rot_x", "rot_y", "rot_z"};
61  std::set<std::string> all_modes(all_modes_array, all_modes_array + 6);
62  if (_modes.size() == 0)
63  _modes = all_modes;
64  if (_modes.size() > 6)
65  {
66  std::stringstream err;
67  err << "Expected between 0 and 6 rigid body modes, got " << _modes.size() << " instead\n";
68  mooseError(err.str());
69  }
70  for (std::set<std::string>::const_iterator it = _modes.begin(); it != _modes.end(); ++it)
71  {
72  if (all_modes.find(*it) == all_modes.end())
73  {
74  std::stringstream err;
75  err << "Invalid 3D rigid body mode " << *it << "; must be one of: ";
76  for (std::set<std::string>::iterator it = all_modes.begin(); it != all_modes.end(); ++it)
77  {
78  if (it != all_modes.begin())
79  err << ", ";
80  err << *it;
81  }
82  err << "\n";
83  mooseError(err.str());
84  }
85  }
86 
87  if (!_subspace_indices.size())
88  {
89  _subspace_indices = std::vector<unsigned int>(_fe_problem.subspaceDim(_subspace_name));
90  for (unsigned int i = 0; i < _fe_problem.subspaceDim(_subspace_name); ++i)
91  _subspace_indices[i] = i;
92  }
93  if (_subspace_indices.size() != _modes.size())
94  {
95  std::stringstream err;
96  err << "Number of subspace indices " << _subspace_indices.size()
97  << " must match the number or rigid body modes " << _modes.size() << "\n";
98  mooseError(err.str());
99  }
100 
101  for (unsigned int i = 0; i < _subspace_indices.size(); ++i)
102  {
103  unsigned int subspace_dim = _fe_problem.subspaceDim(_subspace_name);
104  if (_subspace_indices[i] >= subspace_dim)
105  {
106  std::stringstream err;
107  err << "Invalid " << i << "-th " << _subspace_name << " index " << _subspace_indices[i]
108  << "; must be < " << _fe_problem.subspaceDim(_subspace_name) << "\n";
109  mooseError(err.str());
110  }
111  }
112 }
113 
114 void
116 {
117  // Set the appropriate dof of the selectedrigid body vectors
118  // Currently this only works for Lagrange displacement variables!
119  NonlinearSystemBase & nl = _fe_problem.getNonlinearSystemBase();
120  const Node & node = *_current_node;
121  unsigned int i = 0;
122  // x-displacement mode
123  if (_modes.count("trans_x"))
124  {
125  std::stringstream postfix;
126  postfix << "_" << _subspace_indices[i++];
127  NumericVector<Number> & mode = nl.getVector(_subspace_name + postfix.str());
128  unsigned int xdof = node.dof_number(nl.number(), _disp_x_i, 0);
129  mode.set(xdof, 1.0);
130  unsigned int ydof = node.dof_number(nl.number(), _disp_y_i, 0);
131  mode.set(ydof, 0.0);
132  unsigned int zdof = node.dof_number(nl.number(), _disp_z_i, 0);
133  mode.set(zdof, 0.0);
134  }
135  // y-displacement mode
136  if (_modes.count("trans_y"))
137  {
138  std::stringstream postfix;
139  postfix << "_" << _subspace_indices[i++];
140  NumericVector<Number> & mode = nl.getVector(_subspace_name + postfix.str());
141  unsigned int xdof = node.dof_number(nl.number(), _disp_x_i, 0);
142  mode.set(xdof, 0.0);
143  unsigned int ydof = node.dof_number(nl.number(), _disp_y_i, 0);
144  mode.set(ydof, 1.0);
145  unsigned int zdof = node.dof_number(nl.number(), _disp_z_i, 0);
146  mode.set(zdof, 0.0);
147  }
148  // z-displacement mode
149  if (_modes.count("trans_z"))
150  {
151  std::stringstream postfix;
152  postfix << "_" << _subspace_indices[i++];
153  NumericVector<Number> & mode = nl.getVector(_subspace_name + postfix.str());
154  unsigned int xdof = node.dof_number(nl.number(), _disp_x_i, 0);
155  mode.set(xdof, 0.0);
156  unsigned int ydof = node.dof_number(nl.number(), _disp_y_i, 0);
157  mode.set(ydof, 0.0);
158  unsigned int zdof = node.dof_number(nl.number(), _disp_z_i, 0);
159  mode.set(zdof, 1.0);
160  }
161  // x-axis rotation mode
162  if (_modes.count("rot_x"))
163  {
164  std::stringstream postfix;
165  postfix << "_" << _subspace_indices[i++];
166  NumericVector<Number> & mode = nl.getVector(_subspace_name + postfix.str());
167  Real y = node(1), z = node(2);
168  unsigned int xdof = node.dof_number(nl.number(), _disp_x_i, 0);
169  mode.set(xdof, 0.0);
170  unsigned int ydof = node.dof_number(nl.number(), _disp_y_i, 0);
171  mode.set(ydof, -z);
172  unsigned int zdof = node.dof_number(nl.number(), _disp_z_i, 0);
173  mode.set(zdof, y);
174  }
175  // y-axis rotation mode
176  if (_modes.count("rot_y"))
177  {
178  std::stringstream postfix;
179  postfix << "_" << _subspace_indices[i++];
180  NumericVector<Number> & mode = nl.getVector(_subspace_name + postfix.str());
181  Real x = node(0), z = node(2);
182  unsigned int xdof = node.dof_number(nl.number(), _disp_x_i, 0);
183  mode.set(xdof, z);
184  unsigned int ydof = node.dof_number(nl.number(), _disp_y_i, 0);
185  mode.set(ydof, 0);
186  unsigned int zdof = node.dof_number(nl.number(), _disp_z_i, 0);
187  mode.set(zdof, -x);
188  }
189  // z-axis rotation mode
190  if (_modes.count("rot_z"))
191  {
192  std::stringstream postfix;
193  postfix << "_" << _subspace_indices[i++];
194  NumericVector<Number> & mode = nl.getVector(_subspace_name + postfix.str());
195  Real x = node(0), y = node(1);
196  unsigned int xdof = node.dof_number(nl.number(), _disp_x_i, 0);
197  mode.set(xdof, -y);
198  unsigned int ydof = node.dof_number(nl.number(), _disp_y_i, 0);
199  mode.set(ydof, x);
200  unsigned int zdof = node.dof_number(nl.number(), _disp_z_i, 0);
201  mode.set(zdof, 0);
202  }
203 }
204 
205 void
207 {
208  // Close the basis vectors
209  NonlinearSystemBase & nl = _fe_problem.getNonlinearSystemBase();
210  for (unsigned int i = 0; i < _subspace_indices.size(); ++i)
211  {
212  std::stringstream postfix;
213  postfix << "_" << _subspace_indices[i];
214  NumericVector<Number> & mode = nl.getVector(_subspace_name + postfix.str());
215  mode.close();
216  }
217 }
std::set< std::string > _modes
unsigned int _disp_z_i
InputParameters validParams< RigidBodyModes3D >()
virtual void finalize()
std::string _subspace_name
std::vector< unsigned int > _subspace_indices
virtual void execute()
This function will get called on each node.
RigidBodyModes3D(const InputParameters &parameters)
unsigned int _disp_x_i
unsigned int _disp_y_i