1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 """The elements of the force group. Two new classes have been introduced:
23 L{BindingsForce} and L{BindingsCouple} for communicating with
24 MBDyn at run time.
25 """
26 from mbdyn.common import MANAGER
27
28 from mbdyn.general import NULL
29 from mbdyn.elements_base import ElementWithNode
30
31 FORCE_CLASS = {}
32
34 """A general force for the FORCE group of MBDyn.
35 This class is abstract and used to defined
36 the top classes L{Force} and L{Couple}."""
37
39 ElementWithNode.__init__(self, name)
40 self.mbdyn_type = None
41 self.class_key = None
42 self.group_key = "FORCE"
43
44 self.value = 0.
45 self.will_save("value")
46
47 self.arg_names += ["force_type", "node", "direction"]
48
49 self.control_data_with_values = [("forces", "+1 # %s" % name)]
50
51 - def set_type(self, force_type, com=None):
54
56 """Set the direction of the force"""
57 MANAGER.add_vector(self, "direction", args, kargs)
58
60 """Set the amplitude of the force"""
61 MANAGER.add_argument(self, "amplitude", value, com,
62 "const, " + str(value))
63
65 """Initialize the results before running the simulation"""
66 self.saving_actions["value"] = self.mbdyn_inst.get_value
67 self.has_saving_actions = True
68 self.common_init_results()
69
71 """Get the MBDyn instance from L{mbdyn.bindings}"""
72 mbdyn_elements = self.simulation.wrapt_mbdyn.elts
73 self.mbdyn_inst = mbdyn_elements.forces.get_from_label(self.label)
74
75
76 -class Force(GeneralForce):
77 """The top class of all the forces.
78 """
79
81 GeneralForce.__init__(self, name)
82 self.mbdyn_type = "force"
83 self.class_key = "Force"
84 self.arg_names += ["arm", "amplitude"]
85
86 self.set_default()
87
89 """Set the default force option. It will be a direction
90 along the M{z} axis, and null arm offset and an amplitude of 1."""
91 self.set_direction(0., 0., 1.)
92 self.set_arm(NULL)
93 self.set_amplitude(1.)
94
98
99
100 FORCE_CLASS["Force"] = Force
101
102
104 """The MBDyn conservative force"""
105
106 - def __init__(self, name="Conservative force"):
107 Force.__init__(self, name)
108 self.class_key = "ConservativeForce"
109 self.set_type("conservative")
110
111
112 FORCE_CLASS["ConservativeForce"] = ConservativeForce
113
114
116 """A force that can be set at runtime. This class is
117 an extension to MBDyn as will manipulate the
118 C{BindingsForce} from L{mbdyn.bindings.forces}
119 """
120
121 - def __init__(self, name="Bindings force"):
125
126
127 FORCE_CLASS["BindingsForce"] = BindingsForce
128
129
131 """The top class for the couples.
132 """
133
135 GeneralForce.__init__(self, name)
136 self.mbdyn_type = "couple"
137 self.class_key = None
138
139 self.arg_names += ["amplitude"]
140
141 self.set_default()
142
144 """Set the default values for a couple. Those are
145 a direction along the M{z} axis and an amplitude of 1."""
146 self.set_direction(0., 0., 1.)
147 self.set_amplitude(1.)
148
149
151 """The MBDyn conservative couple"""
152
153 - def __init__(self, name="Conservative couple"):
154 Couple.__init__(self, name)
155 self.class_key = "ConservativeCouple"
156
157
158 FORCE_CLASS["ConservativeCouple"] = ConservativeCouple
159
160
162 """A couple that can be set at runtime. Through its
163 attribute C{mbdyn_inst} this class will manipulate
164 C{BindingsCouple} from L{mbdyn.bindings.forces}.
165 """
166
167 - def __init__(self, name="Bindings couple"):
171
172
173 FORCE_CLASS["BindingsCouple"] = BindingsCouple
174