1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 """The module gathering all the elements.
23 All the MBDyn elements that have an interface are contained
24 in the ELEM_CLASS dictionary of that file.
25
26 The ELEM_CLASS is divided into all the MBDyn groups, each group
27 is another dictionary with all its classes.
28
29 For example:
30 ForceClass = ELEM_CLASS["FORCE"]["BindingsForce"]
31 will return the BindingsForce class.
32 """
33 from mbdyn.common import MANAGER
34 from mbdyn.general import NULL, EYE
35 from mbdyn.references import NONE_REF
36
37 from mbdyn.elements_base import ELEM_CLASS, ElementWithoutNode, ElementWithNode
38
39 from mbdyn.elts.aerodynamic import AERODYNAMIC_CLASS
40 from mbdyn.elts.beam import BEAM_CLASS
41 from mbdyn.elts.force import FORCE_CLASS
42 from mbdyn.elts.joint import JOINT_CLASS
43
44
45 ELEM_CLASS["AERODYNAMIC"] = AERODYNAMIC_CLASS
46 ELEM_CLASS["BEAM"] = BEAM_CLASS
47 ELEM_CLASS["FORCE"] = FORCE_CLASS
48 ELEM_CLASS["JOINT"] = JOINT_CLASS
49
50
52 """The MBDyn air properties.
53 This object is not attached to any node. Until know, only
54 constant driver can be used, set by the 'set_value' method.
55 """
56
57 - def __init__(self, name="air properties"):
58 ElementWithoutNode.__init__(self, name)
59 self.mbdyn_type = "air properties"
60 self.class_key = "AirProperties"
61 self.group_key = "AIRPROPERTIES"
62 self.control_data_without_values = [("air properties")]
63 self.arg_names = ["density", "sound_celerity",
64 "velocity", "value"]
65
67 """Set the density of the air in 'kg/m3'"""
68 MANAGER.add_argument(self, "density", value, com)
69
71 """Set the sound celerity in 'm/s'"""
72 MANAGER.add_argument(self, "sound_celerity", value, com)
73
75 """Set the velocity vector in 'm/s'"""
76 MANAGER.add_vector(self, "velocity", args, kargs)
77
78
79 ELEM_CLASS["AIRPROPERTIES"]["AirProperties"] = AirProperties
80
81
83 """The MBDyn gravity object.
84 This element is not attached to any node.
85
86 An example of use::
87
88 grav = Gravity()
89 grav.set_direction(0., 0., -1.)
90 grav.set_value(9.81)
91
92 C{grav} can then be added to the
93 L{Simulation<mbdyn.main.Simulation>} object by C{add_element}.
94 """
95
97 ElementWithoutNode.__init__(self, name)
98 self.mbdyn_type = "gravity"
99 self.class_key = "Gravity"
100 self.group_key = "GRAVITY"
101 self.control_data_without_values = [("gravity")]
102 self.arg_names = ["direction", "value"]
103
105 """Set the gravity direction"""
106 MANAGER.add_vector(self, "direction", args, kargs)
107
108
109 ELEM_CLASS["GRAVITY"]["Gravity"] = Gravity
110
111
112 -class Body(ElementWithNode):
113 """A MBDyn body with a mass, a center of mass and
114 and an inertia matrix. A body needs to be attached
115 to a node, so the body properties are provided
116 according to the node reference frame. There is usually no need to
117 use the C{set_relative_from} method, but it may be used anyway to
118 set an different center of mass by using a reference frame.
119
120 Example of use::
121
122 body = M.body()
123 body.attach_to(node)
124 body.set_mass(1.)
125 body.set_center_of_mass(0.5, 0., 0.)
126
127 By default a body has a mass of M{1. kg}, no offset
128 and an eye inertia matrix.
129 """
130
131 - def __init__(self, name="body"):
132 ElementWithNode.__init__(self, name)
133 self.mbdyn_type = "body"
134 self.class_key = "Body"
135 self.group_key = "BODY"
136 self.arg_names += ["node",
137 "mass",
138 "center_of_mass",
139 "inertia_matrix"]
140 self.control_data_with_values = [("rigid bodies",
141 "+1 # %s" % name)]
142 self.set_default()
143
144 - def set_default(self):
145 """Set the default definition of a body, those values will stay
146 unless specify by the user"""
147 self.set_mass(1.)
148 self.set_center_of_mass(NULL, ref=NONE_REF)
149 self.set_inertia_matrix(EYE, ref=NONE_REF)
150
151 - def set_relative_from(self, ref):
152 """The properties will be set relative to the provided
153 reference frame"""
154
155
156
157 self.ref = ref
158
159 - def set_mass(self, value, com=None):
160 """Set the mass of the body"""
161 MANAGER.add_argument(self, "mass", value, com)
162
163 - def set_center_of_mass(self, *args, **kargs):
164 """Set the relative center of mass for the body
165 according to the node reference frame"""
166 MANAGER.add_vector(self, "center_of_mass", args, kargs)
167
168 - def set_inertia_matrix(self, *args, **kargs):
169 """Set the inertia matrix on the body, by default
170 in the node reference frame"""
171 MANAGER.add_matrix(self, "inertia_matrix", args, kargs)
172
173
174 ELEM_CLASS["BODY"]["Body"] = Body
175