1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 """The module for saving attributes during the simulation. The L{Results}
23 class is then used by the C{Record} object, in L{mbdyn.record}. The
24 L{Results} instance can be accessed by the C{results} or C{res}
25 attribute of a MBDyn object from which the results of the
26 simulation can be accessed.
27 """
28 from types import ListType
29
31 """A list that can be cleaned.
32 An abstract class used by L{Result} and L{Results}.
33 """
34
36 """Clean the list"""
37 for idx in range(len(self)):
38 item = self.pop()
39 del item
40
41
43 """A list of results for a particular object attribute.
44
45 For example: C{node.results.position} is a C{Result} instance,
46 that contains the position at each time step.
47 """
48
52
53
55 """All the possible results that will be saved during
56 the simulation. This class is attribute of almost all the MDByn objects.
57
58 This is an interface to the user that decides what he
59 would like to save for every object. The instance of this class is for
60 example accessed by: C{node.results}"""
61
65
66 - def add(self, attr_name):
67 """Add the attribute, as a string, that needs to be saved
68 during the simulation. It will create a new C{Result} instance"""
69 if attr_name not in self.names:
70 result = Result(attr_name)
71 self.append(result)
72 self.names.append(attr_name)
73
75 """Initialize the quantities and set them as attributes"""
76 for result in self:
77 result.clean()
78 setattr(self, result.attr_name, result)
79
81 """Return the representation of all the C{Result} attributes"""
82 string = "["
83 if len(self) > 0:
84 for name in self.names[:-1]:
85 string += name + ",\n"
86 string += self.names[-1]
87 string += "]"
88 return string
89
90
91
93 """A function used for plotting (likely to change because
94 not used any more)"""
95 return name[0].capitalize() + name[1:]
96
97
98 EULER_DESC = "Euler angle number %(key)s [%(unit)s]"
99
100 QUANTITIES_DESCRIPTION = {\
101
102
103 "position" : ["m", ("x", "y", "z")],
104 "euler" : ["rad", ("1", "2", "3"), EULER_DESC],
105 "velocity" : ["m/s", ("x", "y", "z")],
106 "angular_velocity" : ["rad/s", ("x", "y", "z")],
107 "value" : ["N", ("x", "y", "z")]
108 }
109
110
112 """A physical quantity having values along 3 axis.
113 This class is currently not used.
114 """
115
117 self.name = name
118 desc = QUANTITIES_DESCRIPTION[name]
119 self.unit = desc[0]
120 self.direction_labels = [label for label in desc[1]]
121 self.direction_list = [[], [], []]
122 if len(desc) == 3:
123 self.label_pattern = desc[2]
124 else:
125 self.label_pattern = "%(name)s along %(key)s [%(unit)s]"
126 self.label_dic = {"name": get_label_name(name), "unit": self.unit}
127
129 indice = self.direction_labels.index( direction_label )
130 return self.direction_list[indice]
131
133 """Return the label of the quantity. Used for plotting.
134 """
135 self.label_dic["key"] = direction_label
136 return self.label_pattern % self.label_dic
137