ansys / pymapdl

Pythonic interface to MAPDL
https://mapdl.docs.pyansys.com
MIT License
423 stars 120 forks source link

Unable to animate_nodal_solution #362

Open Ahmed-Zeid opened 3 years ago

Ahmed-Zeid commented 3 years ago

Hello,

I am trying to perform a simple structural analysis of a compression spring (One end under pressure and the other fixed). I am able to plot the results. However, when I call: mapdl.result.animate_nodal_solution(0, add_text=False, window_size=[1800, 1080], cpos='xy', show_edges=True, loop=False, movie_filename='demo.gif') It generates a GIF file that is a 4 second long still picture with no animation. I have been experimenting with the method, and haven't been able to find a solution to the issue. Attched are my code and geometry file.

CodeGeometry.zip

Any help would be appreciated.

akaszynski commented 3 years ago

Quite likely, the issue is with recent updates with pyvista. Can you downgrade to pyvista==0.27.1?

Ahmed-Zeid commented 3 years ago

I was not able to downgrade to pyvista==0.27.1, as I was asked to downgrade pyansys, ansys-mapdl-core, and ansys-mapdl-reader as well. Even with the oldest versions available on PyPi for the later two, I was not able to downgrade pyvista as they both require at least pyvista==0.27.2 Is there another source for even older versions?

akaszynski commented 3 years ago

Oops, that's right then. There was a change in the API there that forced us to have a bottom limit to the module.

Since this is an issue with pyvista, I'm going to see if we can get a patch through to fix this.

Ahmed-Zeid commented 3 years ago

Great! Looking forward to the next update. Thanks Alex.

akaszynski commented 3 years ago

It generates a GIF file that is a 4 second long still picture with no animation. I have been experimenting with the method, and haven't been able to find a solution to the issue.

I think the issue is that the displacements are so small that you can't really see them. The best approach would be to turn up the displacement factor so you can visualize the displacements.

mapdl.result.animate_nodal_solution(0, add_text=False,
                                    window_size=[1800, 1080],
                                    cpos='xy', show_edges=True,
                                    displacement_factor=10,
                                    smooth_shading=True,
                                    nangles=200,
                                    loop=False, movie_filename='demo.mp4')

https://user-images.githubusercontent.com/11981631/110021200-af950280-7ce7-11eb-919f-32abb0e9bca1.mp4

I used a mp4 here since the file size is way smaller. Also, please note that I used nangles to increase the number of frames. This isn't documented well and I need to patch that.

akaszynski commented 3 years ago

Also, I really like this example. Would it possible to add this example to our example gallery?

I cleaned up the script a bit:

""" Script generated by ansys-mapdl-core version 0.57.3 """
import math
import numpy as np

from ansys.mapdl.core import launch_mapdl
mapdl = launch_mapdl(loglevel="WARNING", additional_switches='-smp')

mapdl.parain('SpringIII','x_t',f"'{os.getcwd()}',SOLIDS,0,0")

# print the current geometry
print(mapdl.geometry)

mapdl.prep7()

# Configure element type and material properties
mapdl.et(1, "SOLID187")
mapdl.mptemp("", "", "", "", "", "", "")
mapdl.mptemp(1, 0)
mapdl.mpdata("EX", 1, "", 2e11)
mapdl.mpdata("PRXY", 1, "", 0.3)

# configure mesher
mapdl.smrtsize(6)
mapdl.mshape(1, "3D")
mapdl.mshkey(0)

# mesh and print mesh stats
mapdl.vmesh("all")
print(mapdl.mesh)

# enter the solution 
mapdl.run("/SOL")
mapdl.antype(0)

# introduce boundary conditions
mapdl.flst(2, 1, 5, "ORDE", 1)
mapdl.fitem(2, 6)
mapdl.run("/GO")

mapdl.sfa("P51X", 1, "PRES", -100000)
mapdl.flst(2, 1, 5, "ORDE", 1)
mapdl.fitem(2, 5)
mapdl.run("/GO")
mapdl.da("P51X", "ALL", "")

mapdl.solve()
mapdl.finish()

mapdl.post1()

# mapdl.vplot(window_size=[1800, 1080], cpos='xy', screenshot= 'Volume.png', off_screen=True)

mapdl.eplot(window_size=[1800, 1080], cpos='xy', screenshot= 'Mesh.png',
            off_screen=True)

mapdl.result.plot_nodal_displacement(0, add_text=False,
                                     window_size=[1800, 1080],
                                     cpos='xy',
                                     screenshot= 'Deformation.png',
                                     stitle='Deformation (m)',
                                     show_displacement=True,
                                     off_screen=True)

mapdl.result.plot_principal_nodal_stress(0, 'SEQV', add_text=False,
                                         window_size=[1800, 1080],
                                         cpos='xy',
                                         screenshot= 'Stress.png',
                                         stitle='Von Messes Stress (MPa)',
                                         off_screen=True)

mapdl.result.animate_nodal_solution(0, add_text=False,
                                    window_size=[1800, 1080],
                                    cpos='xy', show_edges=True,
                                    displacement_factor=10,
                                    smooth_shading=True,
                                    nangles=200,
                                    loop=False, movie_filename='demo.mp4')

