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