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

Source Code for Module mbdyn.bindings.basic_objects

  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 general classes for a node, an element and a reference frame. 
 23  The L{Node<mbdyn.bindings.basic_objects.Node>} class defined here  
 24  is an equivalent to the general C{Node} class defined in 'I{node.h}' and  
 25  manipulated by the C{DataManager}. The same remark applied for the  
 26  L{Element<mbdyn.bindings.basic_objects.Element>} class that is equivalent to  
 27  the C{Elem} class defined in 'I{elem.h}'. Those two classes   
 28  are used to defined all the other types of nodes or elements, this is  
 29  the MBDyn polymorphism. That's why this package follows the same organisation,  
 30  every node will first be converted to a  
 31  L{Node<mbdyn.bindings.basic_objects.Node>} or to an  
 32  L{Element<mbdyn.bindings.basic_objects.Element>} by L{WraptMBDyn}. 
 33  Then the L{Groups} class will try to access a more specific object.  
 34   
 35  However the class C{ReferenceFrame} in L{mbdyn.bindings.frames} 
 36  does not follow this complexity because a single definition is suffisant. 
 37  """ 
 38   
 39   
40 -class BasicObject:
41 """A basic bindings object interfacing a C++ instance.""" 42
43 - def __init__(self, c_inst=None):
44 """The C++ instance reference is supposed to be received 45 in the constructor 46 because this object will represent a MBDyn node, element 47 or reference frame""" 48 if c_inst != None: 49 self.c_inst = c_inst 50 self.label = c_inst.GetLabel()
51
52 - def set_c_inst(self, c_inst):
53 """Set the C++ instance coming from MBDyn""" 54 self.c_inst = c_inst
55
56 - def get_label(self):
57 """Return the MBDyn label""" 58 return self.label
59 60
61 -class Node(BasicObject):
62 """The top class of a node. This class is motivated by 'I{node.h}' 63 in MBDyn and 'I{node.i} in the SWIG interface.""" 64
65 - def __repr__(self):
66 mess = "Node pointer with label %s in MBDyn" 67 return mess % str(self.label)
68 69
70 -class Element(BasicObject):
71 """The top class of an element. This class is coming from 'I{elem.h}' 72 in MBDyn and 'I{elem.i}' for the SWIG interface""" 73
74 - def __init__(self, c_inst=None):
75 BasicObject.__init__(self, c_inst) 76 if c_inst != None: 77 self.class_key = c_inst.get_class_key()
78
79 - def __repr__(self):
80 mess = "%(class)s pointer with label %(label)s in MBDyn" 81 return mess % {"class" : self.class_key, 82 "label" : str(self.label)}
83 84 85 BASIC_CLASS = {"NODE": Node, "ELEM": Element} 86 87
88 -def fill_vector(array, vec3):
89 """A function to fill a Numpy array of size 3x1 from a C{Vec3} instance. 90 The C{Vec3} instance is described in the SWIG file 'I{libmbmath.i}'. 91 """ 92 for i in range(3): 93 array[i][0] = vec3.get_value(i)
94
95 -def fill_matrix(array, mat3x3):
96 """A function to fill a Numpy array of size 3x3 from a C{Mat3x3} 97 instance. The C{Mat3x3} instance is described in the SWIG file 98 'I{libmbmath.i}'.""" 99 for i in range(3): 100 for j in range(3): 101 array[i][j] = mat3x3.get_value(i, j)
102