How to plot shell data at different integration points for LSDYNA using PyDPF?

Member, Employee Posts: 4
First Comment
✭✭✭

How to plot shell data at different integration points for LSDYNA using PyDPF?

Comments

  • Member, Employee Posts: 4
    First Comment
    ✭✭✭

    Here is an example using PyDPF which also includes other types of results like animations and plots.

    Paths must be updated accordingly.

    1. import matplotlib.pyplot as plt
    2. from ansys.dpf import core as dpf
    3. from ansys.dpf.core.plotter import DpfPlotter
    4.  
    5. """Adding an r or double \\ should fix path issues"""
    6. d3plot_path = r"D:\PATHTOD3PLOT\d3plot"
    7. """ACTunits file gets generated when using WB-LSDYNA to solve the analysis. It can be created manually too"""
    8. units_path = r"D:\PATHTOACTUNITS\name.actunits"
    9. ds = dpf.DataSources()
    10. ds.set_result_file_path(d3plot_path, "d3plot")
    11. ds.add_file_path(units_path, "actunits")
    12. model = dpf.Model(ds)
    13. print(model)
    14.  
    15. """ model.plot() # Plots the mesh"""
    16.  
    17. """5 is the d3plot state"""
    18. stress_vm = model.results.stress_von_mises(time_scoping=[5])
    19. disp = model.results.displacement(time_scoping=[5])
    20. fields = disp.outputs.fields_container()
    21. """2 is the 3rd displacement component, i.e. Z"""
    22. field = fields.select_component(2)[0]
    23.  
    24. mesh = model.metadata.meshed_region
    25. meshes = dpf.operators.mesh.split_mesh(mesh=mesh, property="eltype").eval()
    26. print(meshes)
    27. print(meshes[0])
    28. print(meshes[1])
    29.  
    30. disp_f = model.results.displacement(time_scoping=[5]).eval()
    31. scop = dpf.Scoping(ids=[1], location=dpf.locations.nodal)
    32. stress_op = model.results.stress(time_scoping=[5])
    33.  
    34. disp_f_solid = model.results.displacement(time_scoping=[5], mesh_scoping=meshes[1].nodes.scoping).eval()
    35. print(disp_f_solid[0])
    36. disp_f_shell = model.results.displacement(time_scoping=[5], mesh_scoping=meshes[0].nodes.scoping).eval()
    37. print(disp_f_shell[0])
    38.  
    39. stress_f_solid = model.results.stress(time_scoping=[5], mesh_scoping=meshes[1].elements.scoping).eval()
    40. stress_f_solid_x = stress_f_solid.select_component(0)
    41. print(stress_f_solid[0])
    42. stress_f_shell = model.results.stress(time_scoping=[5], mesh_scoping=meshes[0].elements.scoping).eval()
    43.  
    44. """It seems to be wrong in the documentation - Top=3 Bot=0 Mid=1"""
    45. stress_f_shell_top = dpf.operators.utility.change_shell_layers(fields_container=stress_f_shell, e_shell_layer=3,
    46. mesh=meshes[0]).eval()
    47. stress_f_shell_top_x = stress_f_shell_top.select_component(0)
    48. print(stress_f_shell[0])
    49.  
    50. pl = DpfPlotter()
    51. pl.add_field(stress_f_solid_x[0], meshes[1], deform_by=disp_f_solid[0])
    52. pl.add_field(stress_f_shell_top_x[0], meshes[0], deform_by=disp_f_shell[0])
    53. pl.show_figure()
    54.  
    55. sargs_shell = dict(title="Stress X Shell Top", fmt="%.3e", title_font_size=20, label_font_size=16)
    56. stress_f_shell_top[0].plot(deform_by=disp_f_shell[0], scalar_bar_args=sargs_shell)
    57.  
    58. sargs = dict(title="Displacement", fmt="%.3e", title_font_size=20, label_font_size=16)
    59. u_all = model.results.displacement.on_all_time_freqs.eval()
    60. u_all.animate(deform_by=u_all, save_as=r"D:\PATHTOSAVEANIMATION\name.gif",
    61. scalar_bar_args=sargs)
    62.  
    63. """These come from the d3plot file"""
    64. K = model.results.global_kinetic_energy().eval()
    65. U = model.results.global_internal_energy().eval()
    66. H = model.results.global_total_energy().eval()
    67.  
    68. plt.plot(K.time_freq_support.time_frequencies.data, K[0].data, label="Kinetic")
    69. plt.plot(U.time_freq_support.time_frequencies.data, U[0].data, label="Internal")
    70. plt.plot(H.time_freq_support.time_frequencies.data, H[0].data, label="Total")
    71. plt.xlabel("Time ({:s})".format(K.time_freq_support.time_frequencies.unit))
    72. plt.ylabel("Energies ({:s})".format(K[0].unit))
    73. plt.legend()
    74. plt.show()
    75.  
    76.  
    77. binout_path = r"D:\PATHTOBINOUT\binout0000"
    78. dp = dpf.DataSources()
    79. dp.set_result_file_path(binout_path, "binout")
    80. dp.add_file_path(units_path, "actunits")
    81. model_binout = dpf.Model(dp)
    82.  
    83. """These come from the binout file"""
    84. part_sco = dpf.Scoping(ids=[1, 2], location="part")
    85. PKE_op = model_binout.results.part_kinetic_energy()
    86. PKE_op.inputs.entity_scoping.connect(part_sco)
    87. PKE = PKE_op.eval()
    88. PIE_op = model_binout.results.part_internal_energy()
    89. PIE_op.inputs.entity_scoping.connect(part_sco)
    90. PIE = PIE_op.eval()
    91.  
    92. rescope_op = dpf.operators.scoping.rescope()
    93. rescope_op.inputs.fields.connect(PKE.time_freq_support.time_frequencies)
    94. rescope_op.inputs.mesh_scoping.connect(PKE[0].scoping)
    95. t_field = rescope_op.outputs.fields_as_field()
    96. t_vals = t_field.data
    97.  
    98. plt.plot(t_vals, PKE.get_field({"part": 1}).data, label="Kinetic, Part 1")
    99. plt.plot(t_vals, PKE.get_field({"part": 2}).data, label="Kinetic, Part 2")
    100. plt.plot(t_vals, PIE.get_field({"part": 1}).data, label="Internal, Part 1")
    101. plt.plot(t_vals, PIE.get_field({"part": 2}).data, label="Internal, Part 2")
    102. plt.xlabel("Time ({:s})".format(t_field.unit))
    103. plt.ylabel("Energy ({:s})".format(PIE.get_field({"part": 1}).unit))
    104. plt.legend()
    105. plt.show()

Welcome!

It looks like you're new here. Sign in or register to get started.