pyNastran  0.5.0
pyNastran BDF Reader/Writer, OP2 Parser, and GUI
ept.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 
00026 from __future__ import division, print_function
00027 import sys
00028 from struct import unpack
00029 
00030 from pyNastran.bdf.bdf import (NSM,PBAR,PBARL,PBEAM,
00031                                             PROD,PSHELL,PSHEAR,
00032                                             PCOMP,PSOLID,
00033                                             PVISC,PELAS,PMASS,
00034                                             PTUBE,PGAP)
00035 # PCOMPG,PBUSH1D,PBEAML,PBEAM3,PBUSH,
00036 
00037 class EPT(object):
00038 
00039     def readTable_EPT(self):
00040         self.tableName = 'EPT'
00041         self.bigProperties = {}
00042         self.iTableMap = {
00043                         #(3201,32,55):    self.readNSM,     # record 2  - needs an object holder (e.g. self.elements/self.properties)
00044                          (52,20,181):     self.readPBAR,    # record 11 - buggy
00045                          (9102,91,52):    self.readPBARL,   # record 12 - almost there...
00046                         #(2706,27,287):   self.readPCOMP,   # record 22 - buggy
00047                          (302,  3, 46):   self.readPELAS,   # record 39
00048                          (2102,21,121):   self.readPGAP,    # record 42
00049                          (902,  9, 29):   self.readPROD,    # record 49
00050                          (1002,10, 42):   self.readPSHEAR,  # record 50
00051                          (2402,24,281):   self.readPSOLID,  # record 51
00052                          (2302,23,283):   self.readPSHELL,  # record 52
00053                          (1602,16, 30):   self.readPTUBE,   # record 56
00054                          
00055                         #(5402,54,262):   self.readPBEAM,   # record 14 - not done
00056                         #(9202, 92,  53): self.readPBEAML,  # record 15 - not done
00057                          (2502, 25, 248): self.readPBEND,   # record 16 - not done
00058                          (3101, 31, 219): self.readPBUSH1D, # record 20 - not done
00059                         #(152,  19, 147): self.readPCONEAX, # record 24 - not done
00060                         #(11001,110,411): self.readPCONV,   # record 25 - not done
00061                          (202,   2,  45): self.readPDAMP,   # record 27 - not done
00062                         #(2802, 28, 236): self.readPHBDY,   # record 43 - not done
00063                          (402,   4,  44): self.readPMASS,   # record 48
00064                          (1802, 18,  31): self.readPVISC,   # record 59
00065                         #(10201,102,400): self.readPVAL,    # record 58 - not done
00066                         #(2606, 26, 289): self.readVIEW,    # record 62 - not done
00067                         #(1402, 14, 37):   self.readFake,    # record 
00068 
00069                          }
00070         self.readRecordTable('EPT')
00071 
00072     def addOp2Property(self,prop):
00073         self.addProperty(prop,allowOverwrites=True)
00074 
00075 # HGSUPPR
00076 
00077     def readNSM(self,data):
00078         """
00079         NSM(3201,32,55) - the marker for Record 2
00080         @todo this isnt a property...
00081         """
00082         #print "reading NSM"
00083         return
00084         while len(data)>=16: # 4*4
00085             eData = data[:16]
00086             data  = data[16:]
00087             out = unpack(b'i4sif',eData)
00088             (sid,propSet,ID,value) = out
00089             #print "sid=%s propSet=%s ID=%s value=%s" %(sid,propSet,ID,value)
00090             prop = NSM(None,None,[sid,propSet,ID,value])
00091             #self.addOp2Property(prop)
00092         ###
00093 
00094 
00095 # NSM1
00096 # NSML1
00097 # NSMADD
00098 # NSML
00099 # NSML1
00100 # PAABSF
00101 # PACABS
00102 # PACBAR
00103 
00104     def readPBAR(self,data):
00105         """
00106         PBAR(52,20,181) - the marker for Record 11
00107         @warning this makes a funny property...
00108         """
00109         #print "reading PBAR"
00110         while len(data)>=76: # 19*4
00111             eData = data[:76]
00112             data  = data[76:]
00113             out = unpack(b'2i17f',eData)
00114             #print "len(out) = ",len(out)
00115             #print out
00116             (pid,mid,a,I1,I2,J,nsm,fe,c1,c2,d1,d2,e1,e2,f1,f2,k1,k2,I12) = out
00117             prop = PBAR(None,out)
00118             self.addOp2Property(prop)
00119         ###
00120 
00121 
00122     def readPBARL(self,data):
00123         """
00124         PBARL(9102,91,52) - the marker for Record 12
00125         """
00126         validTypes = {
00127             "ROD"   : 1, 
00128             "TUBE"  : 2,
00129             "I"     : 6,
00130             "CHAN"  : 4,
00131             "T"     : 4,
00132             "BOX"   : 4,
00133             "BAR"   : 2,
00134             "CROSS" : 4,
00135             "H"     : 4,
00136             "T1"    : 4,
00137             "I1"    : 4,
00138             "CHAN1" : 4,
00139             "Z"     : 4,
00140             "CHAN2" : 4,
00141             "T2"    : 4,
00142             "BOX1"  : 6,
00143             "HEXA"  : 3,
00144             "HAT"   : 4,
00145             "HAT1"  : 5,
00146             "DBOX"  : 10,  # was 12
00147             } # for GROUP="MSCBML0"
00148 
00149         #print "reading PBARL"
00150         while len(data)>=28: # 7*4 - ROD - shortest entry...could be buggy... ## @todo fix this
00151             eData = data[:28]
00152             data  = data[28:]
00153             out = unpack(b'2i8s8sf',eData)
00154             (pid,mid,group,Type,value) = out
00155             Type = Type.strip()
00156             dataIn = [pid,mid,group,Type,value]
00157             #print "pid=%s mid=%s group=|%s| Type=|%s| value=%s" %(pid,mid,group,Type,value)
00158             expectedLength = validTypes[Type]
00159             iFormat = 'f'*expectedLength
00160             iFormat = bytes(iFormat)
00161             dataIn += list(unpack(iFormat,data[:expectedLength*4]))
00162             
00163             data = data[expectedLength*4+4:]  ## @todo why do i need the +4???
00164             
00165             #print "len(out) = ",len(out)
00166             #print "PBARL = ",dataIn
00167             prop = PBARL(None,dataIn)
00168             self.addOp2Property(prop)
00169             #print self.printSection(20)
00170         ###
00171 
00172 # PBCOMP
00173 
00174     def readPBEAM(self,data):
00175         """
00176         PBEAM(5402,54,262) - the marker for Record 14
00177         @todo add object
00178         """
00179         #print "reading PBEAM"
00180         while len(data)>=1072: # 44+12*84+20
00181             eData = data[:20]
00182             data  = data[20:]
00183             dataIn = list(unpack(b'4if',eData))
00184             #print "len(out) = ",len(out)
00185             #print out
00186             (pid,mid,nsegs,ccf,x) = dataIn
00187 
00188             for i in xrange(12):
00189                 eData = data[64:]
00190                 data  = data[:64]
00191                 pack = unpack(b'16f',eData)
00192                 (so,xxb,a,i1,i2,i12,j,nsm,c1,c2,d1,d2,e1,e2,f1,f2) = pack
00193                 dataIn.append(pack)
00194             
00195             eData = data[:44]
00196             data  = data[44:]
00197 
00198             dataIn = list(unpack(b'11f',eData))
00199             #(k1,k2,s1,s2,nsia,nsib,cwa,cwb,m1a,m2a,m1b,m2b,n1a,n2a,n1b,n2b) = pack
00200             
00201             prop = PBEAM(None,dataIn)
00202             self.addOp2Property(prop)
00203             #sys.exit('ept-PBEAM')
00204         ###
00205 
00206 # PBEAML
00207 
00208     def readPBEND(self,data):
00209         self.skippedCardsFile.write('skipping PBEND in EPT\n')
00210 
00211 # PBMSECT
00212 # PBRSECT
00213 
00214     def readPBUSH(self,data):
00215         self.skippedCardsFile.write('skipping PBUSH in EPT\n')
00216 
00217     def readPBUSH1D(self,data):
00218         self.skippedCardsFile.write('skipping PBUSH1D in EPT\n')
00219 
00220     def readPBUSHT(self,data):
00221         self.skippedCardsFile.write('skipping PBUSHT in EPT\n')
00222 
00223     def readPCOMP(self,data):
00224         """
00225         PCOMP(2706,27,287) - the marker for Record 22
00226         """
00227         #print "reading PCOMP"
00228         while len(data)>=32: # 8*4 - dynamic
00229             #print "len(data) = ",len(data)
00230             #print self.printBlock(data[0:200])
00231             isSymmetrical = 'NO'
00232             eData = data[:32]
00233             data  = data[32:]
00234             out = unpack(b'2i3fi2f',eData)
00235             (pid,nLayers,z0,nsm,sb,ft,Tref,ge,) = out
00236             
00237             eData = data[:16*(nLayers)]
00238             data  = data[16*(nLayers):]
00239             
00240             Mid=[]; T=[]; Theta=[]; Sout=[]
00241             if nLayers<0:
00242                 isSymmetrical = 'YES'
00243                 nLayers = abs(nLayers)
00244             #print "nLayers = ",nLayers
00245             assert 0<nLayers<100,'pid=%s nLayers=%s z0=%s nms=%s sb=%s ft=%s Tref=%s ge=%s' %(pid,nLayers,z0,nsm,sb,ft,Tref,ge)
00246 
00247             for n in xrange(nLayers):
00248                 #print "len(eData) = ",len(eData)
00249                 (mid,t,theta,sout) = unpack(b'i2fi',eData[0:16])
00250                 Mid.append(mid)
00251                 T.append(t)
00252                 Theta.append(theta)
00253                 Sout.append(sout)
00254                 eData = eData[16:]
00255             ###
00256             
00257             dataIn = [pid,z0,nsm,sb,ft,Tref,ge,isSymmetrical,Mid,T,Theta,Sout]
00258             #print "PCOMP = %s" %(dataIn)
00259             prop = PCOMP(None,dataIn)
00260             self.addOp2Property(prop)
00261         ###
00262 
00263 # PCOMPA
00264 # PCONEAX
00265 # PCONV
00266 # PCONVM
00267 
00268     def readPDAMP(self,data):
00269         self.skippedCardsFile.write('skipping PDAMP\n')
00270 
00271 # PDAMPT
00272 # PDAMP5
00273 # PDUM1
00274 # PDUM2
00275 # PDUM3
00276 # PDUM4
00277 # PDUM5
00278 # PDUM6
00279 # PDUM7
00280 # PDUM8
00281 # PDUM9
00282 
00283     def readPELAS(self,data):
00284         """PELAS(302,3,46) - the marker for Record 39"""
00285         #print "reading PELAS"
00286         while len(data)>=16: # 4*4
00287             eData = data[:16]
00288             data  = data[16:]
00289             out = unpack(b'i3f',eData)
00290             #(pid,k,ge,s) = out
00291             prop = PELAS(data=out)
00292             self.addOp2Property(prop)
00293         ###
00294 
00295 # PFAST
00296 # PELAST
00297 
00298     def readPGAP(self,data):
00299         """
00300         PGAP(3201,32,55) - the marker for Record 42
00301         """
00302         #print "reading PGAP"
00303         while len(data)>=44: # 11*4
00304             eData = data[:44]
00305             data  = data[44:]
00306             out = unpack(b'i10f',eData)
00307             #(pid,u0,f0,ka,kb,kt,mu1,mu2,tmax,mar,trmin) = out
00308             prop = PGAP(None,out)
00309             self.addOp2Property(prop)
00310         ###
00311 
00312 # PHBDY
00313 # PINTC
00314 # PINTS
00315 # PLPLANE
00316 # PLSOLID
00317 
00318     def readPMASS(self,data):
00319         """
00320         PMASS(402,4,44) - the marker for Record 48
00321         """
00322         n = 0
00323         nEntries = len(data)//8  # 2*4
00324         for i in xrange(nEntries):
00325             eData = data[n:n+8]
00326             out = unpack(b'ii',eData)
00327             #out = (pid,mass)
00328             prop = PMASS(data=out)
00329             self.addOp2Property(prop)
00330             n+=8
00331         ###
00332         data = data[n:]
00333 
00334     def readPROD(self,data):
00335         """
00336         PROD(902,9,29) - the marker for Record 49
00337         """
00338         #print "reading PROD"
00339         while len(data)>=24: # 6*4
00340             eData = data[:24]
00341             data  = data[24:]
00342             out = unpack(b'2i4f',eData)
00343             (pid,mid,a,j,c,nsm) = out
00344             prop = PROD(None,out)
00345             self.addOp2Property(prop)
00346         ###
00347 
00348     def readPSHEAR(self,data):
00349         """
00350         PSHEAR(1002,10,42) - the marker for Record 50
00351         """
00352         #print "reading PSHEAR"
00353         while len(data)>=24: # 6*4
00354             eData = data[:24]
00355             data  = data[24:]
00356             out = unpack(b'2i4f',eData)
00357             (pid,mid,t,nsm,f1,f2) = out
00358             prop = PSHEAR(data=out)
00359             self.addOp2Property(prop)
00360         ###
00361 
00362     def readPSHELL(self,data):
00363         """
00364         PSHELL(2302,23,283) - the marker for Record 51
00365         """
00366         #print "reading PSHELL"
00367         while len(data)>=44: # 11*4
00368             eData = data[:44]
00369             data  = data[44:]
00370             out = unpack(b'iifififfffi',eData)
00371             (pid,mid1,t,mid2,bk,mid3,ts,nsm,z1,z2,mid4) = out
00372             prop = PSHELL(None,out)
00373 
00374             if max(pid,mid1,mid2,mid3,mid4)>1e8:
00375                 #print "PSHELL = ",out
00376                 self.bigProperties[pid] = prop
00377             else:
00378                 self.addOp2Property(prop)
00379             ###
00380         ###
00381 
00382     def readPSOLID(self,data):
00383         """
00384         PSOLID(2402,24,281) - the marker for Record 52
00385         """
00386         #print "reading PSOLID"
00387         while len(data)>=28: # 7*4
00388             eData = data[:28]
00389             data  = data[28:]
00390             (pid,mid,cid,inp,stress,isop,fctn) = unpack(b'6i4s',eData)
00391             dataIn = [pid,mid,cid,inp,stress,isop,fctn]
00392             prop = PSOLID(None,dataIn)
00393             self.addOp2Property(prop)
00394         ###
00395 
00396 # PSOLIDL
00397 # PTRIA6
00398 # PTSHELL
00399 
00400     def readPTUBE(self,data):
00401         """
00402         PTUBE(1602,16,30) - the marker for Record 56
00403         @todo OD2 only exists for heat transfer...how do i know if there's heat transfer at this point...
00404         @todo I could store all the tubes and add them later, but what about themal/non-thermal subcases
00405         @warning assuming OD2 is not written (only done for thermal)
00406         """
00407         #print "reading PTUBE"
00408         while len(data)>=20: # 5*4
00409             eData = data[:20]
00410             data  = data[20:] # or 24
00411             (pid,mid,OD,t,nsm) = unpack(b'2i3f',eData)
00412             dataIn = [pid,mid,OD,t,nsm]
00413             prop = PTUBE(None,dataIn)
00414             self.addOp2Property(prop)
00415         ###
00416 
00417 # PSET
00418 # PVAL
00419 
00420     def readPVISC(self,data):
00421         """PVISC(1802,18,31) - the marker for Record 39"""
00422         #print "reading PVISC"
00423         while len(data)>=12: # 3*4
00424             eData = data[:12]
00425             data  = data[12:]
00426             out = unpack(b'i2f',eData)
00427             #(pid,ce,cr) = out
00428             prop = PVISC(data=out)
00429             self.addOp2Property(prop)
00430         ###
00431 
00432 # PWELD
00433 # PWSEAM
00434 # PVIEW
00435 # PVIEW3D
 All Classes Namespaces Files Functions Variables