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