Skip to content

Commit 182787c

Browse files
Improve geometry examples
1 parent aa3a4f1 commit 182787c

File tree

3 files changed

+37
-21
lines changed

3 files changed

+37
-21
lines changed

examples/05-plotting/07-plot_on_points.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""
22
.. _plot_on_points:
33
4-
Plot on geometry elements
5-
~~~~~~~~~~~~~~~~~~~~~~~~~
4+
Plot on Points object
5+
~~~~~~~~~~~~~~~~~~~~~
66
This example shows how to plot a Field on a Points object.
77
88
.. note::
@@ -48,6 +48,12 @@
4848
]
4949
)
5050

51+
###############################################################################
52+
# Get Points object properties
53+
print(f"Total number of points: n_points = {points.n_points}")
54+
print(f"Get points' coordinates:\n {points.coordinates.data}")
55+
print(f"Access first point: {points[0]}")
56+
5157
###############################################################################
5258
# Get mesh from model
5359
mesh = model.metadata.meshed_region
@@ -67,7 +73,7 @@
6773
# Map displacement field to Points
6874
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6975
# Use :class:`on_coordinates <ansys.dpf.core.operators.mapping.on_coordinates.
70-
# on_coordinates>`: mapping opretor
76+
# on_coordinates>` mapping opretor
7177
disp = model.results.displacement
7278
mapping_operator = ops.mapping.on_coordinates(
7379
fields_container=disp,

examples/05-plotting/08-plot_on_lines.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@
3737
# Create line passing through the geometry's diagonal
3838
line = Line([[0.03, 0.03, 0.05], [0.0, 0.06, 0.0]], n_points=50)
3939

40+
###############################################################################
41+
# Get Line object properties
42+
print(f"Coordinates of the two points:\n {line.coordinates.data}")
43+
print(f"Direction of the line = {line.direction}")
44+
print(f"Length of the line = {line.length}")
45+
print(f"Path of the line =\n {line.path}")
46+
assert len(line.path) == line.n_points
47+
4048
###############################################################################
4149
# Get mesh from model
4250
mesh = model.metadata.meshed_region
@@ -56,7 +64,7 @@
5664
###############################################################################
5765
# Map displacement field to Line
5866
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
59-
# Use :class:`on_coordinates <ansys.dpf.core.operators.mapping.on_coordinates.on_coordinates>`:
67+
# Use :class:`on_coordinates <ansys.dpf.core.operators.mapping.on_coordinates.on_coordinates>`
6068
# mapping opretor to obtain the displacement Field on the line:
6169
disp = model.results.displacement
6270
mapping_operator = ops.mapping.on_coordinates(
@@ -86,7 +94,7 @@
8694
# 2D Plot displacement field alogn line length
8795
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8896
# Get norm of the displacement using
89-
# :class:`norm <ansys.dpf.core.operators.math.norm.norm>`:
97+
# :class:`norm <ansys.dpf.core.operators.math.norm.norm>`
9098
norm_op = dpf.operators.math.norm() # operator instantiation
9199
norm_op.inputs.field.connect(field_line)
92100
norm = norm_op.outputs.field()

examples/05-plotting/09-plot_on_planes.py

+18-16
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,17 @@
3434
# ~~~~~~~~~~~~~~~~~~~
3535
# Create plane passing through the mid point
3636
plane1 = Plane(
37-
[0.015, 0.045, 0.015],
38-
[1, 1, 0],
37+
center=[0.015, 0.045, 0.015],
38+
normal=[1, 1, 0],
3939
width=0.03,
4040
height=0.03,
4141
n_cells_x=10,
4242
n_cells_y=10,
4343
)
4444

4545
plane2 = Plane(
46-
[0.015, 0.045, 0.015],
47-
[1, 1, 1],
46+
center=[0.015, 0.045, 0.015],
47+
normal=[1, 1, 1],
4848
width=0.03,
4949
height=0.03,
5050
n_cells_x=10,
@@ -69,11 +69,20 @@
6969
plane1.plot(mesh, cpos=cpos)
7070
plane2.plot(mesh, cpos=cpos)
7171

72+
###############################################################################
73+
# Get plane's properties
74+
print(f"Center of the plane = {plane1.center}")
75+
print(f"Normal direction of the plane = {plane1.normal_dir}")
76+
print(f"Number of cells in the x axis to discretize the plane = {plane1.n_cells_x}")
77+
print(f"Number of cells in the y axis to discretize the plane = {plane1.n_cells_y}")
78+
print(f"Height of the discretized plane = {plane1.height}")
79+
print(f"Width of the discretized plane = {plane1.width}")
80+
7281
###############################################################################
7382
# Map displacements to plane
7483
# ~~~~~~~~~~~~~~~~~~~~~~~~~~
7584
# Map displacement field to points in plane object using
76-
# :class:`on_coordinates <ansys.dpf.core.operators.mapping.on_coordinates.on_coordinates>:`
85+
# :class:`on_coordinates <ansys.dpf.core.operators.mapping.on_coordinates.on_coordinates>`
7786
disp = model.results.displacement
7887
mapping_operator = ops.mapping.on_coordinates(
7988
fields_container=disp,
@@ -91,20 +100,15 @@
91100
# Extract the only field (0th entry) available in ``disp_plane1_fc`` FieldsContainer
92101
field_plane1 = disp_plane1_fc[0]
93102

103+
###############################################################################
104+
# Repeat process for plane2
94105
mapping_operator = ops.mapping.on_coordinates(
95106
fields_container=disp,
96107
coordinates=plane2.mesh.nodes.coordinates_field,
97108
create_support=True,
98109
mesh=mesh,
99110
)
100111
disp_plane2_fc = mapping_operator.outputs.fields_container()
101-
102-
###############################################################################
103-
# Print ``disp_plane2_fc`` information
104-
print(disp_plane2_fc)
105-
106-
###############################################################################
107-
# Extract the only field (0th entry) available in ``disp_plane2_fc`` FieldsContainer
108112
field_plane2 = disp_plane2_fc[0]
109113

110114
###############################################################################
@@ -134,7 +138,7 @@
134138
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
135139
# Obtain the levelset of the plane with respect to the mesh using
136140
# :class:`make_plane_levelset <ansys.dpf.core.operators.mesh.make_plane_levelset.
137-
# make_plane_levelset>`:
141+
# make_plane_levelset>`
138142
# A levelset is a scalar Field representing the normal distance between the plane
139143
# and the nodes of the mesh.
140144
# Note that origin and normal must be ``dpf.locations.overall`` 3D vectors.
@@ -171,13 +175,12 @@
171175
###############################################################################
172176
# Compute intersection plane / mesh
173177
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
174-
# Use the :class:`mesh_cut <ansys.dpf.core.operators.mesh.mesh_cut.mesh_cut>`:
178+
# Use the :class:`mesh_cut <ansys.dpf.core.operators.mesh.mesh_cut.mesh_cut>`
175179
# operator to obtain the intersection of the plane with the mesh from the levelset
176180
mesh_cutter_op = ops.mesh.mesh_cut()
177181
mesh_cutter_op.inputs.field.connect(levelset1)
178182
mesh_cutter_op.inputs.iso_value.connect(float(0))
179183
mesh_cutter_op.connect(2, 0)
180-
# mesh_cutter_op.inputs.mesh.connect(mesh)
181184
mesh_cutter_op.connect(3, mesh)
182185
mesh_cutter_op.inputs.slice_surfaces.connect(True)
183186
intersection1 = mesh_cutter_op.outputs.mesh()
@@ -186,7 +189,6 @@
186189
mesh_cutter_op.inputs.field.connect(levelset2)
187190
mesh_cutter_op.inputs.iso_value.connect(float(0))
188191
mesh_cutter_op.connect(2, 0)
189-
# mesh_cutter_op.inputs.mesh.connect(mesh)
190192
mesh_cutter_op.connect(3, mesh)
191193
mesh_cutter_op.inputs.slice_surfaces.connect(True)
192194
intersection2 = mesh_cutter_op.outputs.mesh()

0 commit comments

Comments
 (0)