Chi-Tech
doc_MeshGenerators.h
Go to the documentation of this file.
1/**\defgroup doc_MeshGenerators Mesh Generators
2\ingroup LuaMesh
3*
4We split a `MeshGenerator`'s execution into a
5phase that generates an unpartitioned mesh and a phase that then converts
6this mesh into partitioned `chi_mesh::MeshContinuum` (with both steps
7customizable). The phase that creates the `MeshContinuum` object can be hooked
8up to a partitioner that can also be designed to be pluggable.
9
10## Example A
11\code
12nodes = {-1.0,-0.75,-0.5,-0.25,0.0,0.25,0.5,0.75,1.0}
13meshgen1 = chi_mesh.OrthogonalMeshGenerator.Create({ node_sets = {nodes,nodes} })
14chi_mesh.MeshGenerator.Execute(meshgen1)
15
16chiMeshHandlerExportMeshToVTK("ZMeshTest")
17\endcode
18
19In this example we created a set of nodes (monotonically increasing in value)
20for use with the
21\ref chi_mesh__OrthogonalMeshGenerator. We supplied the same set twice meaning the generator
22will build a 2D mesh.
23
24We did not specify a partitioner and therefore the generator will use the
25\ref chi__PETScGraphPartitioner with `type="parmetis"` by default. Using 8
26processes, we can see the mesh and it's partitioning below.
27
28\image html framework/chi_mesh/MeshGenerators/ExampleA.png width=500px
29
30## Example B
31\code
32meshgen1 = chi_mesh.FromFileMeshGenerator.Create({ filename="TriangleMesh2x2.obj" })
33chi_mesh.MeshGenerator.Execute(meshgen1)
34
35chiMeshHandlerExportMeshToVTK("ZMeshTest")
36\endcode
37
38In this example we created a mesh by reading it from a file, using the
39\ref chi_mesh__FromFileMeshGenerator. The types of file-types we can support is
40ever growing. At the time of writing this we support the following formats:
41- `.obj` Wavefront
42- `.msh` gmesh,
43- `.e` ExodusII,
44- `.vtu` VTK Unstructured grid,
45- `.pvtu` Pieced VTK Unstructured grid,
46- `.case` Ensight Gold
47
48Using 8 processes, we can see the mesh and it's partitioning below.
49
50\image html framework/chi_mesh/MeshGenerators/ExampleB.png width=500px
51
52## Example C
53\code
54meshgen1 = chi_mesh.ExtruderMeshGenerator.Create
55({
56 inputs =
57 {
58 chi_mesh.FromFileMeshGenerator.Create({ filename=TriangleMesh2x2.obj" }),
59 },
60 layers = {{z=1.1, n=2}, -- First layer - 2 sub-layers
61 {z=2.1, n=3}}, -- Second layer - 3 sub-layers
62})
63chi_mesh.MeshGenerator.Execute(meshgen1)
64
65chiMeshHandlerExportMeshToVTK("ZMeshTest")
66\endcode
67
68In this example we use an \ref chi_mesh__ExtruderMeshGenerator with another
69mesh generator as an input to create an extruded mesh. Using 8 processes, we can
70see the mesh and it's partitioning below.
71
72\image html framework/chi_mesh/MeshGenerators/ExampleC.png width=500px
73
74## Using different Partitioners
75ChiTech now has a set of Graph Partitioners (i.e. based off `GraphPartitioner`)
76that support different forms of partitioning, for example we have:
77- \ref chi__LinearGraphPartitioner, a very basic partitioner used for
78during the preparation of simulation meshes.
79- \ref chi__PETScGraphPartitioner, a flexible partitioner that can use all the
80partitioner options available in PETSc (defaults to using `"parmetis"`).
81- \ref chi__KBAGraphPartitioner, the classical Neutron Transport KBA parallel
82partitioning with an overlaid orthogonal layout.
83
84An example of changing the partitioning to PETSc's `"average"` option is shown
85below:
86\code
87meshgen1 = chi_mesh.ExtruderMeshGenerator.Create
88({
89 inputs =
90 {
91 chi_mesh.FromFileMeshGenerator.Create
92 ({
93 filename="resources/TestMeshes/TriangleMesh2x2.obj"
94 }),
95 },
96 layers = {{z=1.1, n=2}, {z=2.1, n=3}},
97 partitioner = chi.PETScGraphPartitioner.Create({type="average"})
98})
99chi_mesh.MeshGenerator.Execute(meshgen1)
100
101chiMeshHandlerExportMeshToVTK("ZMeshTest")
102\endcode
103
104\image html framework/chi_mesh/MeshGenerators/ParExample1.png width=500px
105
106Another example using the `KBAGraphPartitioner` is shown below
107\code
108meshgen1 = chi_mesh.ExtruderMeshGenerator.Create
109({
110 inputs =
111 {
112 chi_mesh.FromFileMeshGenerator.Create
113 ({
114 filename="resources/TestMeshes/TriangleMesh2x2.obj"
115 }),
116 },
117 layers = {{z=1.1, n=2}, {z=2.1, n=3}},
118 partitioner = chi.KBAGraphPartitioner.Create
119 ({
120 nx = 2, ny=2, nz=2,
121 xcuts = {0.0}, ycuts = {0.0}, zcuts = {1.1}
122 })
123})
124chi_mesh.MeshGenerator.Execute(meshgen1)
125
126chiMeshHandlerExportMeshToVTK("ZMeshTest")
127\endcode
128
129\image html framework/chi_mesh/MeshGenerators/ParExample2.png width=500px
130
131
132## The special SplitFileMeshGenerator
133
134For very large meshes the mesh generation process could both take very long and
135require a lot of memory. The current mode of operation of the mesh generators is
136that each process builds the mesh as an unpartitioned mesh then the mesh gets
137converted to a partitioned mesh. Therefore, when a lot of processes are used,
138there could be a large memory spike, large enough to be greater than what even
139an HPC node has available. To partly address this problem we have the
140\ref chi_mesh__SplitFileMeshGenerator. This generator will process multiple mesh inputs like
141any other mesh generator but instead of building the mesh on each processor only
142the home location builds the mesh. Thereafter the mesh is partitioned and each
143processors' local-cells, ghost-cells, and relevant vertices are written to
144separate binary files. The default folder, into which these files are written,
145is named "SplitMesh" and the default file names for the meshes are
146"split_mesh_x.cmesh", where the x represents the processors rank. Both the
147folder name and file name prefixes (i.e. the "split_mesh" part) can be altered
148via input parameters.
149
150It is also possible to generate split meshes in serial by supplying the
151`num_parts` parameter. Also, if a simulation uses the same mesh over and over
152then the parameter `read_only` can be used to suppress the mesh being
153created every single time.
154
155### SplitFile Example A
156
157\code
158meshgen1 = chi_mesh.SplitFileMeshGenerator.Create
159({
160 inputs =
161 {
162 chi_mesh.OrthogonalMeshGenerator.Create({ node_sets = {xmesh,ymesh,zmesh} })
163 },
164})
165
166chi_mesh.MeshGenerator.Execute(meshgen1)
167\endcode
168
169The examples below will create, in the current working directory, the folder
170`SplitMesh` and within it `split_mesh_0.cmesh`, `split_mesh_1.cmesh`, etc.
171
172### SplitFile Example B
173
174\code
175meshgen1 = chi_mesh.SplitFileMeshGenerator.Create
176({
177 inputs = {
178 chi_mesh.OrthogonalMeshGenerator.Create({ node_sets = {xmesh,ymesh} }),
179 chi_mesh.ExtruderMeshGenerator.Create
180 ({
181 layers = {{z=Lz, n=Nz}}
182 })
183 }
184})
185
186chi_mesh.MeshGenerator.Execute(meshgen1)
187\endcode
188
189This example is the same as the one above it, however, it uses the extruder
190mesh generator in a chain.
191
192\note Partitioning and the other parameters of \ref chi_mesh__SplitFileMeshGenerator are
193identical to that of the base \ref chi_mesh__MeshGenerator.
194
195*/