Chi-Tech
devman_A0_meshes.h
Go to the documentation of this file.
1/**\page DevManMeshes The structure of meshes
2 *
3\section devman4_sec0 General structure of meshes
4
5Mesh generation can be classified into 4 basic levels difficulty.
6-# Orthogonal. The simplest mesh generation is undoubtedly the generation of orthogonal
7meshes.
8-# Reading meshes. Minimal repackaging of pre-generated meshes.
9-# Semi-generated meshes. Extruded meshes and other similar operations.
10-# Internally generated meshes. Pipe dream for now, but having the ability
11 to generate tetrahedral meshes would open a lot of doors. From there
12 I would like to have polyhedral meshes generation then hexahedral mesh
13 generation.
14
15\subsection devman_meshes_sec0_0 What is the grid?
16
17The grid is an instance of the chi_mesh::MeshContinuum class. It has 3
18members of primary interest namely:
19- chi_mesh::MeshContinuum::vertices containing pointers to all the nodes of type
20 chi_mesh::Node. The container is an indexed map using vertex global ids.
21- chi_mesh::MeshContinuum::local_cells containing local cells of type
22 chi_mesh::Cell. The container has an iterator available and is indexed by
23 cell local index.
24- chi_mesh::MeshContinuum::cells handles indexing by global cell ids. This
25 also facilitates the addition of cells to the local_cell storage.
26
27## _
28
29\subsection devman_meshes_sec0_1 Easily access an existing grid
30
31We will explain the different elements of a mesh in more detail in sections
32below but as a quick primer we can say that mesh entities are loaded into
33chi_mesh::MeshHandler.
34
35You can get the current mesh-handler using:
36
37 \code
38 auto cur_handler = chi_mesh::GetCurrentHandler();
39 \endcode
40
41The computational grid is contained in a chi_mesh::MeshContinuum object which
42you can obtain with:
43
44\code
45auto grid_ptr = cur_handler->GetGrid();
46\endcode
47
48If there is no existing grid then one can be created as detailed in
49
50## _
51\section devman_meshes_sec_1 More detail on Mesh data structures
52
53\subsection devman_meshes_sec1_0 chi_mesh::MeshHandler
54Meshes and mesh operations are all handled under the umbrella of a
55chi_mesh::MeshHandler. Mesh handlers are loaded onto the global variable
56`chi_meshhandler_stack` and the "current" handler is tracked by
57another global variable, `chi_current_mesh_handler`.
58 If any mesh operation is performed it should push
59newly created objects to a stack in a handler. The figure below shows
60a generalized architecture.
61
62\image html MeshOverview.png "Figure 1: Overview of the mesh hierarchy." width=700px
63
64Even though we already showed how to obtain the handler, the "current"
65 handler can always be obtained with:
66
67 \code
68 auto cur_handler = chi_mesh::GetCurrentHandler();
69 \endcode
70
71## _
72
73\subsection devman_meshes_sec1_2 chi_mesh::SurfaceMesher and chi_mesh::VolumeMesher
74
75Each mesh-handler is outfitted with one surface mesher and one volume
76mesher, both initially undefined. The surface meshing step can be thought of
77a preprocessing step. For those who are used to STAR-CCM+, this step is
78analogous to the remeshing of a CAD surface into a format more conducive to
79volume meshing.
80
81There are various types of surface meshers:
82 - chi_mesh::SurfaceMesherPredefined. Pass through pre-processor. Does not
83 perform any meshing.
84 - chi_mesh::SurfaceMesherDelaunay. Remeshes a surface mesh using Delaunay
85 triangulation.
86 - chi_mesh::SurfaceMesherTriangle. Remeshes a surface mesh using Triangle 1.6.
87
88Similarly there are also various types of volume meshers:
89 - chi_mesh::VolumeMesherLinemesh1D. Converts line meshes into slabs.
90 - chi_mesh::VolumeMesherPredefined2D. Converts predefined surface meshes into
91 2D triangles, quadrilaterals or polygons.
92 - chi_mesh::VolumeMesherExtruder. Extrudes predefined surface meshes into
93 3D triangular prisms, hexahedrals or polyhedrons.
94 - chi_mesh::VolumeMesherPredefined3D. Converts loaded 3D meshes to
95 3D tetrahedrals, hexahedrals or polyhedrons.
96 - chi_mesh::VolumeMesherPredefinedUnpartitioned. Converts a ligthweight
97 unpartitioned mesh to a proper full detail partitioned mesh. This mesher
98 allows much flexibility for reading meshes from external sources.
99
100Surface meshers and volume meshers are assigned to a handler as:
101
102\code
103cur_handler->surface_mesher = new chi_mesh::SurfaceMesherPredefined;
104cur_handler->volume_mesher = new chi_mesh::VolumeMesherPredefined3D;
105\endcode
106
107To execute the surface meshers simply do:
108
109\code
110cur_handler->surface_mesher->Execute();
111cur_handler->volume_mesher->Execute();
112\endcode
113
114## _
115
116\subsection devman_meshes_sec1_3 chi_mesh::MeshContinuum (or if you like ... THE GRID!)
117
118A chi_mesh::MeshContinuum object is the business-end of meshes. The execution
119of a volume mesher ultimately results in the creation of a grid. To obtain
120a reference to a grid simply execute:
121
122\code
123auto grid = cur_handler->GetGrid();
124\endcode
125
126This command will retrieve the latest grid from the latest region within the
127current mesh handler.
128
129## _
130
131\subsection devman_meshes_sec1_4 chi_mesh::Cell
132
133Cells in Chi-Tech are the basic building blocks for mesh-based scientific
134computing. Some of the mesh types are shown in Figure 2 below and are defined
135by the enumeration they hold as defined by chi_mesh::CellType. The cell types
136supported right now are:
137 - chi_mesh::CellType::SLAB
138 - chi_mesh::CellType::TRIANGLE
139 - chi_mesh::CellType::QUADRILATERAL
140 - chi_mesh::CellType::POLYGON
141 - chi_mesh::CellType::TETRAHEDRON
142 - chi_mesh::CellType::HEXAHEDRON
143 - chi_mesh::CellType::POLYHEDRON
144
145
146\image html TypesOfCells.png "Figure 2: Types of cells." width=500px
147
148## _
149
150\subsection devman_meshes_sec1_5 Accessing cells (the pain of parallel programs)
151
152Cells live in the `local_cells` member of a grid, which is of object type
153chi_mesh::MeshContinuum::LocalCells, under the auspices of either
154`native_cells` or `foreign_cells`. Local cells are guaranteed to be fully
155defined (i.e. not ghost cells) whilst non-local cells are most likely to be
156ghost-cells. The fastest way to access a cell is by means of its local id
157
158\code
159auto cell = grid->local_cells[cell_local_id];
160\endcode
161
162The `local_cells` object also facilitates an iterator.
163
164\code
165for (auto cell = grid->local_cells.begin();
166 cell != grid->local-cells.end();
167 ++cell)
168{//do stuff}
169\endcode
170
171and also a range based iterator
172
173\code
174for (auto& cell : grid->local_cells)
175{ //do stuff}
176\endcode
177
178Alternatively, a more expensive way to access a cell is by means of its
179global index via the grid's `cells` member. This member is a utility object
180that will search the `native_cells` and `foreign_cells` for the cell with
181the associated global id
182
183\code
184auto cell = grid->cells[cell_global_id];
185\endcode
186
187Because of the search operation it is not recommended to repeatedly access
188cells by their global ids.
189
190\image html CellMapping.png "Figure 3: Cell mapping logic." width=600px
191 */