pyNastran  0.5.0
pyNastran BDF Reader/Writer, OP2 Parser, and GUI
oes_springs.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 
00026 from __future__ import division, print_function
00027 import sys
00028 
00029 from .oes_objects import stressObject, strainObject
00030 
00031 
00032 class CelasStressObject(stressObject):
00033     """
00034                               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 )
00035         TIME         STRESS              TIME         STRESS              TIME         STRESS              TIME         STRESS
00036     0.0            0.0               5.000000E-02   0.0               1.000000E-01   0.0               1.500000E-01   0.0
00037     2.000000E-01   0.0               2.500000E-01   0.0               3.000000E-01   0.0               3.500000E-01   0.0
00038     """
00039     def __init__(self,dataCode,isSort1,iSubcase,dt=None):
00040         stressObject.__init__(self,dataCode,iSubcase)
00041         self.eType = {}
00042         self.elementName = self.dataCode['elementName']
00043 
00044         self.code = [self.formatCode,self.sortCode,self.sCode]
00045         self.stress = {}
00046 
00047         self.dt = dt
00048         if isSort1:
00049             if dt is not None:
00050                 #self.add = self.addSort1
00051                 self.addNewEid = self.addNewEidSort1
00052             ###
00053         else:
00054             assert dt is not None
00055             #self.add = self.addSort2
00056             self.addNewEid = self.addNewEidSort2
00057         ###
00058 
00059     def getLength(self):
00060         return (8,'f')
00061 
00062     def deleteTransient(self,dt):
00063         del self.stress[dt]
00064 
00065     def getTransients(self):
00066         k = self.stress.keys()
00067         k.sort()
00068         return k
00069 
00070     def addNewTransient(self,dt):
00071         """initializes the transient variables"""
00072         self.elementName = self.dataCode['elementName']
00073         self.dt = dt
00074         self.stress[dt] = {}
00075 
00076     def addNewEid(self,dt,eid,out):
00077         (stress,) = out
00078         self.eType[eid]  = self.elementName
00079         self.stress[eid] = stress
00080 
00081     def addNewEidSort1(self,dt,eid,out):
00082         if dt not in self.stress:
00083             self.addNewTransient(dt)
00084         (stress,) = out
00085         self.eType[eid]      = self.elementName
00086         self.stress[dt][eid] = stress
00087 
00088     def addNewEidSort2(self,eid,dt,out):
00089         if dt not in self.stress:
00090             self.addNewTransient(dt)
00091         (stress,) = out
00092         self.eType[eid]      = self.elementName
00093         self.stress[dt][eid] = stress
00094 
00095     def __reprTransient__(self):
00096         msg = '---CELASx STRESSES---\n'
00097         msg += '%-6s %6s ' %('EID','eType')
00098         headers = ['stress']
00099         for header in headers:
00100             msg += '%10s ' %(header)
00101         msg += '\n'
00102 
00103         for dt,stress in sorted(self.stress.iteritems()):
00104             msg += '%s = %g\n' %(self.dataCode['name'],dt)
00105             for eid,istress in sorted(stress.iteritems()):
00106                 msg += '%-6g %6s ' %(eid,self.eType[eid])
00107                 if abs(istress)<1e-6:
00108                     msg += '%10s ' %('0')
00109                 else:
00110                     msg += '%10g ' %(istress)
00111                 ###
00112                 msg += '\n'
00113             ###
00114         return msg
00115 
00116     def __repr__(self):
00117         #print "spring dt=%s" %(self.dt)
00118         if self.dt is not None:
00119             return self.__reprTransient__()
00120 
00121         msg = '---CELASx STRESSES---\n'
00122         msg += '%-8s %6s ' %('EID','eType')
00123         headers = ['stress']
00124         for header in headers:
00125             msg += '%10s ' %(header)
00126         msg += '\n'
00127         #print "self.code = ",self.code
00128         for eid,istress in sorted(self.stress.iteritems()):
00129             #print "eid=",eid
00130             #print "eType",self.eType
00131             msg += '%-8i %6s ' %(eid,self.eType[eid])
00132             if abs(istress)<1e-6:
00133                 msg += '%10s ' %('0')
00134             else:
00135                 msg += '%10i ' %(istress)
00136             ###
00137             msg += '\n'
00138             #msg += "eid=%-4s eType=%s axial=%-4i torsion=%-4i\n" %(eid,self.eType,axial,torsion)
00139         return msg
00140 
00141 class CelasStrainObject(strainObject):
00142     def __init__(self,dataCode,isSort1,iSubcase,dt=None):
00143         strainObject.__init__(self,dataCode,iSubcase)
00144         self.eType = {}
00145         self.elementName = self.dataCode['elementName']
00146 
00147         self.code = [self.formatCode,self.sortCode,self.sCode]
00148         
00149         self.isTransient = False
00150         self.strain = {}
00151 
00152         self.dt = dt
00153         if isSort1:
00154             if dt is not None:
00155                 #self.add = self.addSort1
00156                 self.addNewEid = self.addNewEidSort1
00157             ###
00158         else:
00159             assert dt is not None
00160             #self.add = self.addSort2
00161             self.addNewEid = self.addNewEidSort2
00162         ###
00163 
00164     def getLength(self):
00165         return (8,'f')
00166 
00167     def deleteTransient(self,dt):
00168         del self.strain[dt]
00169 
00170     def getTransients(self):
00171         k = self.strain.keys()
00172         k.sort()
00173         return k
00174 
00175     def addNewTransient(self,dt):
00176         """
00177         initializes the transient variables
00178         """
00179         self.strain[dt] = {}
00180 
00181     def addNewEid(self,dt,eid,out):
00182         (strain,) = out
00183         assert eid >= 0
00184         #self.eType = self.eType
00185         self.eType[eid]  = self.elementName
00186         self.strain[eid] = strain
00187 
00188     def addNewEidSort1(self,dt,eid,out):
00189         #print out
00190         (strain,) = out
00191         assert eid >= 0
00192 
00193         self.eType[eid] = self.elementType
00194         self.strain[dt][eid] = strain
00195 
00196     def __repr__(self):
00197         if self.dt is not None:
00198             return self.__reprTransient__()
00199 
00200         msg = '---CELASx STRAINS---\n'
00201         msg += '%-8s %6s ' %('EID','eType')
00202         headers = ['strain']
00203         for header in headers:
00204             msg += '%8s ' %(header)
00205         msg += '\n'
00206 
00207         for eid,strain in sorted(self.strain.iteritems()):
00208             #strain = self.strain[eid]
00209             msg += '%-8i %6s ' %(eid,self.eType[eid])
00210 
00211             if abs(strain)<1e-7:
00212                 msg += '%8s ' %('0')
00213             else:
00214                 msg += '%8.3g ' %(strain)
00215             ###
00216             msg += '\n'
00217         return msg
 All Classes Namespaces Files Functions Variables