gfk_plate.py 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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. # """
  13. # clear existing geometry
  14. mapdl.finish()
  15. mapdl.clear()
  16. th = 50 # [°C]
  17. tn = 50 # [°C]
  18. mapdl.prep7()
  19. # define Material
  20. for i in range(0, len(materials)):
  21. mapdl.mptemp(i + 1, th)
  22. mapdl.mpdata("EX", i + 1, "", materials[i]["e11"])
  23. mapdl.mpdata("EY", i + 1, "", materials[i]["e22"])
  24. mapdl.mpdata("EZ", i + 1, "", materials[i]["e33"])
  25. mapdl.mpdata("PRXY", i + 1, "", materials[i]["pr12"])
  26. mapdl.mpdata("PRXZ", i + 1, "", materials[i]["pr13"])
  27. mapdl.mpdata("PRYZ", i + 1, "", materials[i]["pr23"])
  28. mapdl.mpdata("DENS", i + 1, "", materials[i]["dens"])
  29. mapdl.mpdata("GXY", i + 1, "", materials[i]["g12"])
  30. mapdl.mpdata("GXZ", i + 1, "", materials[i]["g13"])
  31. mapdl.mpdata("GYZ", i + 1, "", materials[i]["g23"])
  32. # Waermeausdenungsk
  33. mapdl.mpdata("ALPX", i + 1, "", materials[i]["alp11"])
  34. mapdl.mpdata("ALPY", i + 1, "", materials[i]["alp22"])
  35. mapdl.mpdata("ALPZ", i + 1, "", materials[i]["alp33"])
  36. # Waermeleitfaehigk
  37. mapdl.mpdata("KXX", i + 1, "", materials[i]["k11"])
  38. mapdl.mpdata("KYY", i + 1, "", materials[i]["k22"])
  39. mapdl.mpdata("KZZ", i + 1, "", materials[i]["k33"])
  40. # Quellkoeffizient
  41. mapdl.mpdata("BETX", i + 1, "", materials[i]["bet11"])
  42. mapdl.mpdata("BETY", i + 1, "", materials[i]["bet22"])
  43. mapdl.mpdata("BETZ", i + 1, "", materials[i]["bet33"])
  44. # Diffusionskoeffizient
  45. mapdl.mpdata("DXX", i + 1, "", materials[i]["d11"])
  46. mapdl.mpdata("DYY", i + 1, "", materials[i]["d22"])
  47. mapdl.mpdata("DZZ", i + 1, "", materials[i]["d33"])
  48. mapdl.et(1, "SOLID186")
  49. mapdl.csys(1)
  50. mapdl.k(1, str(inner_diameter/2), 0, str(-thickness/2))
  51. mapdl.k(2, str(inner_diameter/2), 0, str(thickness/2))
  52. mapdl.k(3, str(outer_diameter/2), 0, str(thickness/2))
  53. mapdl.k(4, str(outer_diameter/2), 0, str(-thickness/2))
  54. mapdl.l(1, 2)
  55. mapdl.l(2, 3)
  56. mapdl.l(3, 4)
  57. mapdl.l(4, 1)
  58. mapdl.al(1, 2, 3, 4)
  59. mapdl.k(5, 0, 0, str(thickness/2))
  60. mapdl.k(6, 0, 0, str(-thickness/2))
  61. mapdl.run("VROT,1,,,,,,5,6")
  62. arcdiv = 20*4
  63. darc = 360/arcdiv
  64. mapdl.lsel("S", "LOC", "X", str(inner_diameter/2))
  65. mapdl.lsel("R", "LOC", "Z", str(-thickness/2))
  66. mapdl.lesize("ALL", "", "", str(arcdiv/4))
  67. mapdl.lsel("S", "LOC", "X", str(inner_diameter/2))
  68. mapdl.lsel("R", "LOC", "Z", str(thickness/2))
  69. mapdl.lesize("ALL", "", "", str(arcdiv/4))
  70. mapdl.lsel("S", "LOC", "X", str(outer_diameter/2))
  71. mapdl.lsel("R", "LOC", "Z", str(-thickness/2))
  72. mapdl.lesize("ALL", "", "", str(arcdiv/4))
  73. mapdl.lsel("S", "LOC", "X", str(outer_diameter/2))
  74. mapdl.lsel("R", "LOC", "Z", str(thickness/2))
  75. mapdl.lesize("ALL", "", "", str(arcdiv/4))
  76. for i in range(0, 4):
  77. mapdl.lsel("S", "LOC", "Y", str(90*i))
  78. mapdl.lsel("R", "LOC", "Z", str(-thickness/2))
  79. mapdl.lesize("ALL", "", "", str(arcdiv/4))
  80. mapdl.lsel("S", "LOC", "Y", str(90*i))
  81. mapdl.lsel("R", "LOC", "Z", str(thickness/2))
  82. mapdl.lesize("ALL", "", "", str(arcdiv/4))
  83. mapdl.lsel("S", "LOC", "Y", str(90*i))
  84. mapdl.lesize("ALL", "", "", str(len(angles)))
  85. mapdl.lsel("ALL")
  86. mapdl.mshape(0, "3D")
  87. mapdl.mshkey(1)
  88. mapdl.vmesh("ALL")
  89. # mapdl.eplot("ALL")
  90. for j in range(1, len(angles)+1):
  91. for i in range(0, 20*4):
  92. mapdl.csys(1)
  93. mapdl.esel("S", "CENT", "Y", str(darc*(i + 0.5)))
  94. mapdl.esel("R", "CENT", "Z", str(thickness*(-1/2+1/len(angles)*(j-1))), str(thickness*(-1/2+1/len(angles)*j)), str(thickness/len(angles)/2))
  95. mapdl.local(str(j*100+i), 0, 0, 0, 0, str(angles[j-1]+darc*(i + 0.5)))
  96. mapdl.emodif("all", "ESYS", str(j*100+i))
  97. if len(angles) == len(materials):
  98. mapdl.emodif("all", "MAT", str(j))
  99. mapdl.esel("ALL")
  100. mapdl.run("/SOLU")
  101. mapdl.csys(1)
  102. mapdl.omega("", "", omega)
  103. mapdl.nsel("S", "LOC", "X", inner_diameter / 2)
  104. mapdl.d("ALL", "UX", 0)
  105. mapdl.d("ALL", "UY", 0)
  106. # D,ALL,ROTX,0
  107. # D,ALL,ROTY,0
  108. # D,ALL,ROTZ,0
  109. mapdl.nsel("R", "LOC", "Z", 0)
  110. mapdl.d("ALL", "UZ", 0)
  111. mapdl.run("ALLS")
  112. mapdl.outres("ALL", "ALL")
  113. mapdl.solve()
  114. mapdl.finish()
  115. # """
  116. # mapdl.run("/INPUT, C:/Users/Willi/Documents/projects/gfk-plate/script/01_Modell.inp")
  117. # mapdl.solve()
  118. # mapdl.finish()
  119. mapdl.run("/Post1")
  120. result = mapdl.result
  121. # mapdl.aplot()
  122. # result.plot_principal_nodal_stress(0, '1', show_edges=True, show_axes=True)
  123. result.plot_nodal_solution(0, 'z', show_displacement=True)
  124. result.plot_principal_nodal_stress(0, 'S1', show_edges=True, show_axes=True)
  125. # """
  126. nodenump, stress = result.principal_nodal_stress(0)
  127. # von first principle stress is the first column
  128. # must be nanmax as the shell element stress is not recorded
  129. """
  130. mapdl.run('*GET, NODE_COUNT, NODE, ,COUNT')
  131. mapdl.run('*GET, ELEM_COUNT, ELEM, ,COUNT')
  132. mapdl.load_parameters()
  133. print(mapdl.parameters['NODE_COUNT'])
  134. print(mapdl.parameters['ELEM_COUNT'])
  135. s1max = angles
  136. s2max = angles
  137. srmax = angles
  138. stmax = angles
  139. for i in range(0, len(angles)):
  140. mapdl.run("LAYER, " + str(i + 1)) #
  141. mapdl.run("*DIM, DIM_TEST, ARRAY, ELEM_COUNT, 2")
  142. mapdl.run("ETABLE, TEST, S, 1, MAX")
  143. mapdl.run("*VGET, DIM_TEST(1,1), ETAB, TEST")
  144. mapdl.run("*DIM, OUT_STRESS, ARRAY, NODE_COUNT, 4")
  145. mapdl.run("*VGET, OUT_STRESS(1, 1), NODE,, S, 1")
  146. mapdl.run("*VGET, OUT_STRESS(1, 2), NODE,, S, 2")
  147. mapdl.run("*VGET, OUT_STRESS(1, 3), NODE,, S, X")
  148. mapdl.run("*VGET, OUT_STRESS(1, 4), NODE,, S, Y")
  149. params, arrays = mapdl.load_parameters()
  150. print(arrays['TEST'][0])
  151. s1max[i] = np.nanmax(arrays['OUT_STRESS'][:, 0])
  152. s2max[i] = np.nanmax(arrays['OUT_STRESS'][:, 1])
  153. srmax[i] = np.nanmax(arrays['OUT_STRESS'][:, 2])
  154. stmax[i] = np.nanmax(arrays['OUT_STRESS'][:, 3])
  155. # print(str(element_stress[0]))
  156. # s1max = np.nanmax(stresses)
  157. # nodenump, stress = result.principal_nodal_stress(0)
  158. # s1max[i] = np.nanmax(element_stress[:, -5])
  159. s1max = np.nanmax(s1max)
  160. s2max = np.nanmax(s2max)
  161. srmax = np.nanmax(srmax)
  162. stmax = np.nanmax(stmax)
  163. # """
  164. nodenump, stress = result.principal_nodal_stress(0)
  165. # von first principle stress is the first column
  166. # must be nanmax as the shell element stress is not recorded
  167. s1max = np.nanmax(stress[:, -5])
  168. # von second principle stress is the first column
  169. # must be nanmax as the shell element stress is not recorded
  170. s2max = np.nanmax(stress[:, -4])
  171. nodenum, stress = result.nodal_stress(0)
  172. # von Mises stress is the last column
  173. # must be nanmax as the shell element stress is not recorded
  174. srmax = np.nanmax(stress[:, -6])
  175. stmax = np.nanmax(stress[:, -5])
  176. # von second principle stress is the first column
  177. # must be nanmax as the shell element stress is not recorded
  178. #s2max = np.nanmax(stress[:, -4])
  179. #nodenum, stress = result.nodal_stress(0)
  180. # von Mises stress is the last column
  181. # must be nanmax as the shell element stress is not recorded
  182. #srmax = np.nanmax(stress[:, -6])
  183. #stmax = np.nanmax(stress[:, -5])
  184. print(str(s1max))
  185. # """
  186. """
  187. # access results using ANSYS object
  188. resultfile = os.getcwd() + '\\ws\\file.rst'
  189. result = pyansys.read_binary(resultfile)
  190. # plot_nodal_solution doesnt work
  191. nodenump, stress = result.principal_nodal_stress(0)
  192. # von first principle stress is the first column
  193. # must be nanmax as the shell element stress is not recorded
  194. s1max = np.nanmax(stress[:, -5])
  195. # von second principle stress is the first column
  196. # must be nanmax as the shell element stress is not recorded
  197. s2max = np.nanmax(stress[:, -4])
  198. nodenum, stress = result.nodal_stress(0)
  199. # von Mises stress is the last column
  200. # must be nanmax as the shell element stress is not recorded
  201. srmax = np.nanmax(stress[:, -6])
  202. stmax = np.nanmax(stress[:, -5])
  203. print(str(s1max))
  204. # result.plot_nodal_solution(0)
  205. # """
  206. mapdl.exit()
  207. time.sleep(0.5)
  208. return s1max, s2max, srmax, stmax
  209. print(sim_rotor(
  210. [{
  211. "e11": 42.5E9 ,
  212. "e22": 11E9 ,
  213. "e33": 11E9 ,
  214. "pr12": 0.28 ,
  215. "pr13": 0.28 ,
  216. "pr23": 0.28 ,
  217. "dens": 1950 ,
  218. "g12": 4.2E9 ,
  219. "g13": 4.2E9 ,
  220. "g23": 2.56E9 ,
  221. "alp11": 5.7E-6 ,
  222. "alp22": 45E-6 ,
  223. "alp33": 45E-6 ,
  224. "k11": 0.72E3 ,
  225. "k22": 0.5E3 ,
  226. "k33": 0.5E3 ,
  227. "bet11": 0E-3,
  228. "bet22": 4E-3,
  229. "bet33": 4E-3,
  230. "d11": 4.4E-3,
  231. "d22": 3.1E-3,
  232. "d33": 3.1E-3
  233. }], [90, 0, 0, 0, 0, 0]))