# GTMesh: A Highly Efficient C++ Template Library for Numerical Schemes on General Topology Meshes
## 4 The GTMesh Library
### Algorithms
#### 4.3.6 Calculation of Element Measures  
The next algorithm calculates the Hausdorff measures of elements, with respect to their dimension \(1<d\leq d_{\mathcal{T}}\), where \(d_{\mathcal{T}}\) is the dimension of the mesh. We assume that every polytope \(e\in\mathcal{T}^{d}\) is a star domain, with respect to its center \(\boldsymbol{x}_{e}\)[34]. For \(d>1\), such polytopes can be subdivided into pyramids \(P_{e,e^{\prime}}\), with (planar) bases formed by their sub-elements \(e^{\prime}\in\mathcal{T}^{d-1}\) and a common top \(\boldsymbol{x}_{e}\). An example of subdivision of an element into pyramids is presented in Figure 7. This can be expressed as  
\[e=\bigcup_{e^{\prime}\in N^{d-1}(e)}P_{e,e^{\prime}}\]  
(see Definition 4). The \(d\)-dimensional Hausdorff measure of \(e\) is then given by  
\[m(e)=\sum_{e^{\prime}\in N^{d-1}(e)}m\big{(}P_{e,e^{\prime}}\big{)}. \tag{12}\]  
Let us denote by \(\boldsymbol{v}\) the geometrical position of each vertex \(v\in\mathcal{T}^{0}\). Then, the measure of the pyramid \(P_{e,e^{\prime}}\) reads  
\[m\big{(}P_{e,e^{\prime}}\big{)}=\frac{1}{d}m\big{(}e^{\prime}\big{)}\operatorname {dist}(V_{e^{\prime}},\boldsymbol{x}_{e}), \tag{13}\]  
where \(V_{e^{\prime}}\) is a linear manifold of dimension \(d-1\), containing the element \(e^{\prime}\), and \(m(e^{\prime})\) is the \((d-1)\)-dimensional measure of the pyramid base, calculated recursively by the same algorithm. To find the height of the pyramid \(\operatorname{dist}(V_{e^{\prime}},\boldsymbol{x}_{e})\), the Gram-Schmidt process is applied to the system of linearly independent vectors:  
\[\big{(}\boldsymbol{v}_{e^{\prime},2}-\boldsymbol{v}_{e^{\prime},1}, \boldsymbol{v}_{e^{\prime},3}-\boldsymbol{v}_{e^{\prime},1},\ldots, \boldsymbol{v}_{e^{\prime},d}-\boldsymbol{v}_{e^{\prime},1},\boldsymbol{x}_{ e}-\boldsymbol{v}_{e^{\prime},1}\big{)}, \tag{14}\]  
where \(\boldsymbol{v}_{e^{\prime},i}\in\mathcal{T}^{0}\cap e^{\prime}\) are unique vertices of \(e^{\prime}\). Note that an element of dimension \(d-1\) has at least \(d\) vertices. This results in an orthogonal system:  
\[(\boldsymbol{y}_{2},\boldsymbol{y}_{3},\ldots,\boldsymbol{y}_{d},\bar{ \boldsymbol{y}}), \tag{15}\]  
Figure 6: An example of the algorithm for calculating the element centers in a simple 3D mesh. The center point of an element is calculated as an average of the center points of its sub-elements. For example, the cell center point denoted \(\boldsymbol{x}_{c}\) is the average of the centers of all connected faces, denoted \(\boldsymbol{x}_{f_{1}}\).  
where the last vector, \(\tilde{\mathbf{y}}\), is not normalized. Finally, we calculate  
\[\text{dist}(V_{e^{\prime}},\mathbf{x}_{e})=|\tilde{\mathbf{y}}|.\]  
For \(d=1\), the 1D measure (length) of an edge \(e\in\mathscr{T}^{1}\) is calculated by  
\[m(e)=|\mathbf{v}_{A}-\mathbf{v}_{B}|, \tag{16}\]  
where \(\{v_{A},v_{B}\}=N^{0}(e)\).  
The above algorithm is implemented by the computeMeasures() function, and it returns a MeshDataContainer with measures of all elements in the mesh (except vertices). The computeMeasures() function calculates the measures from lower dimensions to higher ones, and it utilizes, to advantage, the already-calculated measures of lower-dimensional elements. This function also supports the compensation for non-planar elements [35].