Advertisement
Dineshom90

python class

Jan 30th, 2017
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.46 KB | None | 0 0
  1. # -*- encoding: utf-8 -*-
  2.  
  3. '''
  4. Implementation of a TWA Profile class
  5. '''
  6. from math import *
  7.  
  8. from AList import AList
  9. from Base import Base
  10. from Element import Element
  11.  
  12.  
  13. class Profile(Base):
  14.  
  15. # constructor
  16. def __init__(self,name):
  17. Base.__init__(self)
  18.  
  19. self._name = name
  20. self._e = AList()
  21.  
  22. self._a = 0. # area
  23. self._s = [0.,0.] # static moment
  24. self._iu = [0.,0.,0.] # moment of inertia in user coordinates
  25. self._ex = [0.,0.] # position of the main coordinate system
  26. self._ic = [0.,0.,0.] # moment of inertia in main coordinates
  27. self._ip = [0.,0.] # principle values of the moment of inertia
  28. self._alp = 0. # rotation angle
  29.  
  30. # add an element to the profile
  31. def addElement(self,e):
  32. if not isinstance(e,Element):
  33. raise Exception("*** error: object is not an Element instance!")
  34. self._e.add(e._no-1,e)
  35.  
  36. # list all profile data
  37. def list(self):
  38. self.appendLog("name.........................: '%s'" % self._name)
  39.  
  40. self.appendLog(" area.......................: %8.2f cm^2" % \
  41. (self._a/1.e2,))
  42. self.appendLog(" static moments.............: %8.2f %8.2f cm^3" % \
  43. (self._s[0]/1.e3,self._s[1]/1.e3))
  44. self.appendLog(" moment of inertia (user c.): %8.2f %8.2f %8.2f cm^4" % \
  45. (self._iu[0]/1.e4,self._iu[1]/1.e4,self._iu[2]/1.e4))
  46. self.appendLog(" center of mass position....: %8.2f %8.2f cm" % \
  47. (self._ex[0]/10.,self._ex[1]/10.))
  48. self.appendLog(" moment of inertia (center).: %8.2f %8.2f %8.2f cm^4" % \
  49. (self._ic[0]/1.e4,self._ic[1]/1.e4,self._ic[2]/1.e4))
  50. self.appendLog(" moment of inertia (princi.): %8.2f %8.2f cm^4" % \
  51. (self._ip[0]/1.e4,self._ip[1]/1.e4))
  52. self.appendLog(" rotation angle.............: %8.2f °, tan(alp) = %.2f" % \
  53. (self._alp*45./atan(1.),tan(self._alp)))
  54.  
  55. self.appendLog(" > element data:")
  56. self._e.list()
  57.  
  58. # calculate the section values
  59. def getResults(self):
  60. # if len(self._e) < 1: return
  61. elements = 0
  62. # sum up all element data
  63. for e in self._e:
  64. if e is None: continue
  65.  
  66. self._a += e.getA()
  67. for i in range(2): self._s[i] += e.getS(i)
  68. for i in range(3): self._iu[i] += e.getI(i)
  69. elements += 1
  70. if elements < 1 : raise "error:No elements found"
  71.  
  72. # calculate excentricities / center of mass
  73. for i in range(2): self._ex[i] = self._s[(i+1)%2]/self._a
  74.  
  75. # calculate the moi in main coordinate system
  76. for i in range(2):
  77. self._ic[i] = self._iu[i] - self._ex[(i+1)%2]**2*self._a
  78. self._ic[2] = self._iu[2] - self._ex[0]*self._ex[1]* self._a
  79.  
  80. # main axis transformation
  81. iDel = self._ic[0] - self._ic[1] # Iyy,c - Izz,c
  82. iSum = self._ic[0] + self._ic[1] # Iyy,c + Izz,c
  83. iSqr = sqrt(iDel**2 + 4.*self._ic[2]**2)
  84. self._ip[0] = (iSum + iSqr)/2.
  85. self._ip[1] = (iSum - iSqr) / 2.
  86.  
  87. # rotation angle
  88. self._alp = 0.5*atan2(-2.*self._ic[2],iDel)
  89.  
  90. # dras the shape of the profile
  91. def view(self,viewer = True):
  92.  
  93. # import pylab
  94. try:
  95. import pylab
  96. except:
  97. self.appendLog("*** error: pylab not found!")
  98. return
  99.  
  100. # create plot
  101. lines = []
  102.  
  103. # create lines
  104. for e in self._e:
  105. if e is None: continue
  106.  
  107. y1 = e._n[0]._x[0] # y of 1st node
  108. y2 = e._n[1]._x[0] # y of 2nd node
  109. z1 = e._n[0]._x[1] # z of 1st node
  110. z2 = e._n[1]._x[1] # z of 2nd node
  111.  
  112. # --- new line ------
  113. lines += [ [[y1,y2], [z1,z2] ], ]
  114.  
  115. # draw lines (elements)
  116. for line in lines:
  117. # |blue
  118. pylab.plot(line[0],line[1],'b')
  119.  
  120. # draw lines (nodes)
  121. for line in lines:
  122. # |red points
  123. pylab.plot(line[0],line[1],'rp')
  124.  
  125. # set a title
  126. pylab.title(self._name)
  127.  
  128. # controling the output
  129. pylab.axis('equal')
  130.  
  131. if viewer: pylab.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement