pyNastran
0.5.0
pyNastran BDF Reader/Writer, OP2 Parser, and GUI
|
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.aero import GUST 00029 from pyNastran.bdf.cards.tables import (TABLED1, TABLED2, TABLED3, TABLEM1, 00030 TABLEM2, TABLEM3, TABLEM4) 00031 00032 class DIT(object): 00033 def readTable_DIT(self): 00034 self.iTableMap = { 00035 (1005,10,174): self.readGust, # record 1 00036 (1105,11,133): self.readTableD1, # record 4 00037 (1205,12,134): self.readTableD2, # record 5 00038 (1305,13,140): self.readTableD3, # record 6 00039 00040 #(105,1,93): self.readTableM1, # record 9 00041 (205,2,94): self.readTableM2, # record 10 00042 (305,3,95): self.readTableM3, # record 11 00043 #(405,4,96): self.readTableM4, # record 12 00044 00045 (15, 21, 162): self.readFake, 00046 (56, 26, 303): self.readFake, 00047 (3105,31, 97): self.readFake, # record 13 - TABLES1 00048 } 00049 self.readRecordTable('DIT') 00050 00051 def readGust(self,data): 00052 """ 00053 GUST(1005,10,174) - the marker for Record 1 00054 """ 00055 #print "reading GUST" 00056 n = 0 00057 nEntries = len(data)//20 # 5*4 00058 for i in xrange(nEntries): 00059 eData = data[n:n+20] 00060 out = unpack('iifff',eData) 00061 (sid,dload,wg,x0,V) = out 00062 gust = GUST(None,out) 00063 self.addGUST(gust) 00064 n+=20 00065 ### 00066 data = data[n:] 00067 00068 #TABDMP1 00069 #TABLE3D 00070 00071 00072 def readTableD1(self,data): 00073 """ 00074 TABLED1(1105,11,133) - the marker for Record 4 00075 """ 00076 self.skippedCardsFile.write('skipping TABLED1 in DIT\n') 00077 return 00078 #print "reading TABLED1" 00079 func = TABLED1 00080 self.readTable1(func,data) 00081 00082 def readTable1(self,func,data): 00083 n = 0 00084 #nEntries = len(data)//40 # 10*4 00085 while len(data)>=40: 00086 eData = data[n:n+40] 00087 out = unpack('iiiiiiiiff',eData) 00088 (sid,codeX,codeY,a,a,a,a,a,x,y) = out 00089 dataIn = [sid,codeX,codeY] 00090 n+=40 00091 while 1: 00092 (xInt,yInt) = unpack('ii',data[n:n+8]) 00093 (x,y) = unpack('ff',data[n:n+8]) 00094 00095 n+=8 00096 if [xInt,yInt] != [-1,-1]: 00097 break 00098 else: 00099 dataIn+=[x,y] 00100 ### 00101 dataIn+=[x,y] 00102 table = func(None,out) 00103 self.addTable(table) 00104 ### 00105 data = data[n:] 00106 00107 def readTableD2(self,data): 00108 """ 00109 TABLED2(1205,12,134) - the marker for Record 5 00110 """ 00111 #print "reading TABLED2" 00112 func = TABLED2 00113 self.readTable2(func,data) 00114 00115 def readTable2(self,func,data): 00116 n = 0 00117 while len(data)>=40: 00118 eData = data[n:n+40] 00119 out = unpack('ifiiiiiiff',eData) 00120 (sid,x1,a,a,a,a,a,a,x,y) = out 00121 dataIn = [sid,x1] 00122 n+=40 00123 while 1: 00124 (xInt,yInt) = unpack('ii',data[n:n+8]) 00125 (x,y) = unpack('ff',data[n:n+8]) 00126 00127 n+=8 00128 if [xInt,yInt] != [-1,-1]: 00129 break 00130 else: 00131 dataIn+=[x,y] 00132 ### 00133 dataIn+=[x,y] 00134 table = func(None,out) 00135 self.addTable(table) 00136 ### 00137 data = data[n:] 00138 00139 def readTableD3(self,data): 00140 """ 00141 TABLED3(1305,13,140) - the marker for Record 6 00142 """ 00143 #print "reading TABLED3" 00144 func = TABLED3 00145 self.readTable3(func,data) 00146 00147 def readTable3(self,func,data): 00148 n = 0 00149 while len(data)>=40: 00150 eData = data[n:n+40] 00151 out = unpack('iffiiiiiff',eData) 00152 (sid,x1,x2,a,a,a,a,a,x,y) = out 00153 dataIn = [sid,x1,x2] 00154 n+=40 00155 while 1: 00156 (xInt,yInt) = unpack('ii',data[n:n+8]) 00157 (x,y) = unpack('ff',data[n:n+8]) 00158 00159 n+=8 00160 if [xInt,yInt] != [-1,-1]: 00161 break 00162 else: 00163 dataIn+=[x,y] 00164 ### 00165 dataIn+=[x,y] 00166 table = func(None,out) 00167 self.addTable(table) 00168 ### 00169 data = data[n:] 00170 00171 #TABLEDR 00172 00173 def readTableM1(self,data): 00174 """ 00175 TABLEM1(105,1,93) - the marker for Record 9 00176 """ 00177 self.skippedCardsFile.write('skipping TABLEM1 in DIT\n') 00178 return 00179 #print "reading TABLED1" 00180 func = TABLEM1 00181 self.readTable1(func,data) 00182 00183 def readTableM2(self,data): 00184 """ 00185 TABLEM2(205,2,94) - the marker for Record 10 00186 """ 00187 #print "reading TABLEM2" 00188 func = TABLEM2 00189 self.readTable2(func,data) 00190 00191 def readTableM3(self,data): 00192 """ 00193 TABLEM3(305,3,95) - the marker for Record 11 00194 """ 00195 #print "reading TABLED3" 00196 func = TABLEM3 00197 self.readTable3(func,data) 00198 00199 def readTableM4(self,data): 00200 """ 00201 TABLEM4(405,4,96) - the marker for Record 12 00202 """ 00203 #print "reading TABLED3" 00204 func = TABLEM4 00205 self.readTable4(func,data) 00206 00207 00208 #TABLES1 00209 #TABLEST 00210 #TABRND1 00211 #TABRNDG