1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 """Module interfacing the MBDyn reference frames. The main object
23 defined is L{ReferenceFrame}. The others object used are
24 C{GLOBAL_REF} and C{NONE_REF} (an abstract referential that does
25 not write anything in the MBDyn input file -useful
26 for some of the quantities, like the mass of a body-).
27 """
28 from mbdyn.general import NULL, EYE
29 from mbdyn.common import BasicObject, MANAGER
30
31
33 """The most basic reference frame object.
34 """
35
39
41 """Return the representation, still not used"""
42 return self.mbdyn_representation
43
44
45 GLOBAL_REF = BasicReference("global")
46 NODE_REF = BasicReference("node")
47
48
50 """The reference frame interface. When describing a simulation,
51 the first instance is usually a ReferenceFrame because this is
52 a construction object.
53
54 In MBDyn, the reference frames are used to describe the initial
55 conditions of the problem. They are not going to be used for
56 the resolution. So this object exists only at the beginning of
57 the simulation and its values are saved when L{Simulation} calls
58 the method L{store_mbdyn_data}.
59
60 The reference frames are usually linked. A new reference frame is
61 described relative to another one by the L{set_relative_from} method.
62 The properties of one reference frame is inherited to all the reference
63 frames that are linked to. This feature is for example very useful
64 to give an initial rotational speed to many other reference frames,
65 and thus to the nodes attached to them. The drawback is that a mistake
66 done on a base reference frame is propagated to all the other ones.
67 A common mistake is a wrong orientation matrix.
68
69 By default a reference is frame is relative to the absolute referential,
70 with a null position, a identity rotation matrix, a null velocity and
71 a null angular velocity. However, it a relative reference frame is used,
72 it is important to call L{set_relative_from} just after the instance
73 creation (otherwise the default values will be applied relative to the
74 global reference frame - a default to fix).
75
76 Example of use::
77
78 import numpy as N
79
80 angle = N.pi/3.
81 ref1 = ReferenceFrame()
82 ref1.set_orientation_matrix(one=(N.cos(angle),
83 N.sin(angle),
84 0.),
85 three=(0., 0., 1.))
86
87 ref2 = ReferenceFrame()
88 ref2.set_relative_from(ref1)
89 ref2.set_position(10., 0., 0.)
90
91 ref3 = ReferenceFrame()
92 ref3.set_relative_from(ref2)
93 ref3.set_angular_velocity(0., 0., 2.2)
94
95 The reference frame C{ref1} is turn of a M{S{pi}/3} angle along the M{z} axis.
96 The reference frame C{ref2} follows this orientation and is placed at M{10 m}
97 from the origin. However, but this feature is provided by MBDyn,
98 its value in the absolute reference frame is:
99 M{(10. cos(S{pi}/3), 10. sin(S{pi}/3), 0.)}. C{ref3} gets a angular velocity
100 of M{2.2 rad/s} along the M{z} axis and is at
101 the position of C{ref2}. This kinematic property is going to be transfered to
102 any node attached to this reference frame. The reference frame can also be
103 used to enter element property, but the kinematic properties are in that
104 case not relevant as only the nodes introduced kinematic degrees
105 of freedom.
106
107 At the end, the MBDyn results are always output in the absolute
108 reference frame, from which the integration is performed. However,
109 transformations in a particular reference frame can be easily done by
110 using L{node<mbdyn.nodes.StructuralNode>}
111 rotation matrix that are updated at each iteration.
112 """
113
115 BasicReference.__init__(self, name)
116
117 self.mbdyn_type = "reference"
118 self.ref = GLOBAL_REF
119
120 self.own_para_names += ["label"]
121
122 self.arg_names = ["label", "rel_position", "rel_orientation_matrix",
123 "rel_velocity", "rel_angular_velocity"]
124
125
126 self.position = None
127 self.orientation_matrix = None
128 self.velocity = None
129 self.angular_velocity = None
130
131 self.will_save("position",
132 "orientation_matrix")
133 self.set_default()
134
143
145 """Set the relative reference frame. All the values entered
146 will be relative to the given reference frame."""
147 self.ref = ref
148 self.set_default()
149
151 """No referential and no prefix for the MBDyn input file"""
152 self.mbdyn_representation = ""
153 self.name = "None"
154
156 """Set the position relative to its reference frame."""
157 MANAGER.add_vector(self, "rel_position", args, kargs)
158
160 """Set the orientation matrix relative to its reference frame"""
161 MANAGER.add_orientation_matrix(self,
162 "rel_orientation_matrix", args, kargs)
163
165 """Set the velocity relative to its reference frame"""
166 MANAGER.add_vector(self, "rel_velocity", args, kargs)
167
169 """Set the initial angular velocity relative to its reference frame"""
170 MANAGER.add_vector(self, "rel_angular_velocity", args, kargs)
171
173 """Get the MBDyn instance created by WraptMBDyn. """
174 mbdyn_frames = self.simulation.wrapt_mbdyn.frames
175 self.mbdyn_inst = mbdyn_frames.get_from_label(self.label)
176
178 """Initialize the results and set the callbacks for
179 getting MBDyn values."""
180 for attr in self.results.names:
181 self.saving_actions[attr] = getattr(self.mbdyn_inst,
182 "get_" + attr)
183 self.has_saving_actions = True
184 self.common_init_results()
185
187 """Saved the initial values converted in the absolute reference frame
188 by MBDyn. By default, only the absolute position and absolute
189 orientation matrix are saved. The absolute velocity and
190 absolute angular velocity can be added by::
191
192 will_save("velocity",
193 "angular_velocity")
194
195 """
196 self._init_results()
197 self.save_results()
198
199
200
201 NONE_REF = ReferenceFrame()
202 NONE_REF.set_to_none()
203