# GTMesh: A Highly Efficient C++ Template Library for Numerical Schemes on General Topology Meshes
## 4 The GTMesh Library
### Associating Data with the Mesh  
Any numerical method for solving a system of partial differential equations on a domain tessellated by the mesh needs to store data associated with the individual mesh elements. The data can represent the values of the solution, auxiliary pre-calculated space-dependent quantities or implementation-specific storage for intermediate results. The purpose (and hence the type) of data associated with mesh elements is specific to their dimension. For example, finite volume methods use solution values for the computationally significant elements, i.e., cell centers, cell faces or both. However, additional data storage may be allocated, for each vertex to hold the results of intermediate calculations.  
GTMesh provides a data container, named MeshDataContainer, to conveniently store data associated with mesh elements. Once the mesh geometry and topology has been provided, MeshDataContainer provides a flexible interface for allocating and accessing the mesh-associated data. In the most generic case, a single instance of MeshDataContainer  
Figure 5: Scheme of the chosen representation demonstrated on a 3D unstructured mesh.  
is capable of holding data represented by types T1, T2,..., Tn associated with all mesh elements of dimensions \(d_{1}\), \(d_{2}\),..., \(d_{n}\), respectively. The dimensions specifics (\(d_{1}\), \(d_{2}\),..., \(d_{n}\)) need not be unique, i.e., there can be more than one data type associated with elements of the given dimension.  
Internally, MeshDataContainer contains \(n\) arrays with interfaces similar to std::vector<T1>...std::vector<Tn>. For each \(i\in\{1,\ldots,n\}\), the length of the vector is the same as the number of mesh elements of dimension \(d_{i}\).  
The vectors within MeshDataContainer can be addressed in two ways:  
1. By position \(i\) of the dimension \(d_{i}\) within the ordered list (\(d_{1}\), \(d_{2}\),..., \(d_{n}\));
2. By dimension \(d\). In this case, the \(i\)th vector is returned, where \(i\) is the first integer in the sequence \((1,2,\ldots,n)\), such that \(d_{i}=d\).  
In addition, the data within MeshDataContainer can also be indexed directly by the instances of MeshElement, i.e., the MeshDataContainer provides a subscript operator for instances of the MeshElement class (see Listing 1). This establishes a mapping between mesh elements and data instances. The data vector in MeshDataContainer is given by the dimension of the mesh element (by using the rule explained above). The component of the vector is given by element dimension and index, present in every MeshElement data structure.  
Presentation of the usage of the MeshDataContainer class. The data container allocates four different data types to dimensions of the mesh. Upon construction, the MeshDataContainer class allocates data according to the dimensions of the provided mesh. Then, the example presents the possibility of accessing data, using elements of the mesh or the underlying data collections, by explicitly specifying the dimension or position template parameter.  
1 UnstructuredMesh<3, double> mesh3d;
2 mesh3d.load(\"mesh_file.vtk\");
3//Associate data to a mesh
4//Associate data according to the mesh dimensions.
5//Typechar -> cells, int and double -> faces and float -> vertices.
6 MeshDataContainer<std::tuple<char, int, double, float>, 3,2,2,0>meshData(mesh3d);
7
8//Accessene the value corresponding to the first vertex.
9 meshData[mesh3d.getvertices()[0]];
10//equivalent to
11//getDataByDim returns the first collection corresponding to the desired dimension.
12 meshData.getDataByDim<0>()[0];
13
14//Redundant mappings to a dimension are accessible via getDataByPos only.
15 meshData.getDataByPos<2>();