pyNastran  0.5.0
pyNastran BDF Reader/Writer, OP2 Parser, and GUI
geom1.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 import sys
00026 from struct import unpack
00027 
00028 from pyNastran.bdf.cards.nodes import GRID
00029 from pyNastran.bdf.cards.coordinateSystems import (CORD1R, CORD1C, CORD1S,
00030                                                    CORD2R, CORD2C, CORD2S,
00031                                                    CORD3G)
00032 
00033 
00034 class Geometry1(object):
00035 
00036     def readTable_Geom1(self):
00037         self.iTableMap = {
00038                             (1701,17,6):     self.readCord1C, # record 1
00039                             (1801,18,5):     self.readCord1R, # record 2
00040                             (1901,19,7):     self.readCord1S, # record 3
00041                             (2001,20,9):     self.readCord2C, # record 4
00042                             (2101,21,8):     self.readCord2R, # record 5
00043                             (2201,22,10):    self.readCord2S, # record 6
00044                            #(14301,143,651): self.readCord3G, # record 7
00045                             (4501,45,1):     self.readGrid,   # record 17 - slow, but works
00046                             (5301,53,4):     self.readSEQGP,  # record 27 - not done
00047 
00048                             (1101,11, 66):    self.readFake,  # record 
00049                             (3901,39, 50):    self.readFake,  # record 
00050                             (2201,22, 10):    self.readFake,  # record 
00051                             (6101,61,388):    self.readFake,  # record 
00052                          }
00053         self.readRecordTable('GEOM1')
00054 
00055     def readTable_Geom1S(self):
00056         self.readTable_Geom1()
00057         #self.iTableMap = {
00058         #                 }
00059         #self.readRecordTable('GEOM1S')
00060 
00061     def readTable_Geom1N(self):
00062         self.iTableMap = {
00063                          }
00064         self.readRecordTable('GEOM1N')
00065 
00066     def readCord1C(self,data):
00067         """
00068         (1701,17,6) - the marker for Record 1
00069         """
00070         #print "reading CORD1C"
00071         n = 0
00072         nEntries = len(data)//24
00073         for i in xrange(nEntries):
00074             eData = data[n:n+24] # 6*4
00075             (cid,one,two,g1,g2,g3) = unpack(b'iiiiii',eData)
00076             dataIn = [cid,g1,g2,g3]
00077             coord = CORD1C(None,None,dataIn)
00078             self.addCoord(coord)
00079             n+=24
00080         ###
00081         data = data[n:]
00082 
00083     def readCord1R(self,data):
00084         """
00085         (1801,18,5) - the marker for Record 2
00086         """
00087         #print "reading CORD1R"
00088         n = 0
00089         nEntries = len(data)//24
00090         for i in xrange(nEntries):
00091             eData = data[n:n+24] # 6*4
00092             (cid,one,one,g1,g2,g3) = unpack(b'iiiiii',eData)
00093             dataIn = [cid,g1,g2,g3]
00094             coord = CORD1R(None,None,dataIn)
00095             self.addCoord(coord)
00096             n+=24
00097         ###
00098         data = data[n:]
00099 
00100     def readCord1S(self,data):
00101         """
00102         (1901,19,7) - the marker for Record 3
00103         """
00104         #print "reading CORD1S"
00105         n = 0
00106         nEntries = len(data)//24
00107         for i in xrange(nEntries):
00108             eData = data[n:n+24] # 6*4
00109             (cid,three,one,g1,g2,g3) = unpack(b'iiiiii',eData)
00110             dataIn = [cid,g1,g2,g3]
00111             coord = CORD1S(None,dataIn)
00112             self.addCoord(coord,allowOverwrites=True)
00113             n+=24
00114         ###
00115         data = data[n:]
00116 
00117     def readCord2C(self,data):
00118         """
00119         (2001,20,9) - the marker for Record 4
00120         """
00121         #print "reading CORD2C"
00122         n = 0
00123         nEntries = len(data)//52
00124         for i in xrange(nEntries):
00125             eData = data[n:n+52] # 13*4
00126             (cid,two,two,rid,a1,a2,a3,b1,b2,b3,c1,c2,c3) = unpack(b'iiiifffffffff',eData)
00127             #print "cid=%s two=%s two=%s rid=%s a1=%s a2=%s a3=%s b1=%s b2=%s b3=%s c1=%s c2=%s c3=%s" %(cid,two,two,rid,a1,a2,a3,b1,b2,b3,c1,c2,c3)
00128             dataIn = [cid,rid,a1,a2,a3,b1,b2,b3,c1,c2,c3]
00129             coord = CORD2C(None,dataIn)
00130             self.addCoord(coord,allowOverwrites=True)
00131             n+=52
00132         ###
00133         data = data[n:]
00134 
00135     def readCord2R(self,data):
00136         """
00137         (2101,21,8) - the marker for Record 5
00138         """
00139         #print "reading CORD2R"
00140         n = 0
00141         nEntries = len(data)//52
00142         for i in xrange(nEntries):
00143             eData = data[n:n+52] # 13*4
00144             (cid,one,two,rid,a1,a2,a3,b1,b2,b3,c1,c2,c3) = unpack(b'iiiifffffffff',eData)
00145             dataIn = [cid,rid,a1,a2,a3,b1,b2,b3,c1,c2,c3]
00146             #print "cid=%s one=%s two=%s rid=%s a1=%s a2=%s a3=%s b1=%s b2=%s b3=%s c1=%s c2=%s c3=%s" %(cid,one,two,rid,a1,a2,a3,b1,b2,b3,c1,c2,c3)
00147             coord = CORD2R(None,dataIn)
00148             self.addCoord(coord,allowOverwrites=True)
00149             n+=52
00150         ###
00151         data = data[n:]
00152 
00153     def readCord2S(self,data):
00154         """
00155         (2201,22,10) - the marker for Record 6
00156         """
00157         #print "reading CORD2S"
00158         n = 0
00159         nEntries = len(data)//52
00160         for i in xrange(nEntries):
00161             eData = data[n:n+52] # 13*4
00162             (cid,sixty5,eight,rid,a1,a2,a3,b1,b2,b3,c1,c2,c3) = unpack(b'iiiifffffffff',eData)
00163             #print "cid=%s sixty5=%s eight=%s rid=%s a1=%s a2=%s a3=%s b1=%s b2=%s b3=%s c1=%s c2=%s c3=%s" %(cid,sixty5,eight,rid,a1,a2,a3,b1,b2,b3,c1,c2,c3)
00164             dataIn = [cid,rid,a1,a2,a3,b1,b2,b3,c1,c2,c3]
00165             coord = CORD2S(dataIn)
00166             self.addCoord(coord,allowOverwrites=True)
00167             n+=52
00168         ###
00169         data = data[n:]
00170 
00171     def readCord3G(self,data):
00172         """
00173         (14301,143,651) - the marker for Record 7
00174         @todo isnt this a CORD3G, not a CORD3R ???
00175         """
00176         #print "reading CORD3G"
00177         n = 0
00178         nEntries = len(data)//16
00179         for i in xrange(nEntries):
00180             eData = data[n:n+16] # 4*4
00181             (cid,n1,n2,n3) = unpack(b'iiii',eData)
00182             dataIn = [cid,n1,n2,n3]
00183             coord = CORD3G(None,dataIn)
00184             self.addCoord(coord,allowOverwrites=True)
00185             n+=16
00186         ###
00187         data = data[n:]
00188 
00189     def readGrid(self,data):  # 21.8 sec, 18.9
00190         """(4501,45,1) - the marker for Record 17"""
00191         #print "reading GRID"
00192         n = 0
00193         nEntries = len(data)//32
00194         for i in xrange(nEntries):
00195             eData = data[n:n+32]
00196             out = unpack(b'iifffiii',eData)
00197 
00198             (nID,cp,x1,x2,x3,cd,ps,seid) = out
00199             if cd>=0 and nID<10000000:
00200                 node = GRID(None,out)
00201                 self.addNode(node)
00202             else:
00203                 self.log.debug("*nID=%s cp=%s x1=%-5.2f x2=%-5.2f x3=%-5.2f cd=%-2s ps=%s seid=%s" %(nID,cp,x1,x2,x3,cd,ps,seid))
00204             ###
00205             #print str(grid)[:-1]
00206             n+=32
00207         ###
00208         data = data[n:]
00209         #assert len(data)==0,'len(data)!=0   len(data)=%s' %(len(data))
00210         #print "len(data) = ",len(data)
00211 
00212 
00213     def readSEQGP(self,data):
00214         """(5301,53,4) - the marker for Record 27"""
00215         self.skippedCardsFile.write('skipping SEQGP in GEOM1\n')
00216 
 All Classes Namespaces Files Functions Variables