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 00026 from __future__ import division, print_function 00027 import sys 00028 00029 from ..real.oes_objects import stressObject,strainObject #,array 00030 #from oes_complexObjects import complexStressObject,complexStrainObject 00031 00032 complexStressObject = stressObject 00033 complexStrainObject = strainObject 00034 00035 00036 00037 class ComplexCelasStressObject(complexStressObject): 00038 """ 00039 S T R E S S E S I N S C A L A R S P R I N G S ( C E L A S 2 ) 00040 TIME STRESS TIME STRESS TIME STRESS TIME STRESS 00041 0.0 0.0 5.000000E-02 0.0 1.000000E-01 0.0 1.500000E-01 0.0 00042 2.000000E-01 0.0 2.500000E-01 0.0 3.000000E-01 0.0 3.500000E-01 0.0 00043 """ 00044 def __init__(self,dataCode,isSort1,iSubcase,dt=None): 00045 stressObject.__init__(self,dataCode,iSubcase) 00046 self.eType = {} 00047 self.elementName = self.dataCode['elementName'] 00048 00049 self.code = [self.formatCode,self.sortCode,self.sCode] 00050 self.stress = {} 00051 00052 self.dt = dt 00053 if isSort1: 00054 if dt is not None: 00055 #self.add = self.addSort1 00056 self.addNewEid = self.addNewEidSort1 00057 ### 00058 else: 00059 assert dt is not None 00060 #self.add = self.addSort2 00061 self.addNewEid = self.addNewEidSort2 00062 ### 00063 00064 def deleteTransient(self,dt): 00065 del self.stress[dt] 00066 00067 def getTransients(self): 00068 k = self.stress.keys() 00069 k.sort() 00070 return k 00071 00072 def addNewTransient(self,dt): 00073 """initializes the transient variables""" 00074 self.elementName = self.dataCode['elementName'] 00075 self.dt = dt 00076 self.stress[dt] = {} 00077 00078 def addNewEid(self,dt,eid,stress): 00079 self.eType[eid] = self.elementName 00080 self.stress[eid] = stress 00081 00082 def addNewEidSort1(self,dt,eid,stress): 00083 if dt not in self.stress: 00084 self.addNewTransient(dt) 00085 self.eType[eid] = self.elementName 00086 self.stress[dt][eid] = stress 00087 00088 def addNewEidSort2(self,eid,dt,stress): 00089 if dt not in self.stress: 00090 self.addNewTransient(dt) 00091 self.eType[eid] = self.elementName 00092 self.stress[dt][eid] = stress 00093 00094 00095 def writeF06(self,header,pageStamp,pageNum=1,f=None,isMagPhase=False): 00096 """ 00097 @todo doesnt write... 00098 """ 00099 if self.nonlinearFactor is not None: 00100 return self.writeF06Transient(header,pageStamp,pageNum,f,isMagPhase) 00101 return 'ComplexCelasStressObject writeF06 not implemented...\n' 00102 #raise NotImplementedError() 00103 00104 def writeF06Transient(self,header,pageStamp,pageNum=1,f=None,isMagPhase=False): 00105 """ 00106 @todo improve formatting 00107 """ 00108 words = [' C O M P L E X F O R C E S I N S C A L A R S P R I N G S ( C E L A S 1 )\n', 00109 ' (REAL/IMAGINARY)\n', 00110 ' \n', 00111 ' ELEMENT ELEMENT\n', 00112 ' ID. FORCE ID. FORCE\n'] 00113 # 1001 1.537879E+01 / 0.0 1002 1.537879E+01 / 0.0 00114 # 1003 1.537879E+01 / 0.0 1004 1.537879E+01 / 0.0 00115 # 1005 1.537879E+01 / 0.0 1006 1.537879E+01 / 0.0 00116 # 1007 7.689395E+00 / 0.0 1008 7.689395E+00 / 0.0 00117 # 1009 7.689395E+00 / 0.0 1010 7.689395E+00 / 0.0 00118 msg = [] 00119 isMagPhase = False 00120 for dt,Stress in sorted(self.stress.iteritems()): 00121 if isinstance(dt,float): # fix 00122 header[1] = ' %s = %10.4E float %s\n' %(self.dataCode['name'],dt,self.analysisCode) 00123 else: 00124 header[1] = ' %s = %10i integer %s\n' %(self.dataCode['name'],dt,self.analysisCode) 00125 msg += header+words 00126 00127 i = 0 00128 for elementID,stress in sorted(Stress.iteritems()): 00129 00130 if isMagPhase: 00131 stressr=abs(stressr); stressi=angle(stress,deg=True) 00132 else: 00133 stressr=stress.real; stressi=stress.imag 00134 00135 (vals2,isAllZeros) = self.writeImagFloats13E([stress],isMagPhase) 00136 if i==0: 00137 elementID1 = elementID 00138 [stress1Real,stress1Imag] = vals2 00139 if i==1: 00140 elementID2 = elementID 00141 [stress2Real,stress2Imag] = vals2 00142 msg.append('%14i %13s / %13s %14i %13s / %-s\n' %(elementID1,stress1Real,stress1Imag,elementID2,stress2Real,stress2Imag.rstrip() )) 00143 i=-1 00144 ### 00145 i+=1 00146 ### 00147 msg.append(pageStamp+str(pageNum)+'\n') 00148 if f is not None: 00149 f.write(''.join(msg)) 00150 msg = [''] 00151 pageNum+=1 00152 return (''.join(msg),pageNum-1) 00153 00154 def __reprTransient__(self): 00155 msg = '---CELASx STRESSES---\n' 00156 msg += '%-6s %6s ' %('EID','eType') 00157 headers = ['stress'] 00158 for header in headers: 00159 msg += '%10s ' %(header) 00160 msg += '\n' 00161 00162 for dt,stress in sorted(self.stress.iteritems()): 00163 msg += '%s = %g\n' %(self.dataCode['name'],dt) 00164 for eid,istress in sorted(stress.iteritems()): 00165 msg += '%-6g %6s ' %(eid,self.eType[eid]) 00166 if abs(istress)<1e-6: 00167 msg += '%10s ' %('0') 00168 else: 00169 msg += '%10g ' %(istress) 00170 ### 00171 msg += '\n' 00172 ### 00173 return msg 00174 00175 def __repr__(self): 00176 return self.writeF06(['','',''],'')[0] 00177 00178 #print "spring dt=%s" %(self.dt) 00179 if self.dt is not None: 00180 return self.__reprTransient__() 00181 00182 msg = '---CELASx STRESSES---\n' 00183 msg += '%-8s %6s ' %('EID','eType') 00184 headers = ['stress'] 00185 for header in headers: 00186 msg += '%10s ' %(header) 00187 msg += '\n' 00188 #print "self.code = ",self.code 00189 for eid,istress in sorted(self.stress.iteritems()): 00190 #print "eid=",eid 00191 #print "eType",self.eType 00192 msg += '%-8i %6s ' %(eid,self.eType[eid]) 00193 if abs(istress)<1e-6: 00194 msg += '%10s ' %('0') 00195 else: 00196 msg += '%10i ' %(istress) 00197 ### 00198 msg += '\n' 00199 #msg += "eid=%-4s eType=%s axial=%-4i torsion=%-4i\n" %(eid,self.eType,axial,torsion) 00200 return msg 00201 00202 class ComplexCelasStrainObject(complexStrainObject): 00203 def __init__(self,dataCode,isSort1,iSubcase,dt=None): 00204 strainObject.__init__(self,dataCode,iSubcase) 00205 self.eType = {} 00206 self.elementName = self.dataCode['elementName'] 00207 00208 self.code = [self.formatCode,self.sortCode,self.sCode] 00209 00210 self.strain = {} 00211 00212 self.dt = dt 00213 if isSort1: 00214 if dt is not None: 00215 #self.add = self.addSort1 00216 self.addNewEid = self.addNewEidSort1 00217 ### 00218 else: 00219 assert dt is not None 00220 #self.add = self.addSort2 00221 self.addNewEid = self.addNewEidSort2 00222 ### 00223 00224 def deleteTransient(self,dt): 00225 del self.strain[dt] 00226 00227 def getTransients(self): 00228 k = self.strain.keys() 00229 k.sort() 00230 return k 00231 00232 def addNewTransient(self,dt): 00233 """ 00234 initializes the transient variables 00235 """ 00236 self.strain[dt] = {} 00237 00238 def addNewEid(self,dt,eid,strain): 00239 assert eid >= 0 00240 #self.eType = self.eType 00241 self.eType[eid] = self.elementName 00242 self.strain[eid] = strain 00243 00244 def addNewEidSort1(self,dt,eid,strain): 00245 assert eid >= 0 00246 00247 self.eType[eid] = self.elementType 00248 self.strain[dt][eid] = strain 00249 00250 def __repr__(self): 00251 #return self.writeF06(['','',''],'') 00252 00253 if self.dt is not None: 00254 return self.__reprTransient__() 00255 00256 msg = '---CELASx STRAINS---\n' 00257 msg += '%-8s %6s ' %('EID','eType') 00258 headers = ['strain'] 00259 for header in headers: 00260 msg += '%8s ' %(header) 00261 msg += '\n' 00262 00263 for eid,strain in sorted(self.strain.iteritems()): 00264 #strain = self.strain[eid] 00265 msg += '%-8i %6s ' %(eid,self.eType[eid]) 00266 00267 if abs(strain)<1e-7: 00268 msg += '%8s ' %('0') 00269 else: 00270 msg += '%8.3g ' %(strain) 00271 ### 00272 msg += '\n' 00273 return msg