Package mbdyn :: Package bindings :: Module forces
[hide private]

Source Code for Module mbdyn.bindings.forces

  1  #!/usr/bin/env python 
  2  # -*- coding: utf-8 -*- 
  3  # 
  4  # This file is part of MBDyn sim suite. 
  5  # Copyright (C) 2007 André ESPAZE, as part of a Master thesis supervised by 
  6  # Martin O.L.Hansen (DTU) and Nicolas Chauvat (Logilab) 
  7   
  8  # MBDyn sim suite is free software; you can redistribute it and/or modify 
  9  # it under the terms of the GNU General Public License as published by 
 10  # the Free Software Foundation; either version 2 of the License, or 
 11  # (at your option) any later version. 
 12  # 
 13  # This program is distributed in the hope that it will be useful, 
 14  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 15  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 16  # GNU General Public License for more details. 
 17  # 
 18  # You should have received a copy of the GNU General Public License 
 19  # along with this program; if not, write to the Free Software 
 20  # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
 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   
42 -class StructuralForce(Force):
43 """The communication with the MBDyn structural force. 44 """ 45
46 - def __init__(self, c_inst=None):
47 Force.__init__(self, c_inst) 48 self.value = N.zeros((3, 1))
49
50 - def fill_value(self):
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
56 - def get_value(self):
57 """Return a copy of the force value""" 58 self.fill_value() 59 return self.value.copy()
60
61 - def get_driver_amplitude(self):
62 """Return the amplitude of the MBDyn driver""" 63 return self.c_inst.get_driver_amplitude()
64 65
66 -class ConservativeForce(StructuralForce):
67 """The conservative force of MBDyn. 68 """ 69
70 - def __repr__(self):
71 mess = "ConservativeForce with label %s in MBDyn" 72 return mess % str(self.label)
73 74
75 -class BindingsForce(ConservativeForce):
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
82 - def fill_value(self):
83 """Do no perform any operation for a BindingsForce, 84 the value is always known.""" 85 pass
86
87 - def get_value(self):
88 """Return a copy of the force value""" 89 return self.value.copy()
90
91 - def set_value(self, array):
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
101 - def __repr__(self):
102 mess = "BindingsForce with label %s in MBDyn" 103 return mess % str(self.label)
104 105
106 -class ConservativeCouple(StructuralForce):
107 """The MBDyn conservative couple""" 108
109 - def __repr__(self):
110 mess = "ConservativeCouple with label %s in MBDyn" 111 return mess % str(self.label)
112 113
114 -class BindingsCouple(ConservativeCouple):
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
119 - def fill_value(self):
120 """Do not fill the couple value because the value is always 121 known""" 122 pass
123
124 - def get_value(self):
125 """Return a copy of the value vector""" 126 return self.value.copy()
127
128 - def set_value(self, array):
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
138 - def __repr__(self):
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