www.mooseframework.org
DisplacementAboutAxis.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 
9 #include "Function.h"
10 
11 template <>
12 InputParameters
14 {
15  InputParameters params = validParams<PresetNodalBC>();
17  params.addRequiredParam<int>("component", "The component for the rotational displacement");
18  params.set<bool>("use_displaced_mesh") = true;
19  return params;
20 }
21 
22 void
23 addDisplacementAboutAxisParams(InputParameters & params)
24 {
25  MooseEnum units("degrees radians");
26  params.addRequiredParam<FunctionName>("function",
27  "The function providing the angle of rotation.");
28  params.addRequiredParam<MooseEnum>("angle_units",
29  units,
30  "The units of the angle of rotation. Choices are:" +
31  units.getRawNames());
32  params.addRequiredParam<RealVectorValue>("axis_origin", "Origin of the axis of rotation");
33  params.addRequiredParam<RealVectorValue>("axis_direction", "Direction of the axis of rotation");
34 }
35 
36 DisplacementAboutAxis::DisplacementAboutAxis(const InputParameters & parameters)
37  : PresetNodalBC(parameters),
38  _component(getParam<int>("component")),
39  _func(getFunction("function")),
40  _angle_units(getParam<MooseEnum>("angle_units")),
41  _axis_origin(getParam<RealVectorValue>("axis_origin")),
42  _axis_direction(getParam<RealVectorValue>("axis_direction"))
43 {
44  if (_component < 0 || _component > 2)
45  mooseError("Invalid component given for ", name(), ": ", _component, ".");
46 
47  if (_axis_direction.norm() == 0.)
48  mooseError("Please specify a non-zero direction vector for the axis_direction in ", name());
49 }
50 
51 void
53 {
56 }
57 
58 Real
60 {
61  Point p(*_current_node);
62 
63  Real angle(_func.value(_t, *_current_node));
64  if (_angle_units == "degrees")
65  angle = angle * libMesh::pi / 180.0;
66 
67  ColumnMajorMatrix p_old(4, 1);
68  p_old(0, 0) = p(0);
69  p_old(1, 0) = p(1);
70  p_old(2, 0) = p(2);
71  p_old(3, 0) = 1;
72 
73  ColumnMajorMatrix p_new = rotateAroundAxis(p_old, angle);
74 
75  return p_new(_component, 0) - p_old(_component, 0);
76 }
77 
78 ColumnMajorMatrix
79 DisplacementAboutAxis::rotateAroundAxis(const ColumnMajorMatrix & p0, const Real angle)
80 {
81  ColumnMajorMatrix rotate_about_z(4, 4);
82  rotate_about_z(0, 0) = cos(angle);
83  rotate_about_z(0, 1) = -sin(angle);
84  rotate_about_z(0, 2) = 0;
85  rotate_about_z(0, 3) = 0;
86  rotate_about_z(1, 0) = sin(angle);
87  rotate_about_z(1, 1) = cos(angle);
88  rotate_about_z(1, 2) = 0;
89  rotate_about_z(1, 3) = 0;
90  rotate_about_z(2, 0) = 0;
91  rotate_about_z(2, 1) = 0;
92  rotate_about_z(2, 2) = 1;
93  rotate_about_z(2, 3) = 0;
94  rotate_about_z(3, 0) = 0;
95  rotate_about_z(3, 1) = 0;
96  rotate_about_z(3, 2) = 0;
97  rotate_about_z(3, 3) = 1;
98 
99  ColumnMajorMatrix transform =
101  return transform * p0;
102 }
103 
104 void
106 {
107  Real magnitude = _axis_direction.norm();
108  _axis_direction /= magnitude;
109 }
110 
111 void
113 {
114  // These parts of the transformation matrix only depend on the axis of rotation:
115 
116  Real length = _axis_direction.norm_sq();
118 
119  ColumnMajorMatrix transl(4, 4);
120  transl(0, 0) = 1;
121  transl(0, 1) = 0;
122  transl(0, 2) = 0;
123  transl(0, 3) = -_axis_origin(0);
124  transl(1, 0) = 0;
125  transl(1, 1) = 1;
126  transl(1, 2) = 0;
127  transl(1, 3) = -_axis_origin(1);
128  transl(2, 0) = 0;
129  transl(2, 1) = 0;
130  transl(2, 2) = 1;
131  transl(2, 3) = -_axis_origin(2);
132  transl(3, 0) = 0;
133  transl(3, 1) = 0;
134  transl(3, 2) = 0;
135  transl(3, 3) = 1;
136 
137  ColumnMajorMatrix rotate_about_x(4, 4);
138  rotate_about_x(0, 0) = 1;
139  rotate_about_x(0, 1) = 0;
140  rotate_about_x(0, 2) = 0;
141  rotate_about_x(0, 3) = 0;
142  rotate_about_x(1, 0) = 0;
143  rotate_about_x(1, 1) = _axis_direction(2) / v;
144  rotate_about_x(1, 2) = -_axis_direction(1) / v;
145  rotate_about_x(1, 3) = 0;
146  rotate_about_x(2, 0) = 0;
147  rotate_about_x(2, 1) = _axis_direction(1) / v;
148  rotate_about_x(2, 2) = _axis_direction(2) / v;
149  rotate_about_x(2, 3) = 0;
150  rotate_about_x(3, 0) = 0;
151  rotate_about_x(3, 1) = 0;
152  rotate_about_x(3, 2) = 0;
153  rotate_about_x(3, 3) = 1;
154 
155  ColumnMajorMatrix rotate_about_y(4, 4);
156  rotate_about_y(0, 0) = v / length;
157  rotate_about_y(0, 1) = 0;
158  rotate_about_y(0, 2) = -_axis_direction(0) / length;
159  rotate_about_y(0, 3) = 0;
160  rotate_about_y(1, 0) = 0;
161  rotate_about_y(1, 1) = 1;
162  rotate_about_y(1, 2) = 0;
163  rotate_about_y(1, 3) = 0;
164  rotate_about_y(2, 0) = _axis_direction(0) / length;
165  rotate_about_y(2, 1) = 0;
166  rotate_about_y(2, 2) = v / length;
167  rotate_about_y(2, 3) = 0;
168  rotate_about_y(3, 0) = 0;
169  rotate_about_y(3, 1) = 0;
170  rotate_about_y(3, 2) = 0;
171  rotate_about_y(3, 3) = 1;
172 
173  ColumnMajorMatrix transl_inv(4, 4);
174  transl.inverse(transl_inv);
175  ColumnMajorMatrix rotx_inv(4, 4);
176  rotate_about_x.inverse(rotx_inv);
177  ColumnMajorMatrix roty_inv(4, 4);
178  rotate_about_y.inverse(roty_inv);
179 
180  _transformation_matrix = rotate_about_y * rotate_about_x * transl;
181  _transformation_matrix_inv = transl_inv * rotx_inv * roty_inv;
182 }
virtual Real computeQpValue()
Evaluate the boundary condition at the current quadrature point and timestep.
DisplacementAboutAxis(const InputParameters &parameters)
ColumnMajorMatrix _transformation_matrix
void calculateTransformationMatrices()
Calculate the rotation about the x and y axes based on the provided axis direction vector at the star...
void calculateUnitDirectionVector()
Check if the provided axis direction vector is a unit vector and normalizes the vector if necessary d...
void addDisplacementAboutAxisParams(InputParameters &params)
InputParameters validParams< DisplacementAboutAxis >()
ColumnMajorMatrix _transformation_matrix_inv
ColumnMajorMatrix rotateAroundAxis(const ColumnMajorMatrix &p0, const Real angle)
Calculate the tranformation matrix to rotate in x, y, and z depends on the prescribed BC angle and th...