Skip to content

Mesh module

core/MESH/        Namespace: fdaPDE::core::MESH

Note

In principle any mesh file can be handled by this module. A simple CSV parser is part of the module which makes able to load mesh informations from .csv files. Anyway fdaPDE mainly refers to meshes built from the Triangle mesh generation software (see more on Triangle's website) and makes computations based on the specific mesh storage layout provided by triangle (i.e. the mesh topology is reconstructed making heavy assumptions on its storage scheme).

Therefore even if is possible, is not recommended to use this module outside the Triangle's specific output structure. In any case if you use any of the front-ends provided by fdaPDE, Triangle is automatically used as part of the mesh generation process.

The mesh module provides an abstraction layer to the user interfacing directly with the mesh topology by hiding all the details about its organization in memory. The content of the following info box is of interest to developers only or in case you want to understand more in depth the mesh management inside this module.

Info

A mesh is typically provided as a set of the following raw informations (usually produced by the mesh generation process):

  • a matrix , with number of mesh nodes and dimension of the space where the mesh is embedded. Row i of matrix gives the coordinates as floating-point numbers of node i in . This is the only source where we can access informations about the location of nodes in space. Any other source will reference to points by their row index in this matrix.

  • a matrix with number of mesh elements, where row i contains as elements the row indexes of the points in matrix constituting the vertices of the mesh element with identifier i.

  • a matrix with number of mesh edges, where row i contains as elements the row indexes of the points in matrix constituting the endpoints of the edge with identifier i.

  • a matrix where row i contains as elements the row indexes of the elements in matrix constituting the neighboring elements to the element i. Take care that the first neighbor of triangle i is opposite the first corner of triangle i, and so on. A negative value means that there is no neighbor.

This module hides all these details by supplying a more abstract Element object which is able to represent more faithfully the geometry as well as the connectivity of the single mesh element. In this way users can think at an higher abstract level without the burden of this matrix representation.

The main entry point of this module is the Mesh class which provides a set of facilities for easy management of the elements inside the mesh

template <unsigned int M, unsigned int N> class Mesh;
Template parameter Description
unsigned int M The local dimension of the mesh elements, i.e. the dimension of the euclidean space where the single mesh element is embedded. According to the value of M we can have as mesh elements:
  • 1D objects as lines (M=1)
  • 2D objects as triangles (M=2)
  • 3D objects as tetrahedrons (M=3)
unsigned int N The dimension of the space where the mesh is embedded.

In case fdaPDE assumes a manifold mesh and will activate the proper specializations to deal with this kind of structures.

Info

Supported manifold dimensions are 1.5D for linear network (each element is a segment embedded on a plane) and 2.5D (each element is a triangle embedded in a 3D space) for surface meshes.

The following code snippet provides an example of the API offered by this module. Refer to the specific pages for more detailed informations:

// load a 2D mesh from .csv files
Mesh<2,2> mesh("nodes.csv", "edges.csv", "triangles.csv", "neighbors.csv");

// once you have the mesh in memory you can...

// request for a specific element if you know its ID...
std::shared_ptr<Element<2,2>> element = mesh.requestElementById(42);

// range-for the mesh elements...
for(std::shared_ptr<Element<2,2>> element : mesh){
    // do some operations on each single element
}

// search for the element which contains a given point by using one of the provided engines
ADT<2,2> treeBasedSearchEngine(mesh);
std::shared_ptr<Element<2,2>> element = treeBasedSearchEngine.search(SVector<2>(0.5,0.5));

Engines

One of the most recurrent operation a mesh handler faces to solve is the element search. This is particularly important when, for example, we need to evaluate the solution of a differential problem once discretized using the Finite Element Method to produce some raster image of the obtained results. In such cases hundreds of thousands of queries must be supplied to the mesh module which must be able to solve these queries in a reasonable amount of time.

The mesh module provides a set of search engines which can be used to accomplish this problem. Here we report just some performance indicator of the engines provided, refer to the specifc pages for detailed informations (times are reported in microseconds per query).

Engines 2D 2.5D 3D
us/query (average) query/second us/query (average) query/second us/query (average) query/second Complexity
BruteForce 715 1400 average time query/second average time query/second \( O(n) \)
BarycentricWalk 11 90.000 - - average time query/second \( O(\sqrt{n}) \)
ADT (tree based) 3 270.000 average time query/second average time query/second \( O(\log{n}) \)

Engines provides an unified interface represented by a single method search

std::shared_ptr<Element<M,N>> search(const SVector<N>& point);
Args Description
const SVector<N>& point The N-dimensional point to search for.

The method returns a shared pointer to the element containing the given point.