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

Source Code for Module mbdyn.bindings.nodes

  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 interface of MBDyn nodes. Each node group will have a 
 23  general class but until now the only group implemented is  
 24  the structural one. This file is however a start for further  
 25  development. The SWIG file used for the interface is 'I{node.i}'.  
 26  All the classes of that module are then imported in the  
 27  L{mbdyn.bindings.groups} thanks to the C{NODE_CLASS} 
 28  dictionary.""" 
 29  import numpy as N 
 30  from mbdyn.bindings.basic_objects import Node, fill_vector, fill_matrix 
 31   
 32   
33 -class Abstract(Node):
34 """The general node for the "ABSTRACT" group""" 35 pass
36
37 -class Structural(Node):
38 """The general node for the "STRUCTURAL" group. 39 This class is described in the C++ file 'I{strnode.h}'. 40 The concerned definition is C{StructNode}.""" 41
42 - def __init__(self, c_inst):
43 Node.__init__(self, c_inst) 44 45 self.position = N.zeros((3, 1)) 46 self.rotation_matrix = N.zeros((3, 3)) 47 self.velocity = N.zeros((3, 1)) 48 self.angular_velocity = N.zeros((3, 1))
49
50 - def _get_position(self):
51 """Get the position from the MBDyn node""" 52 vec3 = self.c_inst.GetXCurr() 53 fill_vector(self.position, vec3)
54
55 - def get_position(self):
56 """Return a copy of the position array. 57 58 @rtype: Numpy array 59 @return: vector of size 3x1""" 60 self._get_position() 61 return self.position.copy()
62
63 - def _get_rotation_matrix(self):
64 """Get the rotation matrix from the MBDyn node""" 65 mat3x3 = self.c_inst.GetRCurr() 66 fill_matrix(self.rotation_matrix, mat3x3)
67
68 - def get_rotation_matrix(self):
69 """Return a copy of the rotation matrix array 70 the definition of its local reference frame. 71 72 @rtype: Numpy array 73 @return: matrix of size 3x3""" 74 self._get_rotation_matrix() 75 return self.rotation_matrix.copy()
76
77 - def _get_velocity(self):
78 """Get the velocity from the MBDyn node.""" 79 vec3 = self.c_inst.GetVCurr() 80 fill_vector(self.velocity, vec3)
81
82 - def get_velocity(self):
83 """Return a copy of the velocity array. 84 85 @rtype: Numpy array 86 @return: vector of size 3x1""" 87 self._get_velocity() 88 return self.velocity.copy()
89
90 - def _get_angular_velocity(self):
91 """Get the angular velocity from the MBDyn node.""" 92 vec3 = self.c_inst.GetWCurr() 93 fill_vector(self.angular_velocity, vec3)
94
95 - def get_angular_velocity(self):
96 """Return a copy of the angular velocity array. 97 98 @rtype: Numpy array 99 @return: vector of size 3x1""" 100 self._get_angular_velocity() 101 return self.angular_velocity.copy()
102
103 - def __repr__(self):
104 """Return the node representation as a string""" 105 mess = "StructNode with label %s in MBDyn" 106 return mess % str(self.label)
107 108
109 -class Electric(Node):
110 """The general node for the "ELECTRIC" group""" 111 pass
112
113 -class Parameter(Node):
114 """The general node for the "PARAMETER" group""" 115 pass
116
117 -class Hydraulic(Node):
118 """The general group for the "HYDRAULIC" group""" 119 pass
120 121 122 NODE_CLASS_TABLE = [ 123 ("ABSTRACT", Abstract), 124 ("STRUCTURAL", Structural), 125 ("ELECTRIC", Electric), 126 ("PARAMETER", Parameter), 127 ("HYDRAULIC", Hydraulic) 128 ] 129 130 NODE_CLASS = {} 131 132 for group_key, general_class in NODE_CLASS_TABLE: 133 NODE_CLASS[group_key] = {"general" : general_class} 134