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