@@ -23,7 +23,7 @@ Import the necessary modules
2323
2424Import the ``ansys.dpf.core `` module, including the operators subpackage and the numpy library
2525
26- .. code-block :: python
26+ .. jupyter-execute ::
2727
2828 import numpy as np
2929 from ansys.dpf import core as dpf
@@ -32,7 +32,7 @@ Import the ``ansys.dpf.core`` module, including the operators subpackage and the
3232Define the mesh dimensions
3333--------------------------
3434
35- .. code-block :: python
35+ .. jupyter-execute ::
3636
3737 # Define the mesh dimensions
3838 length = 0.1
@@ -52,7 +52,7 @@ the elements and nodes indices connected to each node.
5252
5353Here we create a function that will find the connectivity of our entities.
5454
55- .. code-block :: python
55+ .. jupyter-execute ::
5656
5757 def search_sequence_numpy(arr, seq):
5858 """Find a sequence in an array and return its index."""
@@ -68,7 +68,7 @@ Add nodes
6868
6969Add nodes to the |MeshedRegion | object:
7070
71- .. code-block :: python
71+ .. jupyter-execute ::
7272
7373 node_id = 1
7474 for i, x in enumerate(
@@ -85,7 +85,7 @@ Add nodes to the |MeshedRegion| object:
8585
8686Get the nodes coordinates field
8787
88- .. code-block :: python
88+ .. jupyter-execute ::
8989
9090 my_nodes_coordinates = my_meshed_region.nodes.coordinates_field
9191
@@ -94,13 +94,13 @@ Set the mesh node properties
9494
9595Set the mesh unit:
9696
97- .. code-block :: python
97+ .. jupyter-execute ::
9898
9999 my_meshed_region.unit = "mm"
100100
101101Set the nodes coordinates:
102102
103- .. code-block :: python
103+ .. jupyter-execute ::
104104
105105 # Get the nodes coordinates data
106106 my_nodes_coordinates_data = my_nodes_coordinates.data
@@ -112,7 +112,7 @@ Set the nodes coordinates:
112112Add the elements
113113----------------
114114
115- .. code-block :: python
115+ .. jupyter-execute ::
116116
117117 element_id = 1
118118 for i, x in enumerate(
@@ -144,75 +144,6 @@ Add the elements
144144Plot the mesh
145145-------------
146146
147- .. code-block :: python
147+ .. jupyter-execute ::
148148
149- my_meshed_region.plot()
150-
151- .. rst-class :: sphx-glr-script-out
152-
153- .. jupyter-execute ::
154- :hide-code:
155-
156- import numpy as np
157- from ansys.dpf import core as dpf
158- from ansys.dpf.core import operators as ops
159- length = 0.1
160- width = 0.05
161- depth = 0.1
162- num_nodes_in_length = 10
163- num_nodes_in_width = 5
164- num_nodes_in_depth = 10
165- my_meshed_region = dpf.MeshedRegion()
166- def search_sequence_numpy(arr, seq):
167- """Find a sequence in an array and return its index."""
168- indexes = np.where(np.isclose(arr, seq[0]))
169- for index in np.nditer(indexes[0]):
170- if index % 3 == 0:
171- if np.allclose(arr[index + 1], seq[1]) and np.allclose(arr[index + 2], seq[2]):
172- return index
173- return -1
174- node_id = 1
175- for i, x in enumerate(
176- [float(i) * length / float(num_nodes_in_length) for i in range(0, num_nodes_in_length)]
177- ):
178- for j, y in enumerate(
179- [float(i) * width / float(num_nodes_in_width) for i in range(0, num_nodes_in_width)]
180- ):
181- for k, z in enumerate(
182- [float(i) * depth / float(num_nodes_in_depth) for i in range(0, num_nodes_in_depth)]
183- ):
184- my_meshed_region.nodes.add_node(node_id, [x, y, z])
185- node_id += 1
186- my_nodes_coordinates = my_meshed_region.nodes.coordinates_field
187- my_meshed_region.unit = "mm"
188- my_nodes_coordinates_data = my_nodes_coordinates.data
189- my_nodes_coordinates_data_list = my_nodes_coordinates.data_as_list
190- my_coordinates_scoping = my_nodes_coordinates.scoping
191- element_id = 1
192- for i, x in enumerate(
193- [float(i) * length / float(num_nodes_in_length) for i in range(num_nodes_in_length - 1)]
194- ):
195- for j, y in enumerate(
196- [float(i) * width / float(num_nodes_in_width) for i in range(num_nodes_in_width - 1)]
197- ):
198- for k, z in enumerate(
199- [float(i) * depth / float(num_nodes_in_depth) for i in range(num_nodes_in_depth - 1)]
200- ):
201- coord1 = np.array([x, y, z])
202- connectivity = []
203- for xx in [x, x + length / float(num_nodes_in_length)]:
204- for yy in [y, y + width / float(num_nodes_in_width)]:
205- for zz in [z, z + depth / float(num_nodes_in_depth)]:
206- data_index = search_sequence_numpy(my_nodes_coordinates_data_list, [xx, yy, zz])
207- scoping_index = int(data_index / 3) # 3components
208- connectivity.append(scoping_index)
209- # rearrange connectivity
210- tmp = connectivity[2]
211- connectivity[2] = connectivity[3]
212- connectivity[3] = tmp
213- tmp = connectivity[6]
214- connectivity[6] = connectivity[7]
215- connectivity[7] = tmp
216- my_meshed_region.elements.add_solid_element(element_id, connectivity)
217- element_id += 1
218149 my_meshed_region.plot()
0 commit comments