gfk_plate.py 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. import time
  7. def sim_rotor(materials, angles, outer_diameter=0.250, inner_diameter=0.050, thickness=0.005, omega=1):
  8. layers = len(angles)
  9. layer_thickness = thickness / layers
  10. path = os.getcwd() + "\\ws"
  11. mapdl = pyansys.launch_mapdl(run_location=path, interactive_plotting=True, loglevel='ERROR', override=True)
  12. # clear existing geometry
  13. mapdl.finish()
  14. mapdl.clear()
  15. th = 50 # [°C] Herstellungstemperatur
  16. tn = 50 # [°C] Nutzungstemperatur
  17. mapdl.prep7()
  18. # define Material
  19. for i in range(0, len(materials)):
  20. mapdl.mptemp(i + 1, th)
  21. mapdl.mpdata("EX", i + 1, "", materials[i]["e11"])
  22. mapdl.mpdata("EY", i + 1, "", materials[i]["e22"])
  23. mapdl.mpdata("EZ", i + 1, "", materials[i]["e33"])
  24. mapdl.mpdata("PRXY", i + 1, "", materials[i]["pr12"])
  25. mapdl.mpdata("PRXZ", i + 1, "", materials[i]["pr13"])
  26. mapdl.mpdata("PRYZ", i + 1, "", materials[i]["pr23"])
  27. mapdl.mpdata("DENS", i + 1, "", materials[i]["dens"])
  28. mapdl.mpdata("GXY", i + 1, "", materials[i]["g12"])
  29. mapdl.mpdata("GXZ", i + 1, "", materials[i]["g13"])
  30. mapdl.mpdata("GYZ", i + 1, "", materials[i]["g23"])
  31. # Waermeausdenungsk
  32. mapdl.mpdata("ALPX", i + 1, "", materials[i]["alp11"])
  33. mapdl.mpdata("ALPY", i + 1, "", materials[i]["alp22"])
  34. mapdl.mpdata("ALPZ", i + 1, "", materials[i]["alp33"])
  35. # Waermeleitfaehigk
  36. mapdl.mpdata("KXX", i + 1, "", materials[i]["k11"])
  37. mapdl.mpdata("KYY", i + 1, "", materials[i]["k22"])
  38. mapdl.mpdata("KZZ", i + 1, "", materials[i]["k33"])
  39. # Quellkoeffizient
  40. mapdl.mpdata("BETX", i + 1, "", materials[i]["bet11"])
  41. mapdl.mpdata("BETY", i + 1, "", materials[i]["bet22"])
  42. mapdl.mpdata("BETZ", i + 1, "", materials[i]["bet33"])
  43. # Diffusionskoeffizient
  44. mapdl.mpdata("DXX", i + 1, "", materials[i]["d11"])
  45. mapdl.mpdata("DYY", i + 1, "", materials[i]["d22"])
  46. mapdl.mpdata("DZZ", i + 1, "", materials[i]["d33"])
  47. # define Element
  48. mapdl.et(1, "SHELL181")
  49. # enable Laminate
  50. mapdl.run("KEYOPT,1,8,1")
  51. # define Laminate
  52. mapdl.run("SECT, 1, SHELL")
  53. # secdata, Thickness ,MatId,theta,Number of integration points in layer
  54. if len(angles) != len(materials):
  55. for i in range(0, len(angles)):
  56. mapdl.secdata(layer_thickness, 1, angles[i], 3)
  57. print(str(angles[i]))
  58. else:
  59. for i in range(0, len(angles)):
  60. mapdl.secdata(layer_thickness, i + 1, angles[i], 3)
  61. # Shell node will be offset to midplane of the section
  62. mapdl.secoffset("MID")
  63. mapdl.run("seccontrol,,,,,,,")
  64. mapdl.run("/ESHAPE,1.0")
  65. # define Geometry
  66. # change global coordinate system to cylindric system
  67. mapdl.csys(1)
  68. mapdl.cyl4(0, 0, inner_diameter / 2, 0, outer_diameter / 2, 180)
  69. mapdl.cyl4(0, 0, inner_diameter / 2, 180, outer_diameter / 2, 360)
  70. # mapdl.aplot()
  71. mapdl.nsel("S", "LOC", "Y", 0)
  72. mapdl.nummrg("ALL")
  73. mapdl.nsel("S", "LOC", "Y", 180)
  74. mapdl.nummrg("ALL")
  75. mapdl.lsel("S", "", "", 1, 7, 2)
  76. mapdl.lesize("ALL", "", "", 20)
  77. mapdl.lsel("S", "", "", 2, 4, 2)
  78. mapdl.lesize("ALL", "", "", 20)
  79. mapdl.lsel("ALL")
  80. mapdl.mshape(0, "2D") # quadratic 2D Shapes
  81. mapdl.mshkey(1) # 0-free meshing
  82. mapdl.amesh("ALL")
  83. mapdl.run("/SOLU")
  84. mapdl.omega("", "", omega) # [rad/s] Winkelgeschwindigkeit(+: gegen Uhrzeigersinn))
  85. mapdl.nsel("S", "LOC", "X", inner_diameter / 2)
  86. mapdl.d("ALL", "UX", 0)
  87. mapdl.d("ALL", "UY", 0)
  88. mapdl.d("ALL", "UZ", 0)
  89. mapdl.d("ALL", "ROTX", 0)
  90. mapdl.d("ALL", "ROTY", 0)
  91. mapdl.d("ALL", "ROTZ", 0)
  92. mapdl.run("ALLS")
  93. mapdl.outres("ALL", "ALL")
  94. # mapdl.open_gui()
  95. mapdl.solve()
  96. mapdl.finish()
  97. mapdl.run("/Post1")
  98. result = mapdl.result
  99. mapdl.aplot()
  100. # result.plot_principal_nodal_stress(0, '1', show_edges=True, show_axes=True)
  101. result.plot_nodal_solution(0, 'x')
  102. result.plot_principal_nodal_stress(0, '1', show_edges=True, show_axes=True)
  103. # """
  104. nodenump, stress = result.principal_nodal_stress(0)
  105. # von first principle stress is the first column
  106. # must be nanmax as the shell element stress is not recorded
  107. mapdl.run('*GET, NODE_COUNT, NODE, ,COUNT')
  108. mapdl.run('*GET, ELEM_COUNT, ELEM, ,COUNT')
  109. mapdl.load_parameters()
  110. print(mapdl.parameters['NODE_COUNT'])
  111. print(mapdl.parameters['ELEM_COUNT'])
  112. s1max = angles
  113. s2max = angles
  114. srmax = angles
  115. stmax = angles
  116. for i in range(0, len(angles)):
  117. mapdl.run("LAYER, " + str(i + 1)) #
  118. mapdl.run("*DIM, DIM_TEST, ARRAY, ELEM_COUNT, 2")
  119. mapdl.run("ETABLE, TEST, S, 1, MAX")
  120. mapdl.run("*VGET, DIM_TEST(1,1), ETAB, TEST")
  121. mapdl.run("*DIM, OUT_STRESS, ARRAY, NODE_COUNT, 4")
  122. mapdl.run("*VGET, OUT_STRESS(1, 1), NODE,, S, 1")
  123. mapdl.run("*VGET, OUT_STRESS(1, 2), NODE,, S, 2")
  124. mapdl.run("*VGET, OUT_STRESS(1, 3), NODE,, S, X")
  125. mapdl.run("*VGET, OUT_STRESS(1, 4), NODE,, S, Y")
  126. params, arrays = mapdl.load_parameters()
  127. print(arrays['TEST'][0])
  128. s1max[i] = np.nanmax(arrays['OUT_STRESS'][:, 0])
  129. s2max[i] = np.nanmax(arrays['OUT_STRESS'][:, 1])
  130. srmax[i] = np.nanmax(arrays['OUT_STRESS'][:, 2])
  131. stmax[i] = np.nanmax(arrays['OUT_STRESS'][:, 3])
  132. # print(str(element_stress[0]))
  133. # s1max = np.nanmax(stresses)
  134. # nodenump, stress = result.principal_nodal_stress(0)
  135. # s1max[i] = np.nanmax(element_stress[:, -5])
  136. s1max = np.nanmax(s1max)
  137. s2max = np.nanmax(s2max)
  138. srmax = np.nanmax(srmax)
  139. stmax = np.nanmax(stmax)
  140. # von second principle stress is the first column
  141. # must be nanmax as the shell element stress is not recorded
  142. #s2max = np.nanmax(stress[:, -4])
  143. #nodenum, stress = result.nodal_stress(0)
  144. # von Mises stress is the last column
  145. # must be nanmax as the shell element stress is not recorded
  146. #srmax = np.nanmax(stress[:, -6])
  147. #stmax = np.nanmax(stress[:, -5])
  148. print(str(s1max))
  149. # """
  150. """
  151. # access results using ANSYS object
  152. resultfile = os.getcwd() + '\\ws\\file.rst'
  153. result = pyansys.read_binary(resultfile)
  154. # plot_nodal_solution doesnt work
  155. nodenump, stress = result.principal_nodal_stress(0)
  156. # von first principle stress is the first column
  157. # must be nanmax as the shell element stress is not recorded
  158. s1max = np.nanmax(stress[:, -5])
  159. # von second principle stress is the first column
  160. # must be nanmax as the shell element stress is not recorded
  161. s2max = np.nanmax(stress[:, -4])
  162. nodenum, stress = result.nodal_stress(0)
  163. # von Mises stress is the last column
  164. # must be nanmax as the shell element stress is not recorded
  165. srmax = np.nanmax(stress[:, -6])
  166. stmax = np.nanmax(stress[:, -5])
  167. print(str(s1max))
  168. # result.plot_nodal_solution(0)
  169. # """
  170. mapdl.exit()
  171. time.sleep(0.5)
  172. return s1max, s2max, srmax, stmax
  173. print(sim_rotor(
  174. [{
  175. "e11": 42.5E9 ,
  176. "e22": 11E9 ,
  177. "e33": 11E9 ,
  178. "pr12": 0.28 ,
  179. "pr13": 0.28 ,
  180. "pr23": 0.28 ,
  181. "dens": 1950 ,
  182. "g12": 4.2E9 ,
  183. "g13": 4.2E9 ,
  184. "g23": 2.56E9 ,
  185. "alp11": 5.7E-6 ,
  186. "alp22": 45E-6 ,
  187. "alp33": 45E-6 ,
  188. "k11": 0.72E3 ,
  189. "k22": 0.5E3 ,
  190. "k33": 0.5E3 ,
  191. "bet11": 0E-3,
  192. "bet22": 4E-3,
  193. "bet33": 4E-3,
  194. "d11": 4.4E-3,
  195. "d22": 3.1E-3,
  196. "d33": 3.1E-3
  197. }], [90, 0, 0, 0, 0, 0]))