Package mbdyn :: Package elts :: Module force
[hide private]

Source Code for Module mbdyn.elts.force

  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 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   
33 -class GeneralForce(ElementWithNode):
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
38 - def __init__(self, name):
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):
52 """Set the type of force""" 53 MANAGER.add_argument(self, "force_type", force_type, com)
54
55 - def set_direction(self, *args, **kargs):
56 """Set the direction of the force""" 57 MANAGER.add_vector(self, "direction", args, kargs)
58
59 - def set_amplitude(self, value, com=None):
60 """Set the amplitude of the force""" 61 MANAGER.add_argument(self, "amplitude", value, com, 62 "const, " + str(value))
63
64 - def init_results(self):
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
70 - def get_mbdyn_instance(self):
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
80 - def __init__(self, name="force"):
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
88 - def set_default(self):
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
95 - def set_arm(self, *args, **kargs):
96 """Set the arm of the force""" 97 MANAGER.add_vector(self, "arm", args, kargs)
98 99 100 FORCE_CLASS["Force"] = Force 101 102
103 -class ConservativeForce(Force):
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
115 -class BindingsForce(Force):
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"):
122 Force.__init__(self, name) 123 self.class_key = "BindingsForce" 124 self.set_type("external swig")
125 126 127 FORCE_CLASS["BindingsForce"] = BindingsForce 128 129
130 -class Couple(GeneralForce):
131 """The top class for the couples. 132 """ 133
134 - def __init__(self, name):
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
143 - def set_default(self):
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
150 -class ConservativeCouple(Couple):
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
161 -class BindingsCouple(Couple):
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"):
168 Couple.__init__(self, name) 169 self.class_key = "BindingsCouple" 170 self.set_type("external swig")
171 172 173 FORCE_CLASS["BindingsCouple"] = BindingsCouple 174