pyNastran  0.5.0
pyNastran BDF Reader/Writer, OP2 Parser, and GUI
opg_Objects.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 from numpy import array
00026 from pyNastran.op2.resultObjects.op2_Objects import scalarObject
00027 
00028 class AppliedLoadsObject(scalarObject): # approachCode=1, sortCode=0
00029     def __init__(self,dataCode,isSort1,iSubcase,dt=None):
00030         scalarObject.__init__(self,dataCode,iSubcase)
00031         self.dt = dt
00032         
00033         ## this could get very bad very quick, but it could be great!
00034         ## basically it's a way to handle transients without making
00035         ## a whole new class
00036         self.eids    = {}
00037         self.sources = {}
00038         self.forces  = {}
00039         self.moments = {}
00040         if self.dt is not None:
00041             assert dt>=0.
00042             raise NotImplementedError('transient appliedLoads not implemented...')
00043             self.eids    = {dt: []}
00044             self.sources = {dt: []}
00045             self.forces  = {dt: []}
00046             self.moments = {dt: []}
00047             self.add = self.addTransient
00048         ###
00049 
00050     def updateDt(self):
00051         """
00052         this method is called if the object
00053         already exits and a new time step is found
00054         """
00055         assert dt>=0.
00056         self.dt = dt
00057         self.eids[dt]    = []
00058         self.sources[dt] = []
00059         self.forces[dt]  = []
00060         self.moments[dt] = []
00061 
00062     def addNode(self,nodeID,eid,source,v1,v2,v3,v4,v5,v6):
00063         msg = "nodeID=%s eid=%s source=|%s| v1=%i v2=%i v3=%i v4=%i v5=%i v6=%i" %(nodeID,eid,source,v1,v2,v3,v4,v5,v6)
00064         assert 0<nodeID<1000000000, msg
00065         assert nodeID not in self.forces,msg
00066 
00067         self.eids[nodeID]    = [eid]
00068         self.sources[nodeID] = [source]
00069         self.forces[ nodeID] = [ array([v1,v2,v3]) ] # Fx,Fy,Fz
00070         self.moments[nodeID] = [ array([v4,v5,v6]) ] # Mx,My,Mz
00071     ###
00072 
00073     def add(self,nodeID,eid,source,v1,v2,v3,v4,v5,v6):
00074         msg = "nodeID=%s eid=%s source=|%s| v1=%i v2=%i v3=%i v4=%i v5=%i v6=%i" %(nodeID,eid,source,v1,v2,v3,v4,v5,v6)
00075         assert 0<nodeID<1000000000,msg
00076         if nodeID not in self.forces:
00077             self.addNode(nodeID,eid,source,v1,v2,v3,v4,v5,v6)
00078             return None
00079         #assert nodeID not in self.forces,msg
00080 
00081         self.eids[nodeID].append(eid)
00082         self.sources[nodeID].append(source)
00083         self.forces[nodeID].append( array([v1,v2,v3])) # Fx,Fy,Fz
00084         self.moments[nodeID].append(array([v4,v5,v6])) # Mx,My,Mz
00085     ###
00086 
00087     def addTransient(self,nodeID,eid,source,v1,v2,v3,v4,v5,v6):
00088         raise Exception('no implemented')
00089         msg = "nodeID=%s v1=%s v2=%s v3=%s" %(nodeID,v1,v2,v3)
00090         assert 0<nodeID<1000000000, msg
00091         assert nodeID not in self.forces
00092         
00093         self.forces[ self.dt][nodeID] = array([v1,v2,v3]) # Fx,Fy,Fz
00094         self.moments[self.dt][nodeID] = array([v4,v5,v6]) # Mx,My,Mz
00095     ###
00096 
00097     def __repr__(self):
00098         msg = '---APPLIED LOADS---\n'
00099         if self.dt is not None:
00100             msg += 'dt = %g\n' %(self.dt)
00101         headers = ['Fx','Fy','Fz','Mx','My','Mz']
00102         msg += '%-8s %-8s %8s ' %('nodeID','eID','source')
00103         for header in headers:
00104             msg += '%11s ' %(header)
00105         msg += '\n'
00106 
00107         msg += '-'*100+'\n'
00108         for nodeID,forces in sorted(self.forces.iteritems()):
00109             for i in xrange(len(forces)):
00110                 force  = forces[i]
00111                 moment = self.moments[nodeID][i]
00112                 source = self.sources[nodeID][i]
00113                 eid    = self.eids[nodeID][i]
00114                 if '*TOTALS*' in source:
00115                     eid = '='
00116                 elif eid==0:
00117                     eid = '*'
00118 
00119                 (Fx,Fy,Fz) = force
00120                 (Mx,My,Mz) = moment
00121 
00122                 msg += '%-8i %-8s %8s ' %(nodeID,eid,source)
00123                 vals = [Fx,Fy,Fz,Mx,My,Mz]
00124                 for val in vals:
00125                     if abs(val)<1e-6:
00126                         msg += '%11s ' %(0)
00127                     else:
00128                         msg += '%11.3f ' %(val)
00129                     ###
00130                 msg += '\n'
00131                 if '*TOTALS*' in source:
00132                     msg += '-'*100+'\n'
00133                 ###
00134             ###
00135         return msg
00136 
 All Classes Namespaces Files Functions Variables