Package mbdyn :: Module general
[hide private]

Source Code for Module mbdyn.general

  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  """All the built-in objects for working with MBDyn. 
 23   
 24  The two mains objects are C{NULL} and C{EYE}, there is also C{MATRIX_NULL}  
 25  in use. 
 26  C{NULL} is the vector null of size 3x1 
 27  C{EYE} is the identity matrix of size 3x3 
 28   
 29  The class L{Real} and L{Int} were started at the beginning but are not in use, 
 30  all the pre processing is done from Python. 
 31  """ 
 32  import numpy as N 
 33   
34 -class Real:
35 """A MBDyn real for the input file 36 """ 37
38 - def __init__(self, name=None, value=None, comment=None):
39 self.name = name 40 if not isinstance(value, float): 41 value = float(value) 42 self.value = value 43 self.comment = comment
44
45 - def __repr__(self):
46 return self.__str__()
47
48 - def __str__(self):
49 return "real %s = %f " % (self.name, self.value)
50 51
52 -class Int:
53 """A MBDyn integer for the input file 54 """ 55
56 - def __init__(self, name=None, value=None, comment=None):
57 self.name = name 58 if not isinstance(value, int): 59 value = int(value) 60 self.value = value 61 self.comment = comment
62
63 - def __repr__(self):
64 return self.__str__()
65
66 - def __str__(self):
67 return "integer %s = %f " % (self.name, self.value)
68 69
70 -class Null:
71 """The vector Null 72 """ 73
74 - def __init__(self):
75 self.value = N.array([0., 0., 0.]) 76 self.name = "null"
77 78
79 -class MatrixNull:
80 """The matrix Null 81 """
82 - def __init__(self):
83 self.value = N.array([[0., 0., 0.], 84 [0., 0., 0.], 85 [0., 0., 0.]]) 86 self.name = "null"
87 88
89 -class Eye:
90 """The eye matrix 91 """ 92
93 - def __init__(self):
94 self.value = N.eye(3) 95 self.name = "eye"
96 97 98 # Those objects can just exist as instance, they are MBDyn built-in 99 NULL = Null() 100 MAT_NULL = MatrixNull() 101 EYE = Eye() 102 103 # Used by the MANAGER in 'common.py' for scanning the arguments 104 EYE_NAME = "Eye" 105 VECTOR_NAMES = ["Null"] 106 MATRIX_NAMES = ["Eye", "MatrixNull"] 107