Skip to content

Commit d860a33

Browse files
new ls dyna example
1 parent 8c3a06c commit d860a33

File tree

1 file changed

+68
-26
lines changed

1 file changed

+68
-26
lines changed

examples/14-lsdyna/01-lsdyna_beam.py

Lines changed: 68 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
ds.set_result_file_path(d3plot[0], "d3plot")
5555
ds.add_file_path(d3plot[3], "actunits")
5656
my_model = dpf.Model(ds)
57-
# print(model)
57+
# print(my_model)
5858

5959
###############################################################################
6060
# The model has solid (3D) elements and beam (1D) elements. Some of the results
@@ -64,55 +64,97 @@
6464
# By splitting the mesh by element shape we see that the ball is made by the solid
6565
# 3D elements and the plate by the beam 1D elements
6666

67+
# Define the analysis mesh
6768
my_meshed_region = my_model.metadata.meshed_region
6869

70+
# Get separate meshes for each body
6971
my_meshes = ops.mesh.split_mesh(
7072
mesh=my_meshed_region, property=dpf.common.elemental_properties.element_shape
7173
).eval()
72-
my_ball_mesh = my_meshes.get_mesh(label_space_or_index={"body": 1, "elshape": 1})
73-
my_plate_mesh = my_meshes.get_mesh(label_space_or_index={"body": 2, "elshape": 2})
74+
75+
# Define the meshes in separate variables
76+
ball_mesh = my_meshes.get_mesh(label_space_or_index={"body": 1, "elshape": 1})
77+
plate_mesh = my_meshes.get_mesh(label_space_or_index={"body": 2, "elshape": 2})
78+
7479
# print(my_meshes)
7580
###############################################################################
7681
# Ball
7782

78-
# print(my_meshes[0])
79-
# my_meshes[0].plot()
83+
# print(ball_mesh)
84+
# my_ball_mesh.plot()
8085

8186
###############################################################################
8287
# Plate
8388

84-
# print(my_meshes[1])
85-
# my_meshes[1].plot()
86-
89+
# print(my_plate_mesh)
90+
# my_plate_mesh.plot()
8791

8892
###############################################################################
89-
# We can split the mesh scoping so it's easier to chose from which body we are
90-
# analysing the results
9193

9294
my_meshes_scopings = ops.scoping.split_on_property_type(mesh=my_meshed_region).eval()
93-
my_ball_scoping = my_meshes_scopings.get_scoping(label_space_or_index={"elshape": 1})
94-
my_plate_scoping = my_meshes_scopings.get_scoping(label_space_or_index={"elshape": 2})
95-
96-
my_time_scoping = my_model.metadata.time_freq_support.time_frequencies
97-
# For example the ball velocity
98-
v = my_model.results.velocity(time_scoping=my_time_scoping).eval()
9995

96+
# Define the mesh scoping in separate variables
97+
# Here we have a elemental location
98+
ball_scoping = my_meshes_scopings.get_scoping(label_space_or_index={"elshape": 1})
99+
plate_scoping = my_meshes_scopings.get_scoping(label_space_or_index={"elshape": 2})
100100

101-
# Forces
102-
101+
# We will need a nodal location, so we have to transpose the mesh scoping from elemental to nodal
102+
ball_scoping_nodal = dpf.operators.scoping.transpose(
103+
mesh_scoping=ball_scoping, meshed_region=my_meshed_region
104+
).eval()
105+
plate_scoping_nodal = dpf.operators.scoping.transpose(
106+
mesh_scoping=plate_scoping, meshed_region=my_meshed_region
107+
).eval()
103108
###############################################################################
104-
# compare results in different time steps
105-
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
106-
107-
Sballforces = my_model.results.beam_s_shear_force(mesh_scoping=my_ball_scoping).eval()
108-
Splateforces = my_model.results.beam_s_shear_force(mesh_scoping=my_plate_scoping).eval()
109-
109+
# Comparing results in different time steps
110+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
111+
# 1) Define the time steps
112+
time_steps_set = [2, 6, 12]
113+
j = -400
114+
# 2) Copy the mesh of interest. Here it is the plate mesh that we copy along the X axis
115+
for i in time_steps_set:
116+
# Copy the mesh
117+
globals()[f"plate_mesh_{i}"] = plate_mesh.deep_copy()
118+
119+
# 3) Get the plot coordinates that will be changed
120+
coords_to_update = globals()[f"plate_mesh_{i}"].nodes.coordinates_field
121+
# 4) Define the coordinates where the new mesh will be placed
122+
overall_field = dpf.fields_factory.create_3d_vector_field(
123+
num_entities=1, location=dpf.locations.overall
124+
)
125+
overall_field.append(data=[j, 0.0, 0.0], scopingid=1)
126+
127+
# 5) Define the updated coordinates
128+
new_coordinates = ops.math.add(fieldA=coords_to_update, fieldB=overall_field).eval()
129+
coords_to_update.data = new_coordinates.data
130+
131+
# 6) Extract the result, here we start by getting the displacement
132+
globals()[f"my_displacement_{i}"] = my_model.results.displacement(
133+
time_scoping=i, mesh_scoping=plate_scoping_nodal
134+
).eval()[0]
135+
136+
# Increment the coordinate value for the loop
137+
j = j - 400
138+
###############################################################################
139+
# Use the :class: `Plotter <ansys.dpf.core.plotter.DpfPlotter>` class to add the plots
140+
# in the same image
110141

111142
comparison_plot = dpf.plotter.DpfPlotter()
143+
112144
comparison_plot.add_field(
113-
field=Sballforces.get_field(label_space_or_index={"time": 12}), meshed_region=my_ball_mesh
145+
field=my_displacement_2, meshed_region=plate_mesh_2, deform_by=my_displacement_2
114146
)
115147
comparison_plot.add_field(
116-
field=Splateforces.get_field(label_space_or_index={"time": 12}), meshed_region=my_plate_mesh
148+
field=my_displacement_6, meshed_region=plate_mesh_6, deform_by=my_displacement_6
117149
)
150+
comparison_plot.add_field(
151+
field=my_displacement_12, meshed_region=plate_mesh_12, deform_by=my_displacement_12
152+
)
153+
118154
comparison_plot.show_figure()
155+
156+
###############################################################################
157+
# For example the ball velocity
158+
# v = my_model.results.velocity(time_scoping=my_time_scoping, mesh_scoping=ball_scoping).eval()
159+
160+
###############################################################################

0 commit comments

Comments
 (0)