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 # pylint: disable=C0103,R0902,R0904,R0914 00026 00027 from __future__ import division, print_function 00028 #import sys 00029 00030 from pyNastran.bdf.fieldWriter import set_blank_if_default 00031 from pyNastran.bdf.cards.baseCard import BaseCard 00032 from pyNastran.general.general import ListPrint 00033 00034 class Table(BaseCard): 00035 type = 'TABLE??' 00036 def __init__(self,card,data): 00037 pass 00038 00039 def mapAxis(self,axis): 00040 if axis==0: 00041 axisType = 'LINEAR' 00042 else: 00043 raise ValueError('axis=|%s|' %(axis)) 00044 return axisType 00045 00046 def parseFields(self, fields, nRepeated, isData=False): 00047 self.table = TableObj(fields, nRepeated, isData) 00048 00049 class TableObj(object): 00050 def __init__(self, fields, nRepeated, isData=False): 00051 self.table = [] 00052 fields = self.cleanupFields(fields, isData) 00053 00054 nFields = len(fields) 00055 00056 if not isData: 00057 if nFields%nRepeated!=0: 00058 self.crashFields(fields, nRepeated, nFields) 00059 if nFields%nRepeated!=0: 00060 msg = 'invalid table length nRepeat=%s fields=%s' %(nRepeated, ListPrint(fields)) 00061 raise RuntimeError(msg) 00062 00063 i=0 00064 while i<nFields: 00065 pack = [] 00066 for j in xrange(nRepeated): 00067 pack.append(fields[i+j]) 00068 i+=nRepeated 00069 self.table.append(pack) 00070 ### 00071 00072 def crashFields(self,fields, nRepeated, nFields): 00073 try: 00074 msg = '' 00075 #k = 0 00076 for i in xrange(nFields): 00077 for j in xrange(nRepeated): 00078 try: 00079 msg += '%-8g ' %(fields[i*nRepeated+j]) 00080 except TypeError: 00081 msg += '*%-8s ' %(fields[i*nRepeated+j]) 00082 except IndexError: 00083 msg += 'IndexError' 00084 #k+=1 00085 ### 00086 msg += '\n' 00087 ### 00088 except: 00089 print(fields) 00090 print(msg) 00091 #assert nFields%nRepeated==0,msg 00092 raise 00093 ### 00094 ### 00095 00096 def cleanupFields(self, fields, isData=False): 00097 fields2 = [] # remove extra ENDTs 00098 foundENDT = False 00099 for field in fields: 00100 if isinstance(field, str) and 'ENDT' in field.upper(): 00101 foundENDT = True 00102 else: 00103 fields2.append(field) 00104 00105 if not isData: 00106 assert foundENDT==True, fields 00107 return fields2 00108 00109 def fields(self): 00110 fields = [] 00111 for pack in self.table: 00112 fields += pack 00113 return fields 00114 00115 class TABLED1(Table): 00116 type = 'TABLED1' 00117 def __init__(self, card=None, data=None): 00118 Table.__init__(self,card,data) 00119 if card: 00120 self.tid = card.field(1) 00121 self.xaxis = card.field(2, 'LINEAR') 00122 self.yaxis = card.field(3, 'LINEAR') 00123 fields = card.fields(9) 00124 isData = False 00125 else: 00126 self.tid = data[0] 00127 self.xaxis = self.mapAxis(data[1]) 00128 self.yaxis = self.mapAxis(data[2]) 00129 fields = data[3:] 00130 isData = True 00131 assert self.xaxis in ['LINEAR','LOG'], 'xaxis=|%s|' %(self.xaxis) 00132 assert self.yaxis in ['LINEAR','LOG'], 'yaxis=|%s|' %(self.yaxis) 00133 self.parseFields(fields,nRepeated=2,isData=isData) 00134 00135 def rawFields(self): 00136 fields = ['TABLED1', self.tid, self.xaxis, self.yaxis, None, None, None, None, None]+self.table.fields()+['ENDT'] 00137 return fields 00138 00139 def reprFields(self): 00140 #xaxis = set_blank_if_default(self.xaxis,'LINEAR') 00141 #yaxis = set_blank_if_default(self.yaxis,'LINEAR') 00142 return self.rawFields() 00143 #fields = ['TABLED1',self.tid,self.xaxis,self.yaxis,None,None,None,None,None]+self.table.fields()+['ENDT'] 00144 #return fields 00145 00146 class TABLED2(Table): 00147 type = 'TABLED2' 00148 def __init__(self, card=None, data=None): 00149 Table.__init__(self, card, data) 00150 if card: 00151 self.tid = card.field(1) 00152 self.x1 = card.field(2) 00153 fields = card.fields(9) 00154 isData = False 00155 else: 00156 self.tid = data[0] 00157 self.x1 = data[1] 00158 fields = data[2:] 00159 isData = True 00160 self.parseFields(fields, nRepeated=2, isData=isData) 00161 00162 def rawFields(self): 00163 fields = ['TABLED2',self.tid,self.x1,None,None,None,None,None,None]+self.table.fields()+['ENDT'] 00164 return fields 00165 00166 def reprFields(self): 00167 return self.rawFields() 00168 00169 class TABLED3(Table): 00170 type = 'TABLED3' 00171 def __init__(self, card=None, data=None): 00172 Table.__init__(self, card, data) 00173 if card: 00174 self.tid = card.field(1) 00175 self.x1 = card.field(2) 00176 self.x2 = card.field(3) 00177 fields = card.fields(9) 00178 isData = False 00179 else: 00180 self.tid = data[0] 00181 self.x1 = data[1] 00182 self.x2 = data[2] 00183 fields = data[3:] 00184 isData = True 00185 self.parseFields(fields, nRepeated=2, isData=isData) 00186 00187 def rawFields(self): 00188 fields = ['TABLED3',self.tid,self.x1,self.x2,None,None,None,None,None]+self.table.fields()+['ENDT'] 00189 return fields 00190 00191 def reprFields(self): 00192 return self.rawFields() 00193 00194 class TABLEM1(Table): 00195 type = 'TABLEM1' 00196 def __init__(self, card=None, data=None): 00197 Table.__init__(self, card, data) 00198 if card: 00199 self.tid = card.field(1) 00200 fields = card.fields(9) 00201 isData = False 00202 else: 00203 self.tid = data[0] 00204 fields = data[1:] 00205 isData = True 00206 self.parseFields(fields, nRepeated=2, isData=isData) 00207 00208 def rawFields(self): 00209 fields = ['TABLEM1',self.tid,None,None,None,None,None,None,None]+self.table.fields()+['ENDT'] 00210 return fields 00211 00212 class TABLEM2(Table): 00213 type = 'TABLEM2' 00214 def __init__(self, card=None, data=None): 00215 Table.__init__(self, card, data) 00216 if card: 00217 self.tid = card.field(1) 00218 self.x1 = card.field(2) 00219 fields = card.fields(9) 00220 isData = False 00221 else: 00222 self.tid = data[0] 00223 self.x1 = data[1] 00224 fields = data[2:] 00225 isData = True 00226 self.parseFields(fields, nRepeated=2, isData=isData) 00227 00228 def rawFields(self): 00229 fields = ['TABLEM2',self.tid,self.x1,None,None,None,None,None,None]+self.table.fields()+['ENDT'] 00230 return fields 00231 00232 def reprFields(self): 00233 return self.rawFields() 00234 00235 00236 class TABLEM3(Table): 00237 type = 'TABLEM3' 00238 def __init__(self, card=None, data=None): 00239 Table.__init__(self, card, data) 00240 if card: 00241 self.tid = card.field(1) 00242 self.x1 = card.field(2) 00243 self.x2 = card.field(3) 00244 fields = card.fields(9) 00245 isData = False 00246 else: 00247 self.tid = data[0] 00248 self.x1 = data[1] 00249 self.x2 = data[2] 00250 fields = data[3:] 00251 isData = True 00252 self.parseFields(fields, nRepeated=2, isData=isData) 00253 00254 def rawFields(self): 00255 fields = ['TABLEM3',self.tid,self.x1,self.x2,None,None,None,None,None]+self.table.fields()+['ENDT'] 00256 return fields 00257 00258 def reprFields(self): 00259 return self.rawFields() 00260 00261 class TABLEM4(Table): 00262 type = 'TABLEM4' 00263 def __init__(self, card=None, data=None): 00264 Table.__init__(self, card, data) 00265 if card: 00266 self.tid = card.field(1) 00267 self.x1 = card.field(2) 00268 self.x2 = card.field(3) 00269 self.x3 = card.field(4) 00270 self.x4 = card.field(5) 00271 fields = card.fields(9) 00272 isData = False 00273 else: 00274 self.tid = data[0] 00275 self.x1 = data[1] 00276 self.x2 = data[2] 00277 self.x3 = data[3] 00278 self.x4 = data[4] 00279 fields = data[3:] 00280 isData = True 00281 self.parseFields(fields, nRepeated=1, isData=isData) 00282 00283 def rawFields(self): 00284 fields = ['TABLEM4',self.tid,self.x1,self.x2,self.x3,self.x4,None,None,None]+self.table.fields()+['ENDT'] 00285 return fields 00286 00287 def reprFields(self): 00288 return self.rawFields() 00289 00290 class TABLES1(Table): 00291 type = 'TABLES1' 00292 def __init__(self, card=None, data=None): 00293 Table.__init__(self, card, data) 00294 if card: 00295 self.tid = card.field(1) 00296 fields = card.fields(9) 00297 isData = False 00298 else: 00299 self.tid = data[0] 00300 fields = data[1:] 00301 isData = True 00302 self.parseFields(fields, nRepeated=2, isData=isData) 00303 00304 def rawFields(self): 00305 fields = ['TABLES1',self.tid,None,None,None,None,None,None,None]+self.table.fields()+['ENDT'] 00306 return fields 00307 00308 def reprFields(self): 00309 return self.rawFields() 00310 00311 class TABLEST(Table): 00312 type = 'TABLEST' 00313 def __init__(self, card=None, data=None): 00314 Table.__init__(self, card, data) 00315 if card: 00316 self.tid = card.field(1) 00317 fields = card.fields(9) 00318 isData = False 00319 else: 00320 self.tid = data[0] 00321 fields = data[1:] 00322 isData = True 00323 self.parseFields(fields, nRepeated=2, isData=isData) 00324 00325 def rawFields(self): 00326 fields = ['TABLEST',self.tid,None,None,None,None,None,None,None]+self.table.fields()+['ENDT'] 00327 return fields 00328 00329 def reprFields(self): 00330 return self.rawFields() 00331 00332 class RandomTable(BaseCard): 00333 type = 'TABLE??' 00334 def __init__(self,card,data): 00335 pass 00336 00337 class TABRND1(RandomTable): 00338 type = 'TABRND1' 00339 def __init__(self, card=None, data=None): 00340 RandomTable.__init__(self, card, data) 00341 if card: 00342 self.tid = card.field(1) 00343 self.xaxis = card.field(2,'LINEAR') 00344 self.yaxis = card.field(3,'LINEAR') 00345 fields = card.fields(9) 00346 isData = False 00347 else: 00348 self.tid = data[0] 00349 self.xaxis = self.mapAxis(data[1]) 00350 self.yaxis = self.mapAxis(data[2]) 00351 fields = data[3:] 00352 isData = True 00353 assert self.xaxis in ['LINEAR', 'LOG'], 'xaxis=|%s|' % (self.xaxis) 00354 assert self.yaxis in ['LINEAR', 'LOG'], 'yaxis=|%s|' % (self.yaxis) 00355 self.parseFields(fields, nRepeated=2, isData=isData) 00356 00357 def parseFields(self,fields, nRepeated, isData=False): 00358 self.table = TableObj(fields, nRepeated, isData) 00359 00360 def mapAxis(self, axis): 00361 if axis == 0: 00362 axisType = 'LINEAR' 00363 else: 00364 raise ValueError('axis=|%s|' %(axis)) 00365 return axisType 00366 00367 def rawFields(self): 00368 fields = ['TABRND1', self.tid, self.xaxis, self.yaxis, None, None, 00369 None, None, None]+self.table.fields()+['ENDT'] 00370 return fields 00371 00372 def reprFields(self): 00373 xaxis = set_blank_if_default(self.xaxis, 'LINEAR') 00374 yaxis = set_blank_if_default(self.yaxis, 'LINEAR') 00375 fields = ['TABRND1',self.tid,xaxis,yaxis,None,None,None,None,None]+self.table.fields()+['ENDT'] 00376 return fields 00377 00378 class TABRNDG(RandomTable): 00379 """ 00380 Gust Power Spectral Density 00381 Defines the power spectral density (PSD) of a gust for aeroelastic response analysis. 00382 """ 00383 type = 'TABRNDG' 00384 def __init__(self, card=None, data=None): 00385 RandomTable.__init__(self, card, data) 00386 if card: 00387 ## Table identification number. (Integer >0) 00388 self.tid = card.field(1) 00389 ## PSD Type: 1. von Karman; 2. Dryden 00390 self.Type = card.field(2) 00391 ## Scale of turbulence divided by velocity (units of time; Real) 00392 self.LU = card.field(3) 00393 ## Root-mean-square gust velocity. (Real) 00394 self.WG = card.field(4) 00395 assert self.Type in [1,2],'Type must be 1 or 2. Type=%s' %(self.Type) 00396 else: 00397 raise NotImplementedError() 00398 00399 def rawFields(self): 00400 fields = ['TABRNDG', self.tid, self.Type, self.LU, self.WG] 00401 return fields 00402 00403 def reprFields(self): 00404 return self.rawFields() 00405 00406 class TIC(Table): 00407 """Transient Initial Condition""" 00408 type = 'TIC' 00409 def __init__(self, card=None, data=None): 00410 """ 00411 Defines values for the initial conditions of variables used in 00412 structural transient analysis. Both displacement and velocity values may 00413 be specified at independent degrees-of-freedom. This entry may not be 00414 used for heat transfer analysis. 00415 """ 00416 Table.__init__(self, card, data) 00417 if card: 00418 self.sid = card.field(1) 00419 self.G = card.field(2) 00420 self.C = card.field(3) 00421 self.U0 = card.field(4) 00422 self.V0 = card.field(5) 00423 else: 00424 self.sid = data[0] 00425 self.G = data[1] 00426 self.C = data[2] 00427 self.U0 = data[3] 00428 self.V0 = data[4] 00429 ### 00430 00431 def rawFields(self): 00432 fields = ['TIC', self.sid, self.G, self.C, self.U0, self.V0] 00433 return fields 00434 00435 def reprFields(self): 00436 return self.rawFields()