Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- encoding: utf-8 -*-
- '''
- Implementation of a TWA Profile class
- '''
- from math import *
- from AList import AList
- from Base import Base
- from Element import Element
- class Profile(Base):
- # constructor
- def __init__(self,name):
- Base.__init__(self)
- self._name = name
- self._e = AList()
- self._a = 0. # area
- self._s = [0.,0.] # static moment
- self._iu = [0.,0.,0.] # moment of inertia in user coordinates
- self._ex = [0.,0.] # position of the main coordinate system
- self._ic = [0.,0.,0.] # moment of inertia in main coordinates
- self._ip = [0.,0.] # principle values of the moment of inertia
- self._alp = 0. # rotation angle
- # add an element to the profile
- def addElement(self,e):
- if not isinstance(e,Element):
- raise Exception("*** error: object is not an Element instance!")
- self._e.add(e._no-1,e)
- # list all profile data
- def list(self):
- self.appendLog("name.........................: '%s'" % self._name)
- self.appendLog(" area.......................: %8.2f cm^2" % \
- (self._a/1.e2,))
- self.appendLog(" static moments.............: %8.2f %8.2f cm^3" % \
- (self._s[0]/1.e3,self._s[1]/1.e3))
- self.appendLog(" moment of inertia (user c.): %8.2f %8.2f %8.2f cm^4" % \
- (self._iu[0]/1.e4,self._iu[1]/1.e4,self._iu[2]/1.e4))
- self.appendLog(" center of mass position....: %8.2f %8.2f cm" % \
- (self._ex[0]/10.,self._ex[1]/10.))
- self.appendLog(" moment of inertia (center).: %8.2f %8.2f %8.2f cm^4" % \
- (self._ic[0]/1.e4,self._ic[1]/1.e4,self._ic[2]/1.e4))
- self.appendLog(" moment of inertia (princi.): %8.2f %8.2f cm^4" % \
- (self._ip[0]/1.e4,self._ip[1]/1.e4))
- self.appendLog(" rotation angle.............: %8.2f °, tan(alp) = %.2f" % \
- (self._alp*45./atan(1.),tan(self._alp)))
- self.appendLog(" > element data:")
- self._e.list()
- # calculate the section values
- def getResults(self):
- # if len(self._e) < 1: return
- elements = 0
- # sum up all element data
- for e in self._e:
- if e is None: continue
- self._a += e.getA()
- for i in range(2): self._s[i] += e.getS(i)
- for i in range(3): self._iu[i] += e.getI(i)
- elements += 1
- if elements < 1 : raise "error:No elements found"
- # calculate excentricities / center of mass
- for i in range(2): self._ex[i] = self._s[(i+1)%2]/self._a
- # calculate the moi in main coordinate system
- for i in range(2):
- self._ic[i] = self._iu[i] - self._ex[(i+1)%2]**2*self._a
- self._ic[2] = self._iu[2] - self._ex[0]*self._ex[1]* self._a
- # main axis transformation
- iDel = self._ic[0] - self._ic[1] # Iyy,c - Izz,c
- iSum = self._ic[0] + self._ic[1] # Iyy,c + Izz,c
- iSqr = sqrt(iDel**2 + 4.*self._ic[2]**2)
- self._ip[0] = (iSum + iSqr)/2.
- self._ip[1] = (iSum - iSqr) / 2.
- # rotation angle
- self._alp = 0.5*atan2(-2.*self._ic[2],iDel)
- # dras the shape of the profile
- def view(self,viewer = True):
- # import pylab
- try:
- import pylab
- except:
- self.appendLog("*** error: pylab not found!")
- return
- # create plot
- lines = []
- # create lines
- for e in self._e:
- if e is None: continue
- y1 = e._n[0]._x[0] # y of 1st node
- y2 = e._n[1]._x[0] # y of 2nd node
- z1 = e._n[0]._x[1] # z of 1st node
- z2 = e._n[1]._x[1] # z of 2nd node
- # --- new line ------
- lines += [ [[y1,y2], [z1,z2] ], ]
- # draw lines (elements)
- for line in lines:
- # |blue
- pylab.plot(line[0],line[1],'b')
- # draw lines (nodes)
- for line in lines:
- # |red points
- pylab.plot(line[0],line[1],'rp')
- # set a title
- pylab.title(self._name)
- # controling the output
- pylab.axis('equal')
- if viewer: pylab.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement