1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 """The interface for writing the MBDyn control data.
23 """
24 from mbdyn.common import Block
25
26
28 """The control data of MBDyn, generated automatically by
29 the nodes and elements information or the user's object.
30 """
32 self.objects = []
33 self.name = "control data"
34 self.block = Block()
35 self.category = {}
36 self.obj_list = {}
37 self.extra_arguments = []
38
40 """Add an object to control data"""
41 self.objects.append(obj)
42
44 """Add an extra argument not yet managed by the interface,
45 it will be directly printed in the input file"""
46 self.extra_arguments.append(arg)
47
49 """Create the objects lists with the control data with values
50 (for example 'beams: +1;' in MBDyn) and control data without values
51 (for example 'gravity;').
52
53 Additionaly, the control data with values will need to gather all the
54 items that are in the same category.
55 (For example::
56
57 beams:
58 +2 # Tower
59 +1 # Nacelle
60 ;
61 )
62 A list for each category is here created. (Note: each category from
63 the user's model, not from all the MBDyn categories)
64 """
65 self.category = {"with_values" : {}, "without_values" : {}}
66 self.obj_list = {"with_values" : [], "without_values" : []}
67 for obj in self.objects:
68 if hasattr(obj, "control_data_with_values"):
69 for control_data in obj.control_data_with_values:
70 category_name = control_data[0]
71 self.category["with_values"][category_name] = []
72 self.obj_list["with_values"].append(obj)
73 if hasattr(obj, "control_data_without_values"):
74 self.obj_list["without_values"].append(obj)
75
77 """The objects having C{control_data_with_values} fill the dictionary
78 C{category["with_values"]} according to the category name. All their
79 MBDyn value are saved into a list for the input file writing.
80
81 The objects having C{control_data_without_values} just need
82 to give their category name, they do not have any value. However the
83 user may have different objects having the same control data without
84 value, for example the C{AirProperties}. This property
85 must not be duplicated in the input file. For consistency, the
86 C{self.category["without_values"][category_name]} is set to 1 but never
87 used, just the information on the C{category_name} is important.
88 """
89 for obj in self.obj_list["with_values"]:
90 for category_name, value in obj.control_data_with_values:
91 self.category["with_values"][category_name].append(value)
92 for obj in self.obj_list["without_values"]:
93 for category_name in obj.control_data_without_values:
94 self.category["without_values"][category_name] = 1
95
97 """Write the control data block into the MBDyn input file"""
98 self._sort_control_data()
99 self._fill_category()
100 self.block.set_file(file_to_write)
101 self.block.set_name(self.name)
102 self.block.begin()
103
104 for category_name in self.category["with_values"].keys():
105 self.block.write_line(category_name + ":")
106 self.block.indent()
107 for value in self.category["with_values"][category_name]:
108 self.block.write_line(value)
109 self.block.dedent()
110 self.block.write_line(";")
111
112 for category_name in self.category["without_values"].keys():
113 self.block.write_line(category_name + ";")
114 for arg in self.extra_arguments:
115 self.block.write_line(arg + ";")
116 self.block.end()
117