|
| 1 | +# Copyright (C) 2020 - 2024 ANSYS, Inc. and/or its affiliates. |
| 2 | +# SPDX-License-Identifier: MIT |
| 3 | +# |
| 4 | +# |
| 5 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | +# of this software and associated documentation files (the "Software"), to deal |
| 7 | +# in the Software without restriction, including without limitation the rights |
| 8 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | +# copies of the Software, and to permit persons to whom the Software is |
| 10 | +# furnished to do so, subject to the following conditions: |
| 11 | +# |
| 12 | +# The above copyright notice and this permission notice shall be included in all |
| 13 | +# copies or substantial portions of the Software. |
| 14 | +# |
| 15 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 | +# SOFTWARE. |
| 22 | + |
| 23 | +""" |
| 24 | +.. _lsdyna_operators: |
| 25 | +
|
| 26 | +Results extraction and analysis from LS-DYNA sources |
| 27 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 28 | +
|
| 29 | +This example provides an overview of the LS-DYNA beam results manipulations. |
| 30 | +
|
| 31 | +.. note:: |
| 32 | + This example requires DPF 6.1 (ansys-dpf-server-2023-2-pre0) or above. |
| 33 | + For more information, see :ref:`ref_compatibility`. |
| 34 | +
|
| 35 | +""" |
| 36 | + |
| 37 | +import matplotlib.pyplot as plt |
| 38 | +from ansys.dpf import core as dpf |
| 39 | +from ansys.dpf.core import examples |
| 40 | +from ansys.dpf.core import operators as ops |
| 41 | + |
| 42 | +############################################################################### |
| 43 | +# d3plot file results extraction |
| 44 | +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 45 | +# Create the model and print its contents. This LS-DYNA d3plot file contains |
| 46 | +# several individual results, each at different times. The d3plot file does not |
| 47 | +# contain information related to Units. In this case, as the simulation was run |
| 48 | +# through Mechanical, a file.actunits file is produced. If this file is |
| 49 | +# supplemented in the data_sources, the units will be correctly fetched for all |
| 50 | +# results in the file as well as for the mesh. |
| 51 | + |
| 52 | +d3plot = examples.download_d3plot_beam() |
| 53 | +ds = dpf.DataSources() |
| 54 | +ds.set_result_file_path(d3plot[0], "d3plot") |
| 55 | +ds.add_file_path(d3plot[3], "actunits") |
| 56 | +my_model = dpf.Model(ds) |
| 57 | +# print(model) |
| 58 | + |
| 59 | +############################################################################### |
| 60 | +# The model has solid (3D) elements and beam (1D) elements. Some of the results |
| 61 | +# only apply to one type of elements (such as the stress tensor for solids, or |
| 62 | +# the axial force for beams, for example). |
| 63 | + |
| 64 | +# By splitting the mesh by element shape we see that the ball is made by the solid |
| 65 | +# 3D elements and the plate by the beam 1D elements |
| 66 | + |
| 67 | +my_meshed_region = my_model.metadata.meshed_region |
| 68 | + |
| 69 | +my_meshes = ops.mesh.split_mesh(mesh=my_meshed_region, property="elemental").eval() |
| 70 | +# print(my_meshes) |
| 71 | +############################################################################### |
| 72 | +# Ball |
| 73 | + |
| 74 | +# print(my_meshes[0]) |
| 75 | +# my_meshes[0].plot() |
| 76 | + |
| 77 | +############################################################################### |
| 78 | +# Plate |
| 79 | + |
| 80 | +# print(my_meshes[1]) |
| 81 | +# my_meshes[1].plot() |
| 82 | + |
| 83 | + |
| 84 | +############################################################################### |
| 85 | +# We can split the mesh scoping so it's easier to chose from which body we are |
| 86 | +# analysing the results |
| 87 | + |
| 88 | +my_meshes_scopings = ops.scoping.split_on_property_type(mesh=my_meshed_region).eval() |
| 89 | +my_time_scoping = my_model.metadata.time_freq_support.time_frequencies |
| 90 | +# For example the ball velocity |
| 91 | +v = my_model.results.velocity(time_scoping=my_time_scoping).eval() |
| 92 | + |
| 93 | + |
| 94 | +# Forces |
| 95 | + |
| 96 | +############################################################################### |
| 97 | +# compare results in different time steps |
| 98 | +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 99 | + |
| 100 | +Sforces = my_model.results.beam_s_shear_force(mesh_scoping=my_meshes_scopings[1]).eval() |
| 101 | +Sforces2 = my_model.results.beam_s_shear_force(mesh_scoping=my_meshes_scopings[0]).eval() |
| 102 | + |
| 103 | +comparison_plot = dpf.plotter.DpfPlotter |
| 104 | +comparison_plot.add_field(field=Sforces, meshed_region=my_meshes[1]) |
| 105 | +comparison_plot.add_field(field=Sforces2, meshed_region=my_meshes[0]) |
| 106 | + |
| 107 | +comparison_plot.show_figure() |
0 commit comments