Package mbdyn :: Module elements_base
[hide private]

Source Code for Module mbdyn.elements_base

  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 base objects for the elements. 
 23  The classes defined in that module are abstract, they defined an element  
 24  with node, by the class L{ElementWithNode} and an element without node,  
 25  by the class L{ElementWithoutNode}. Those two classes are the bases shared 
 26  by all the element definitions. 
 27  The L{ELEM_CLASS} dictionary, gathering all the element classes, is also created 
 28  in that module but will be filled in the L{mbdyn.elements} module. 
 29  """ 
 30  from mbdyn.references import NONE_REF 
 31  from mbdyn.common import BasicObject, MANAGER 
 32   
 33  ELEM_GROUP_LIST = [\ 
 34  "ROTOR", 
 35  "AUTOMATICSTRUCTURAL", 
 36  "GRAVITY", 
 37  "BODY", 
 38  "JOINT" 
 39  "BEAM",  
 40  "PLATE", 
 41  "FORCE", 
 42  "ELECTRICBULK",  
 43  "ELECTRIC",  
 44  "HYDRAULIC", 
 45  "BULK",  
 46  "LOADABLE", 
 47  "DRIVEN", 
 48  "EXTERNAL", 
 49  "AIRPROPERTIES", 
 50  "AEROMODAL", 
 51  "AERODYNAMIC", 
 52  "GENEL",  
 53  "SOCKETSTREAM_OUTPUT", 
 54  ] 
 55   
 56  ELEM_CLASS = {} 
 57  for group_key in ELEM_GROUP_LIST: 
 58      ELEM_CLASS[group_key] = {} 
 59   
 60   
61 -class CommonElement(BasicObject):
62 """A common element belongs to a group and has a clas key, 63 specific to that group, that allow to retrieve its class. 64 """ 65
66 - def __init__(self, name):
67 BasicObject.__init__(self, name) 68 self.group_key = None 69 self.class_key = None 70 self.own_para_names += ["class_key", "group_key"]
71
72 - def do_as_init(self):
73 """A function defined by the user 74 when he inherits from an object having 75 MBDyn bindings. 76 """ 77 pass
78
79 - def update(self, simulation):
80 """The update of the MBDyn object at each time step. 81 Used by the user when he inherits from a Python 82 object having MBDyn bindings. 83 """ 84 pass
85
86 - def set_default(self):
87 """The default property set on an element. This method 88 is only used when writing the MBDyn input file from Python""" 89 pass
90 91
92 -class ElementWithoutNode(CommonElement):
93 """Common class for the objects without node.""" 94
95 - def __init__(self, name):
96 CommonElement.__init__(self, name) 97 self.ref = NONE_REF
98
99 - def set_node_label(self):
100 """Not of use here. Those kind of element are not attached to a node 101 (used nevertheless when looping through the objects for setting 102 the nodes label (or index) in the 'Simulation')""" 103 pass
104
105 - def set_value(self, value, com=None):
106 """Set a MBDyn driver to a constant value. 107 for example:: 108 109 set_value(4.) 110 111 will write: C{const, 4.} in the MBDyn input file.""" 112 MANAGER.add_argument(self, "value", value, com, 113 "const, %s" % str(value))
114
115 - def set_mbdyn_value(self, arg, com=None):
116 """Directly set the MBDyn driver as string. 117 It must be the right MBDyn syntax, nothing will be done 118 by the package. The drivers are not really supported as 119 this functionality is supposed to be provided by the bindings module 120 and WraptMBDyn.""" 121 MANAGER.add_argument(self, "value", arg, com)
122 123
124 -class ElementWithNode(CommonElement):
125 """Every element attached to a node.""" 126
127 - def __init__(self, name):
128 CommonElement.__init__(self, name) 129 self.ref = NONE_REF 130 self.arg_names = ["label"] 131 self.node = None 132 self.mbdyn_node = None
133
134 - def attach_to_node(self, node):
135 """Keep the reference of the node""" 136 self.node = node
137
138 - def set_node_label(self):
139 """Set the node label (or index) for the element once its node 140 has received a label for the MBDyn input file""" 141 self.mbdyn_node = self.node.mbdyn_label
142
143 - def set_relative_from(self, ref):
144 """Set the relative reference frame. From it, the properties will be 145 entered. Once this method called, the default properties are 146 set on the object, with an update of reference frame. 147 This method is usually called just after the object creation, else 148 there is no relative reference frame written for the input file. 149 150 WARNING: If this method is used as last, the object properties 151 are not updated. This is default of the package that needs 152 to be fixed. 153 154 Example:: 155 156 ref = ReferenceFrame() 157 ref.set_position(10., 0., 0.) 158 159 node1 = StructuralNode() 160 node1.set_relative_from(ref) 161 node1.set_position(5., 0., 0.) 162 163 node2 = StructuralNode() 164 node2.set_position(5., 0., 0.) 165 node2.set_relative_from(ref) 166 167 Relative to the absolute reference frame, the node 1 will be 168 placed 15m from the origin while the node 2 will be only at 5m. 169 """ 170 self.ref = ref 171 self.set_default()
172