1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 """The classes implemented in the force group.
23 This module introduces an interface between the instances from the swigModule
24 and the forces available for the user. For example for setting the
25 value of a force, a numpy array is provided and the C++ vector object,
26 Vec3, is filled by the method.
27
28 The two MBDyn extensions are
29 L{BindingsForce<mbdyn.bindings.forces.BindingsForce>} and
30 L{BindingsCouple<mbdyn.bindings.forces.BindingsCouple>} that can set
31 their value at each time step. They are however supposed to be managed
32 by the L{mbdyn.elts.force} module.
33
34
35 All the classes are contained into L{FORCE_CLASS}, then used
36 by L{mbdyn.bindings.groups}.
37 """
38 import numpy as N
39 from mbdyn.bindings.elements import Force
40
41
43 """The communication with the MBDyn structural force.
44 """
45
49
51 """Fill the value from the C++ interface into
52 the numpy array"""
53 for i in range(3):
54 self.value[i] = self.c_inst.Finterface.get_value(i)
55
57 """Return a copy of the force value"""
58 self.fill_value()
59 return self.value.copy()
60
64
65
67 """The conservative force of MBDyn.
68 """
69
71 mess = "ConservativeForce with label %s in MBDyn"
72 return mess % str(self.label)
73
74
76 """A MBDyn conservative force on which the value can be set
77 at every time step. This object is a MBDyn extension on which
78 the C{AssRes} method, called at each iteration, has been
79 transformed.
80 """
81
83 """Do no perform any operation for a BindingsForce,
84 the value is always known."""
85 pass
86
88 """Return a copy of the force value"""
89 return self.value.copy()
90
92 """Set the value on the MBDyn C++ instance.
93
94 @type array: numpy array
95 @param array: a vector of size 3x1
96 """
97 for i in range(3):
98 self.value[i] = array[i]
99 self.c_inst.F.set_value(i, float(array[i]))
100
102 mess = "BindingsForce with label %s in MBDyn"
103 return mess % str(self.label)
104
105
107 """The MBDyn conservative couple"""
108
110 mess = "ConservativeCouple with label %s in MBDyn"
111 return mess % str(self.label)
112
113
115 """A MBDyn conservative couple on which a value can be set at each time
116 step. This object is a MBDyn extension.
117 """
118
120 """Do not fill the couple value because the value is always
121 known"""
122 pass
123
125 """Return a copy of the value vector"""
126 return self.value.copy()
127
129 """Set the value of the torque to the MBDyn instance.
130
131 @type array: numpy array
132 @param array: a vector of size 3x1
133 """
134 for i in range(3):
135 self.value[i] = array[i]
136 self.c_inst.Value.set_value(i, float(array[i]))
137
139 mess = "BindingsCouple with label %s in MBDyn"
140 return mess % str(self.label)
141
142
143 FORCE_CLASS = {}
144 FORCE_CLASS["general"] = Force
145 FORCE_CLASS["conservative_force"] = ConservativeForce
146 FORCE_CLASS["bindings_force"] = BindingsForce
147
148 FORCE_CLASS["conservative_couple"] = ConservativeCouple
149 FORCE_CLASS["bindings_couple"] = BindingsCouple
150