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 from struct import pack 00026 from pyNastran.op2.writer.oesWriter import Oes1Writer 00027 from pyNastran.op2.writer.ougWriter import Ougv1Writer 00028 00029 class Op2Writer(Ougv1Writer,Oes1Writer): 00030 self.hollerith = pack('i',584) # assumes a 128 character string 00031 def pack(self,format,*vals): 00032 return [str(val) for val in vals] 00033 00034 def writeStart(self): 00035 self.writeMarkers([3,7]) 00036 self.writeStringBlock('NASTRAN FORT TAPE ID CODE - ',28) 00037 self.writeMarkers([2,-1]) 00038 00039 def writeOp2(self,op2Name): 00040 op2 = open(op2Name,'wb') 00041 self.writeStart() 00042 #self.writeGEOM1() 00043 #self.writeGEOM2() 00044 #self.writeGEOM3() 00045 #self.writeGEOM4() 00046 00047 #self.writeEPT() 00048 #self.writeMPTS() 00049 00050 #self.writeOQG1() # spc forces 00051 00052 #self.writeOGP() 00053 self.writeOUGV1() # displacements/temps/heatFlux 00054 #self.writeOGF1() 00055 self.writeOES1() # stress 00056 00057 def printHeader(word,nChars): 00058 self.deviceCode = 1 # print the OP2... 00059 00060 self.writeStringBlock(word,nChars) 00061 00062 msg += writeMarkers([-1,7]) 00063 out = [101, 0, 4136, 0, 0, 0, 1] ## @todo what this is - DMAP -> "no def or month,year,one,one"...huh??? 00064 msg += pack('iiiiiii',*out) 00065 00066 msg += writeMarkers([-2,1,0]) 00067 00068 # approachCode=1, tableCode=1 00069 self.iTable = -3 00070 00071 def writeStringBlock(self,word,nChars): 00072 """ 00073 'OUG' - 1 word = 4 characters 00074 'OUGV' - 1 word = 4 characters 00075 'OUGV1' - 2 words = 8 characters 00076 '12345678' - 2 words = 8 characters 00077 nWords = round(ceil(len(word)/4.)) 00078 nChars = nWords*4 != len(word) 00079 just set nChars and dont overthink it too much 00080 """ 00081 m = self.writeMarkers([1]) 00082 #word = self.readStringBlock() 00083 ## creating a %Xs - where x is the number of 00084 ## words*4,left justifying it, and setting the value 00085 value = '%%-%ss' %(nChars) %(word) 00086 00087 out = pack('c'*nChars,value) 00088 out = '' 00089 return m+out+m 00090 00091 def packTitle(iSubcase): 00092 Title = self.Title 00093 subtitle,label = self.iSubcaseNameMap[iSubcase] 00094 titleSubtitleLabel = '%128s%128s%128s' %(Title,subtitle,label) 00095 msg = pack('c'*384,list(titleSubtitleLabel)) + self.hollerith 00096 return msg 00097 00098 def writeMarkers(markers): 00099 """ 00100 takes -5,1,0 -> [4,5,4, 4,1,4, 4,0,4] 00101 and puts it into binary 00102 """ 00103 out = [] 00104 for marker in markers: 00105 out += [4,marker,4] 00106 n = len(out) 00107 return pack('i'*n,*out) 00108 00109 def combineApproachDeviceCodes(self,approachCode): 00110 aCode = approachCode*10 + self.deviceCode 00111 return aCode 00112 00113 def combineTableSortCodes(self,tableCode,sortCode): 00114 tCode = sortCode*1000+tableCode 00115 return tCode 00116 00117 def aCode_tCode(approachCode,tableCode,sortCode): 00118 aCode = self.combineApproachDeviceCodes(approachCode) 00119 tCode = self.combineTableDeviceCodes(tableCode,sortCode) 00120 return (aCode,tCode)