|
54 | 54 | ds.set_result_file_path(d3plot[0], "d3plot") |
55 | 55 | ds.add_file_path(d3plot[3], "actunits") |
56 | 56 | my_model = dpf.Model(ds) |
57 | | -# print(model) |
| 57 | +# print(my_model) |
58 | 58 |
|
59 | 59 | ############################################################################### |
60 | 60 | # The model has solid (3D) elements and beam (1D) elements. Some of the results |
|
64 | 64 | # By splitting the mesh by element shape we see that the ball is made by the solid |
65 | 65 | # 3D elements and the plate by the beam 1D elements |
66 | 66 |
|
| 67 | +# Define the analysis mesh |
67 | 68 | my_meshed_region = my_model.metadata.meshed_region |
68 | 69 |
|
| 70 | +# Get separate meshes for each body |
69 | 71 | my_meshes = ops.mesh.split_mesh( |
70 | 72 | mesh=my_meshed_region, property=dpf.common.elemental_properties.element_shape |
71 | 73 | ).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 | + |
74 | 79 | # print(my_meshes) |
75 | 80 | ############################################################################### |
76 | 81 | # Ball |
77 | 82 |
|
78 | | -# print(my_meshes[0]) |
79 | | -# my_meshes[0].plot() |
| 83 | +# print(ball_mesh) |
| 84 | +# my_ball_mesh.plot() |
80 | 85 |
|
81 | 86 | ############################################################################### |
82 | 87 | # Plate |
83 | 88 |
|
84 | | -# print(my_meshes[1]) |
85 | | -# my_meshes[1].plot() |
86 | | - |
| 89 | +# print(my_plate_mesh) |
| 90 | +# my_plate_mesh.plot() |
87 | 91 |
|
88 | 92 | ############################################################################### |
89 | | -# We can split the mesh scoping so it's easier to chose from which body we are |
90 | | -# analysing the results |
91 | 93 |
|
92 | 94 | 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() |
99 | 95 |
|
| 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}) |
100 | 100 |
|
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() |
103 | 108 | ############################################################################### |
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 |
110 | 141 |
|
111 | 142 | comparison_plot = dpf.plotter.DpfPlotter() |
| 143 | + |
112 | 144 | 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 |
114 | 146 | ) |
115 | 147 | 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 |
117 | 149 | ) |
| 150 | +comparison_plot.add_field( |
| 151 | + field=my_displacement_12, meshed_region=plate_mesh_12, deform_by=my_displacement_12 |
| 152 | +) |
| 153 | + |
118 | 154 | 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