gfk-plate.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. # https://akaszynski.github.io/pyansys/ansys_control.html#initial-setup-and-example
  2. # pip install pyansys --upgrade
  3. import pyansys
  4. import numpy as np
  5. import os
  6. def plot_rotor(ansys):
  7. ansys.run("/Post1")
  8. ansys.run("ALLS")
  9. ansys.run("/erase")
  10. ansys.run("/win,1,ltop $/win,2,rtop")
  11. ansys.run("/win,3,lbot $/win,4,rbot")
  12. ansys.run("/win,1,off")
  13. ansys.run("/win,2,off")
  14. ansys.run("/win,3,off")
  15. ansys.run("/win,4,off")
  16. ansys.run("/win,1,on")
  17. ansys.plnsol("S", "X") # Stress in Radialrichtung
  18. ansys.run("/noerase")
  19. ansys.run("/win,1,off")
  20. ansys.run("/win,2,on")
  21. ansys.run("/view,2,0,0,-1")
  22. ansys.plnsol("S", "X") # Stress in Radialrichtung, Sicht von hinten
  23. ansys.run("/noerase")
  24. ansys.run("/win,2,off")
  25. ansys.run("/win,3,on")
  26. ansys.plnsol("S", "Y") # Stress in Tangentialrichtung
  27. ansys.run("/noerase")
  28. ansys.run("/win,3,off")
  29. ansys.run("/win,4,on")
  30. ansys.plnsol("U", "SUM")
  31. ansys.run("/noerase")
  32. ansys.run("/win,4,off")
  33. ansys.run("/EOF")
  34. def sim_rotor(materials, angles, outer_diameter=250, inner_diameter=50, thickness=5, omega=0.1):
  35. layers = len(angles)
  36. layer_thickness = thickness / layers
  37. path = os.getcwd()+"\\ws"
  38. mapdl = pyansys.launch_mapdl(run_location=path, interactive_plotting=True)
  39. # clear existing geometry
  40. mapdl.finish()
  41. mapdl.clear()
  42. th = 200 # [°C] Herstellungstemperatur
  43. tn = 20 # [°C] Nutzungstemperatur
  44. mapdl.prep7()
  45. # define Material
  46. for i in range(0, len(materials)):
  47. mapdl.mptemp(i + 1, th)
  48. mapdl.mpdata("EX", i + 1, "", materials[i]["e11"])
  49. mapdl.mpdata("EY", i + 1, "", materials[i]["e22"])
  50. mapdl.mpdata("EZ", i + 1, "", materials[i]["e33"])
  51. mapdl.mpdata("PRXY", i + 1, "", materials[i]["pr12"])
  52. mapdl.mpdata("PRXZ", i + 1, "", materials[i]["pr13"])
  53. mapdl.mpdata("PRYZ", i + 1, "", materials[i]["pr23"])
  54. mapdl.mpdata("DENS", i + 1, "", materials[i]["dens"])
  55. mapdl.mpdata("GXY", i + 1, "", materials[i]["g12"])
  56. mapdl.mpdata("GXZ", i + 1, "", materials[i]["g13"])
  57. mapdl.mpdata("GYZ", i + 1, "", materials[i]["g23"])
  58. # Waermeausdenungsk
  59. mapdl.mpdata("ALPX", i + 1, "", materials[i]["alp11"])
  60. mapdl.mpdata("ALPY", i + 1, "", materials[i]["alp22"])
  61. mapdl.mpdata("ALPZ", i + 1, "", materials[i]["alp33"])
  62. # Waermeleitfaehigk
  63. # mapdl.mpdata("KXX", i + 1, "", materials[i]["k11"])
  64. # mapdl.mpdata("KYY", i + 1, "", materials[i]["k22"])
  65. # mapdl.mpdata("KZZ", i + 1, "", materials[i]["k33"])
  66. # Quellkoeffizient
  67. # mapdl.mpdata("BETX", i + 1, "", materials[i]["bet11"])
  68. # mapdl.mpdata("BETY", i + 1, "", materials[i]["bet22"])
  69. # mapdl.mpdata("BETZ", i + 1, "", materials[i]["bet33"])
  70. # Diffusionskoeffizient
  71. # mapdl.mpdata("DXX", i + 1, "", materials[i]["d11"])
  72. # mapdl.mpdata("DYY", i + 1, "", materials[i]["d22"])
  73. # mapdl.mpdata("DZZ", i + 1, "", materials[i]["d33"])
  74. # define Element
  75. mapdl.et(1, "SHELL181")
  76. # enable Laminate
  77. mapdl.run("KEYOPT,1,8,1")
  78. # define Laminate
  79. mapdl.run("SECT, 1, SHELL")
  80. # secdata, Thickness ,MatId,theta,Number of integration points in layer
  81. if len(angles) != len(materials):
  82. for i in range(0, len(angles)):
  83. mapdl.secdata(layer_thickness, 1, angles[i], 3)
  84. else:
  85. for i in range(0, len(angles)):
  86. mapdl.secdata(layer_thickness, i + 1, angles[i], 3)
  87. # Shell node will be offset to midplane of the section
  88. mapdl.secoffset("MID")
  89. mapdl.run("seccontrol,,,,,,,")
  90. mapdl.run("/ESHAPE,1.0")
  91. # define Geometry
  92. # change global coordinate system to cylindric system
  93. mapdl.csys(1)
  94. mapdl.cyl4(0, 0, inner_diameter / 2, 0, outer_diameter / 2, 180)
  95. mapdl.cyl4(0, 0, inner_diameter / 2, 180, outer_diameter / 2, 360)
  96. mapdl.nsel("S", "LOC", "Y", 0)
  97. mapdl.nummrg("ALL")
  98. mapdl.nsel("S", "LOC", "Y", 180)
  99. mapdl.nummrg("ALL")
  100. mapdl.lsel("S", "", "", 1, 7, 2)
  101. mapdl.lesize("ALL", "", "", 20)
  102. mapdl.lsel("S", "", "", 2, 4, 2)
  103. mapdl.lesize("ALL", "", "", 20)
  104. mapdl.lsel("ALL")
  105. # mapdl.aplot()
  106. mapdl.mshape(0, "2D") # quadratic 2D Shapes
  107. mapdl.mshkey(1) # 0-free meshing
  108. mapdl.amesh("ALL")
  109. # mapdl.eplot()
  110. mapdl.run("/SOLU")
  111. mapdl.omega("", "", omega) # [rad/s] Winkelgeschwindigkeit(+: gegen Uhrzeigersinn))
  112. mapdl.nsel("S", "LOC", "X", inner_diameter / 2)
  113. mapdl.d("ALL", "UX", 0)
  114. mapdl.d("ALL", "UY", 0)
  115. mapdl.d("ALL", "UZ", 0)
  116. mapdl.d("ALL", "ROTX", 0)
  117. mapdl.d("ALL", "ROTY", 0)
  118. mapdl.d("ALL", "ROTZ", 0)
  119. mapdl.run("ALLS")
  120. mapdl.outres("ALL", "ALL")
  121. # mapdl.open_gui()
  122. mapdl.solve()
  123. mapdl.finish()
  124. #mapdl.post1()
  125. #mapdl.open_gui()
  126. # plot_rotor(mapdl)
  127. # access results using ANSYS object
  128. resultfile = os.getcwd() + '\\ws\\file.rst'
  129. result = pyansys.read_binary(resultfile)
  130. # result = mapdl.result
  131. result.plot_principal_nodal_stress(0, 'EQV')
  132. # plot_nodal_solution doesnt work
  133. nodenum, stress = result.principal_nodal_stress(0)
  134. # von Mises stress is the last column
  135. # must be nanmax as the shell element stress is not recorded
  136. maxstress = np.nanmax(stress[:, -1])
  137. mapdl.exit()
  138. return maxstress
  139. print(sim_rotor(
  140. [{
  141. "e11": 42.5,
  142. "e22": 11,
  143. "e33": 11,
  144. "pr12": 0.28,
  145. "pr13": 0.28,
  146. "pr23": 0.28,
  147. "dens": 1950E-6,
  148. "g12": 4.2,
  149. "g13": 4.2,
  150. "g23": 2.56,
  151. "alp11": 5.7E-6,
  152. "alp22": 45E-6,
  153. "alp33": 45E-6,
  154. "k11": 0.72E3,
  155. "k22": 0.5E3,
  156. "k33": 0.5E3,
  157. "bet11": 0E-3,
  158. "bet22": 4E-3,
  159. "bet33": 4E-3,
  160. "d11": 4.4E3,
  161. "d22": 3.1E3,
  162. "d33": 3.1E3
  163. }], [90, 0, 0, 0, 0, 0]))