# GTMesh: A Highly Efficient C++ Template Library for Numerical Schemes on General Topology Meshes
## 4 The GTMesh Library
### The UnstructuredMeshWrapper Class  
As described in the project architecture (Section 4), GTMesh aims at providing a single compact class exposing both the mesh structure and the mesh algorithms by means of its member functions, to simplify the work with the mesh. This construction makes the work with the mesh much more convenient. This wrapper class is called UnstructuredMesh. It inherits the MeshElements class, and it has no further structure. The only purpose of UnstructuredMesh is to provide the algorithms from Sections 4.3 as its public member functions. The provided functions are constructed with as few template parameters as possible, because most of the parameters of the mesh functions can be deduced from the setup of UnstructuredMesh. For example, the member function computeElementMeasures() has only one template parameter Method, because the rest of the parameters of the function computeMeasures() are deduced. An example of UnstructuredMesh wrapper usage is shown in Listing 3. ```
1@import<firstrem>
2#import<GTMesh/UnstructuredMesh/UnstructuredMesh.b>
3
4 StructCellData{
5 unsignedintcolor;
6 Vertex<3,double>center;
7 doubleinvPol;
8};
9//CreatedefaultTraitsfortheclassCellData
10 MAKE_ATTRINPUT_TAMIT(CellData,center,color,invVol);
11
12 voidmain(){
13//loadmesh
14 UnstructuredMesh<3,size.t,double,6>=mesh;
15 autoreshkader=mesh.load(\"mesh_file.vtk\");
16 mesh.initializeCentre();
17
18//CalculatemeshpropertiesandstorethemintomeshData
19 MeshDataContainer<CellData,3>meshData(mesh);
20 autocolors=ColorMesh<3,0>:color(mesh);
21 autoresames



the context of numerical algorithms, this tool makes it possible to write generic code that implements the following functionalities:

1. Data stored in user-defined data structures can be exported/imported to/from VTK, JSON or binary formats. 2. Arithmetic or other mathematical operations (such as norm calculation) can be performed on the user-defined data structures. As the above (and possibly other) use cases have different requirements, multiple reflections designed for different purposes can exist for a single class. The iteration over data members is done via static for loops, i.e., resolved at compile time by means of template function recursion. Hence, the generated code is as efficient as manually written code. At the time of writing, there exist several other open-source projects that aim for data serialization and/or class reflection in C++. A very recent and elegant solution is Cista++ ([[https://cista.rocks](https://cista.rocks)]([https://cista.rocks](https://cista.rocks))),which implements class reflection with the help of C++17 structured bindings [37]. However, this approach suffers from substantial limitations that prevent using Cista++ with GTMesh: in particular, it does not allow data transformations to create \"virtual\" data members, and it only works with plain structures without constructors. ### Member Access

A data member denotes any information calculated from the data stored in a data structure. Data members are obtained by their getter and are set by their setter functions. These functions might be arbitrary. The first part of the architecture is the method for data access. This is realized by the MemberAccess template class with several template specializations. This class then provides a unified interface to getting and setting the member data values. MemberAccess may be constructed in different ways:

1. Member reference, i.e., &data_structure:member, which defines the get, constant get and set operations. These operations are, thus, accessing the member data directly. 2. Pair of getter and setter, where each of these may be a member function or global function (callable object, e.g., lambda function) accepting the data structure instance as a parameter. ### Class Traits

The MemberAccess classes are then grouped in the Traits class template, which manages their association with the names of the data members. Traits has member functions returning the data accessed by MemberAccess based on an integer template parameter (see Listing 4).