4
4
Create a mesh from scratch
5
5
==========================
6
6
7
- .. |Field | replace :: :class: `Field<ansys.dpf.core.field.Field> `
8
- .. |FieldsContainer | replace :: :class: `FieldsContainer<ansys.dpf.core.fields_container.FieldsContainer> `
9
- .. |MeshedRegion | replace :: :class: `MeshedRegion <ansys.dpf.core.meshed_region.MeshedRegion> `
10
- .. |Model | replace :: :class: `Model <ansys.dpf.core.model.Model> `
7
+ .. include :: ../../../links_and_refs.rst
11
8
12
- The mesh object in DPF is a |MeshedRegion |. You can create your own |MeshedRegion | object to use DPF operators
13
- with your own data. The ability to use scripting to create any DPF entity means
9
+ This tutorial demonstrates how to build a |MeshedRegion | from the scratch.
10
+
11
+ The mesh object in DPF is a |MeshedRegion |. You can create your own |MeshedRegion | object and use it
12
+ with DPF operators. The ability to use scripting to create any DPF entity means
14
13
that you are not dependent on result files and can connect the DPF environment
15
14
with any Python tool.
16
15
17
- This tutorial demonstrates how to build a | MeshedRegion | from the scratch .
16
+ Here, we create a parallel piped mesh made of linear hexa elements .
18
17
19
- Here we create a parallel piped mesh made of linear hexa elements.
18
+ :jupyter-download-script: `Download tutorial as Python script<create_a_mesh_from_scratch> `
19
+ :jupyter-download-notebook: `Download tutorial as notebook<create_a_mesh_from_scratch> `
20
20
21
21
Import the necessary modules
22
22
----------------------------
23
23
24
- Import the ``ansys.dpf.core `` module, including the operators subpackage and the numpy library
24
+ Import the ``ansys.dpf.core `` module, including the operators subpackage and the numpy library.
25
25
26
26
.. jupyter-execute ::
27
27
28
+ # Import the numpy library
28
29
import numpy as np
30
+ # Import the ``ansys.dpf.core `` module
29
31
from ansys.dpf import core as dpf
32
+ # Import the operators subpackage
30
33
from ansys.dpf.core import operators as ops
31
34
32
35
Define the mesh dimensions
@@ -47,10 +50,10 @@ Define the mesh dimensions
47
50
Define the connectivity function
48
51
--------------------------------
49
52
50
- To create a mesh we need to define the nodes connectivity. This means to define
51
- the elements and nodes indices connected to each node.
53
+ To create a mesh you must define the nodes connectivity. This means to define
54
+ the nodes ids connected to each node.
52
55
53
- Here we create a function that will find the connectivity of our entities .
56
+ Here we create a function that will find this connectivity.
54
57
55
58
.. jupyter-execute ::
56
59
@@ -66,7 +69,7 @@ Here we create a function that will find the connectivity of our entities.
66
69
Add nodes
67
70
---------
68
71
69
- Add nodes to the |MeshedRegion | object:
72
+ Add | Nodes | to the |MeshedRegion | object.
70
73
71
74
.. jupyter-execute ::
72
75
@@ -83,34 +86,35 @@ Add nodes to the |MeshedRegion| object:
83
86
my_meshed_region.nodes.add_node(node_id, [x, y, z])
84
87
node_id += 1
85
88
86
- Get the nodes coordinates field
89
+ Get the nodes coordinates field.
87
90
88
91
.. jupyter-execute ::
89
92
90
93
my_nodes_coordinates = my_meshed_region.nodes.coordinates_field
91
94
92
- Set the mesh node properties
93
- ----------------------------
95
+ Set the mesh properties
96
+ -----------------------
94
97
95
- Set the mesh unit:
98
+ Set the mesh unit.
96
99
97
100
.. jupyter-execute ::
98
101
99
102
my_meshed_region.unit = "mm"
100
103
101
- Set the nodes coordinates:
104
+ Set the nodes coordinates.
102
105
103
106
.. jupyter-execute ::
104
107
105
108
# Get the nodes coordinates data
106
109
my_nodes_coordinates_data = my_nodes_coordinates.data
107
110
# As we use the connectivity function we need to get the data as a list
108
111
my_nodes_coordinates_data_list = my_nodes_coordinates.data_as_list
109
- # Get the nodes scoping
112
+ # Set the nodes scoping
110
113
my_coordinates_scoping = my_nodes_coordinates.scoping
111
114
112
- Add the elements
113
- ----------------
115
+ Add elements
116
+ ------------
117
+ Add |Elements | to the |MeshedRegion | object.
114
118
115
119
.. jupyter-execute ::
116
120
@@ -141,9 +145,11 @@ Add the elements
141
145
connectivity[7] = tmp
142
146
my_meshed_region.elements.add_solid_element(element_id, connectivity)
143
147
element_id += 1
148
+
144
149
Plot the mesh
145
150
-------------
146
151
147
152
.. jupyter-execute ::
148
153
154
+ # Plot the mesh you created
149
155
my_meshed_region.plot()
0 commit comments