pyNastran  0.5.0
pyNastran BDF Reader/Writer, OP2 Parser, and GUI
bush.py
Go to the documentation of this file.
00001 ## GNU Lesser General Public License
00002 ## 
00003 ## Program pyNastran - a python interface to NASTRAN files
00004 ## Copyright (C) 2011-2012  Steven Doyle, Al Danial
00005 ## 
00006 ## Authors and copyright holders of pyNastran
00007 ## Steven Doyle <mesheb82@gmail.com>
00008 ## Al Danial    <al.danial@gmail.com>
00009 ## 
00010 ## This file is part of pyNastran.
00011 ## 
00012 ## pyNastran is free software: you can redistribute it and/or modify
00013 ## it under the terms of the GNU Lesser General Public License as published by
00014 ## the Free Software Foundation, either version 3 of the License, or
00015 ## (at your option) any later version.
00016 ## 
00017 ## pyNastran is distributed in the hope that it will be useful,
00018 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 ## GNU General Public License for more details.
00021 ## 
00022 ## You should have received a copy of the GNU Lesser General Public License
00023 ## along with pyNastran.  If not, see <http://www.gnu.org/licenses/>.
00024 ## 
00025 # pylint: disable=C0103,R0902,R0904,R0914
00026 
00027 from __future__ import division, print_function
00028 #import sys
00029 #from numpy.linalg import norm
00030 
00031 from pyNastran.bdf.fieldWriter import set_blank_if_default
00032 from pyNastran.bdf.cards.baseCard import Element
00033 
00034 class BushElement(Element):
00035     def __init__(self, card, data):
00036         self.cid = None
00037         Element.__init__(self, card, data)
00038 
00039     def Cid(self):
00040         if isinstance(self.cid, int):
00041             return self.cid
00042         return self.cid.cid
00043 
00044     #def Ga(self):
00045         #print dir(self)
00046         #if isinstance(self.ga, int):
00047             #return self.ga
00048         #return self.ga.nid
00049 
00050     #def Gb(self):
00051         #if isinstance(self.gb, int):
00052             #return self.gb
00053         #return self.gb.nid
00054 
00055     #def NodeIDs(self):
00056         #print self.nodeIDs()
00057         #return [self.Ga(), self.Gb()]
00058 
00059 class CBUSH(BushElement):
00060     type = 'CBUSH'
00061     def __init__(self, card=None, data=None):
00062         BushElement.__init__(self, card, data)
00063         
00064         if card:
00065             self.eid = card.field(1)
00066             self.pid = card.field(2)
00067             self.ga = card.field(3)
00068             self.gb = card.field(4)
00069             x1G0    = card.field(5)
00070             if isinstance(x1G0, int):
00071                 self.g0 = x1G0
00072                 self.x = None
00073             elif isinstance(x1G0, float):
00074                 self.g0  = None
00075                 x1  = x1G0
00076                 x2  = card.field(6)
00077                 x3  = card.field(7)
00078                 self.x  = [x1, x2, x3]
00079             else:
00080                 #raise RuntimeError('invalid CBUSH...x1/g0 = |%s|' %(x1G0))
00081                 self.g0 = None
00082                 self.x  = [None, None, None]
00083             ###
00084             ## Element coordinate system identification. A 0 means the basic
00085             ## coordinate system. If CID is blank, then the element coordinate
00086             ## system is determined from GO or Xi.
00087             self.cid  = card.field(8, 0)
00088             ## Location of spring damper (0 <= s <= 1.0)
00089             self.s    = card.field(9, 0.5)
00090             ## Coordinate system identification of spring-damper offset. See
00091             ## Remark 9. (Integer > -1; Default = -1, which means the offset
00092             ## point lies on the line between GA and GB
00093             self.ocid = card.field(10, -1)
00094             ## Components of spring-damper offset in the OCID coordinate system
00095             ## if OCID > 0.
00096             self.si   = card.fields(i=11, j=13)
00097         else:
00098             self.eid = data[0]
00099             raise NotImplementedError('CBUSH data...')
00100         #self.prepareNodeIDs(nids,allowEmptyNodes=True)
00101         #assert len(self.nodes)==2
00102 
00103     #def OCid(self):
00104         #if isinstance(self.ocid,int):
00105             #return self.ocid
00106         #return self.ocid.cid
00107 
00108     def Cid(self):
00109         if isinstance(self.cid, int):
00110             return self.cid
00111         return self.cid.cid
00112 
00113     def crossReference(self, model):
00114         self.nodes = model.Nodes(self.nodes)
00115         #self.pid = model.Property(self.pid)
00116         self.cid = model.Coord(self.cid)
00117         
00118     def rawFields(self):
00119         if self.g0 is not None:
00120             x = [self.g0, None, None]
00121         else:
00122             x = self.x
00123         fields = ['CBUSH' ,self.eid, self.Pid(), self.ga, self.gb]+x+[self.Cid(),
00124                           self.s, self.ocid]+self.si
00125         return fields
00126 
00127     def reprFields(self):
00128         if self.g0 is not None:
00129             x = [self.g0, None, None]
00130         else:
00131             x = self.x
00132         
00133         cid = set_blank_if_default(self.Cid(), 0)
00134         fields = ['CBUSH', self.eid, self.Pid(), self.ga, self.gb]+x+[cid,
00135                           self.s, self.ocid]+self.si
00136         return fields
00137 
00138 class CBUSH1D(BushElement):
00139     type = 'CBUSH1D'
00140     def __init__(self, card=None, data=None):
00141         BushElement.__init__(self, card, data)
00142         if card:
00143             self.eid = int(card.field(1))
00144             self.pid = int(card.field(2, self.eid))
00145             nids = card.fields(3, 5)
00146             self.cid = card.field(5, 0)
00147         else:
00148             self.eid = data[0]
00149             self.pid = data[1]
00150             nids = data[2:4]
00151         ###
00152         self.prepareNodeIDs(nids)
00153         assert len(self.nodes)==2
00154 
00155     def crossReference(self, model):
00156         self.nodes = model.Nodes(self.nodes)
00157         self.pid = model.Property(self.pid)
00158         self.cid = model.Coord(self.cid)
00159 
00160     def rawFields(self):
00161         nodeIDs = self.nodeIDs()
00162         fields = ['CBUSH1D', self.eid, self.Pid(), nodeIDs[0], nodeIDs[1], self.Cid()]
00163         return fields
00164 
00165     def reprFields(self):
00166         nodeIDs = self.nodeIDs()
00167         cid = set_blank_if_default(self.Cid(), 0)
00168         fields = ['CBUSH1D', self.eid, self.Pid(), nodeIDs[0], nodeIDs[1], cid]
00169         return fields
00170 
00171 class CBUSH2D(BushElement):
00172     """
00173     2-D Linear-Nonlinear Connection
00174     Defines the connectivity of a two-dimensional Linear-Nonlinear element.
00175     """
00176     type = 'CBUSH2D'
00177     def __init__(self, card=None, data=None):
00178         BushElement.__init__(self, card, data)
00179         if card:
00180             self.eid = int(card.field(1))
00181             self.pid = int(card.field(2))
00182             nids = card.fields(3, 5)
00183             self.cid = int(card.field(5))
00184             self.plane = card.field(6, 'XY')
00185             self.sptid = card.field(7)
00186             if self.plane not in ['XY', 'YZ', 'ZX']:
00187                 msg = 'plane not in required list, plane=|%s|\n' %(self.plane)
00188                 msg += "expected planes = ['XY','YZ','ZX']"
00189                 raise RuntimeError(msg)
00190         else:
00191             self.eid = data[0]
00192             self.pid = data[1]
00193             nids = data[2:4]
00194         ###
00195         self.prepareNodeIDs(nids)
00196         assert len(self.nodes)==2
00197 
00198     def rawFields(self):
00199         nodeIDs = self.nodeIDs()
00200         fields = ['CBUSH1D', self.eid, self.Pid(), nodeIDs[0], nodeIDs[0], self.Cid(), self.plane, self.sptid]
00201         return fields
00202 
00203     def crossReference(self, model):
00204         self.nodes = model.Nodes(self.nodes)
00205         #self.pid = model.Property(self.pid)
00206         self.cid = model.Coord(self.cid)
00207 
00208     #def reprFields(self):
00209         #return self.rawFields()
00210 ###
 All Classes Namespaces Files Functions Variables