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 #import copy 00027 00028 # pyNastran 00029 from pyNastran.op2.resultObjects.tableObject import (TableObject, 00030 ComplexTableObject) 00031 00032 class DisplacementObject(TableObject): # approachCode=1, thermal=0 00033 def __init__(self,dataCode,isSort1,iSubcase,dt=None): 00034 TableObject.__init__(self,dataCode,isSort1,iSubcase,dt) 00035 00036 def writeMatlab(self,iSubcase,f=None,isMagPhase=False): 00037 name = 'displacements' 00038 if self.nonlinearFactor is None: 00039 return self._writeMatlab(name,iSubcase,f) 00040 else: 00041 return self._writeMatlabTransient(name,iSubcase,f) 00042 00043 def writeF06(self,header,pageStamp,pageNum=1,f=None,isMagPhase=False): 00044 if self.nonlinearFactor is not None: 00045 return self.writeF06Transient(header,pageStamp,pageNum,f) 00046 words = [' D I S P L A C E M E N T V E C T O R\n', 00047 ' \n', 00048 ' POINT ID. TYPE T1 T2 T3 R1 R2 R3\n'] 00049 words += self.getTableMarker() 00050 return self._writeF06Block(words,header,pageStamp,pageNum,f) 00051 00052 def writeF06Transient(self,header,pageStamp,pageNum=1,f=None,isMagPhase=False): 00053 words = [' D I S P L A C E M E N T V E C T O R\n', 00054 ' \n', 00055 ' POINT ID. TYPE T1 T2 T3 R1 R2 R3\n'] 00056 words += self.getTableMarker() 00057 return self._writeF06TransientBlock(words,header,pageStamp,pageNum,f) 00058 00059 def __repr__(self): 00060 return '' 00061 if self.nonlinearFactor is not None: 00062 return self.__reprTransient__() 00063 00064 msg = ['---DISPLACEMENTS---\n'] 00065 msg.append(self.writeHeader()) 00066 00067 for nodeID,translation in sorted(self.translations.iteritems()): 00068 rotation = self.rotations[nodeID] 00069 gridType = self.gridTypes[nodeID] 00070 00071 (dx,dy,dz) = translation 00072 (rx,ry,rz) = rotation 00073 00074 msg2 = '%-10i %-8s ' %(nodeID,gridType) 00075 vals = [dx,dy,dz,rx,ry,rz] 00076 for val in vals: 00077 if abs(val)<1e-6: 00078 msg2 += '%10s ' %(0) 00079 else: 00080 msg2 += '%10.3e ' %(val) 00081 ### 00082 msg2 = '\n' 00083 msg.append(msg2) 00084 return ''.join(msg) 00085 00086 def __reprTransient__(self): 00087 msg = ['---TRANSIENT DISPLACEMENTS---\n'] 00088 msg.append(self.writeHeader()) 00089 00090 for dt,translations in sorted(self.translations.iteritems()): 00091 msg2 = '%s = %g\n' %(self.dataCode['name'],dt) 00092 for nodeID,translation in sorted(translations.iteritems()): 00093 rotation = self.rotations[dt][nodeID] 00094 gridType = self.gridTypes[nodeID] 00095 (dx,dy,dz) = translation 00096 (rx,ry,rz) = rotation 00097 00098 msg2 += '%-10i %8s ' %(nodeID,gridType) 00099 vals = [dx,dy,dz,rx,ry,rz] 00100 for val in vals: 00101 if abs(val)<1e-6: 00102 msg2 += '%10s ' %(0) 00103 else: 00104 msg2 += '%10.3e ' %(val) 00105 ### 00106 msg2 += '\n' 00107 msg.append(msg2) 00108 ### 00109 return ''.join(msg) 00110 00111 class ComplexDisplacementObject(ComplexTableObject): # approachCode=1, sortCode=0, thermal=0 00112 def __init__(self,dataCode,isSort1,iSubcase,dt=None): 00113 ComplexTableObject.__init__(self,dataCode,isSort1,iSubcase,dt) 00114 00115 def writeMatlab(self,iSubcase,f=None,isMagPhase=False): 00116 name = 'displacements' 00117 if self.nonlinearFactor is None: 00118 return self._writeMatlab(name,iSubcase,f,isMagPhase) 00119 else: 00120 return self._writeMatlabTransient(name,iSubcase,f,isMagPhase) 00121 00122 def writeF06(self,header,pageStamp,pageNum=1,f=None,isMagPhase=False): 00123 if self.nonlinearFactor is not None: 00124 return self.writeF06Transient(header,pageStamp,pageNum,f,isMagPhase) 00125 00126 words = [' C O M P L E X D I S P L A C E M E N T V E C T O R\n'] 00127 return self._writeF06Block(words,header,pageStamp,pageNum,f,isMagPhase) 00128 00129 def writeF06Transient(self,header,pageStamp,pageNum=1,f=None,isMagPhase=False): 00130 words = [' C O M P L E X D I S P L A C E M E N T V E C T O R\n'] 00131 return self._writeF06TransientBlock(words,header,pageStamp,pageNum,f,isMagPhase) 00132 00133 def __repr__(self): 00134 return self.writeF06(['','',''],'PAGE ',1)[0] 00135 00136 msg = '---COMPLEX DISPLACEMENTS---\n' 00137 #if self.dt is not None: 00138 # msg += '%s = %g\n' %(self.dataCode['name'],self.dt) 00139 headers = ['DxReal','DxImag','DyReal','DyImag','DzReal','DyImag','RxReal','RxImag','RyReal','RyImag','RzReal','RzImag'] 00140 msg += '%-10s ' %('nodeID') 00141 for header in headers: 00142 msg += '%10s ' %(header) 00143 msg += '\n' 00144 00145 for freq,translations in sorted(self.translations.iteritems()): 00146 msg += '%s = %g\n' %(self.dataCode['name'],freq) 00147 00148 for nodeID,translation in sorted(translations.iteritems()): 00149 rotation = self.rotations[freq][nodeID] 00150 00151 msg += '%-10i ' %(nodeID) 00152 vals = translation+rotation 00153 for val in vals: 00154 if abs(val)<1e-6: 00155 msg += '%10s ' %(0) 00156 else: 00157 msg += '%10.3e ' %(val) 00158 ### 00159 msg += '\n' 00160 ### 00161 return msg