gfk_plate.py 5.3 KB

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