dism=[]
num, dis= mapdl.result.nodal_displacement(0)
for item in dis:
    temp=math.sqrt((item[0])**2+(item[1])**2+(item[2])**2)
    dism.append(temp)            

print("Max Displacement= ", max(dism))

von_mises = []
nnum, stress = mapdl.result.principal_nodal_stress(0)
for item in stress:
    von_mises.append(item[4])           
max_stress = max(von_mises)

print("Max Stress= ", max_stress)

mapdl.exit()
Ahmed-Zeid commented 3 years ago

It generates a GIF file that is a 4 second long still picture with no animation. I have been experimenting with the method, and haven't been able to find a solution to the issue.

I think the issue is that the displacements are so small that you can't really see them. The best approach would be to turn up the displacement factor so you can visualize the displacements.

mapdl.result.animate_nodal_solution(0, add_text=False,
                                    window_size=[1800, 1080],
                                    cpos='xy', show_edges=True,
                                    displacement_factor=10,
                                    smooth_shading=True,
                                    nangles=200,
                                    loop=False, movie_filename='demo.mp4')

demo.mp4 I used a mp4 here since the file size is way smaller. Also, please note that I used nangles to increase the number of frames. This isn't documented well and I need to patch that.

Hey Alex, thanks a lot for getting back to this. Unfortunately, I am still facing the same problem even after introducing a displacement factor and nangles .
Do you think there might me another cause of the problem such as dependent modules' versions or something? I am running latest versions of pyvista, ansys-mapdl-reader, ansys-mapdl-core currently available on pypi. Just out of curiosity, does pyansys have a wrapper method around ANCNTR or a way I can call it?

https://user-images.githubusercontent.com/55894561/110113299-5a7eec80-7dcc-11eb-9a1d-a015230b2324.mp4

Ahmed-Zeid commented 3 years ago

Also, I really like this example. Would it possible to add this example to our example gallery?

I cleaned up the script a bit:

""" Script generated by ansys-mapdl-core version 0.57.3 """
import math
import numpy as np

from ansys.mapdl.core import launch_mapdl
mapdl = launch_mapdl(loglevel="WARNING", additional_switches='-smp')

mapdl.parain('SpringIII','x_t',f"'{os.getcwd()}',SOLIDS,0,0")

# print the current geometry
print(mapdl.geometry)

mapdl.prep7()

# Configure element type and material properties
mapdl.et(1, "SOLID187")
mapdl.mptemp("", "", "", "", "", "", "")
mapdl.mptemp(1, 0)
mapdl.mpdata("EX", 1, "", 2e11)
mapdl.mpdata("PRXY", 1, "", 0.3)

# configure mesher
mapdl.smrtsize(6)
mapdl.mshape(1, "3D")
mapdl.mshkey(0)

# mesh and print mesh stats
mapdl.vmesh("all")
print(mapdl.mesh)

# enter the solution 
mapdl.run("/SOL")
mapdl.antype(0)

# introduce boundary conditions
mapdl.flst(2, 1, 5, "ORDE", 1)
mapdl.fitem(2, 6)
mapdl.run("/GO")

mapdl.sfa("P51X", 1, "PRES", -100000)
mapdl.flst(2, 1, 5, "ORDE", 1)
mapdl.fitem(2, 5)
mapdl.run("/GO")
mapdl.da("P51X", "ALL", "")

mapdl.solve()
mapdl.finish()

mapdl.post1()

# mapdl.vplot(window_size=[1800, 1080], cpos='xy', screenshot= 'Volume.png', off_screen=True)

mapdl.eplot(window_size=[1800, 1080], cpos='xy', screenshot= 'Mesh.png',
            off_screen=True)

mapdl.result.plot_nodal_displacement(0, add_text=False,
                                     window_size=[1800, 1080],
                                     cpos='xy',
                                     screenshot= 'Deformation.png',
                                     stitle='Deformation (m)',
                                     show_displacement=True,
                                     off_screen=True)

mapdl.result.plot_principal_nodal_stress(0, 'SEQV', add_text=False,
                                         window_size=[1800, 1080],
                                         cpos='xy',
                                         screenshot= 'Stress.png',
                                         stitle='Von Messes Stress (MPa)',
                                         off_screen=True)

mapdl.result.animate_nodal_solution(0, add_text=False,
                                    window_size=[1800, 1080],
                                    cpos='xy', show_edges=True,
                                    displacement_factor=10,
                                    smooth_shading=True,
                                    nangles=200,
                                    loop=False, movie_filename='demo.mp4')

dism=[]
num, dis= mapdl.result.nodal_displacement(0)
for item in dis:
    temp=math.sqrt((item[0])**2+(item[1])**2+(item[2])**2)
    dism.append(temp)            

print("Max Displacement= ", max(dism))

von_mises = []
nnum, stress = mapdl.result.principal_nodal_stress(0)
for item in stress:
    von_mises.append(item[4])           
max_stress = max(von_mises)

print("Max Stress= ", max_stress)

mapdl.exit()

Absolutely, glad I could help! Please note that the script should work for all helical compression springs 'with ground ends' (as long as the geometry file has been imported correctly of course). Also, if you're planning to share my drawing file, I am still under the investigation of a problem with vplot, as the volume plot always looks distorted and causes mapdl.vplot() to crash (despite the fact that this distortion doesn't affect the mesh generation nor the solution processes)

volume plot