ug4
|
The central class of libGrid is the Grid class. It handles element creation, neighbourhood management, data-attachments and observers. The class MultiGrid is derived from Grid, and adds a hierarchical structure to the grids elements.
Geometric Objects are the building blocks of a grid. There are four different basic geometric objects:
Those basic objects are then further specialized:
For hanging-node support the following objects are introduced:
All geometric objects deriving from Edge, Face or Volume feature methods to access the vertices of an element:
Furthermore they define methods like
Please check the documentation of the different base types.
Geometric Objects are created through the ug::Grid::create method (or ug::MultiGrid::create). Since the Grid class only knows about the basic geometric objects, ug::Grid::create<TGeomObj> is a template method, that takes the type of the geometric object that is to be created as template argument:
The create method takes an optional parameter:
The parent is used in different ways:
All those beahviours can be enabled / disabled in the respective classes.
libGrid uses the technique of iterators for geometric-object access. A separate iterator-type exists for each object-type:
You can query a grid for a begin and an end-iterator for each geometric-object type using ug::Grid::begin and ug::Grid::end. Both methods are template methods. The template argument specifies the type of geometric-object over which you want to iterate.
The same technique can be used to iterate over all Triangles of a subset:
or a ug::Selector
or a level of a ug::MultiGrid
or triangles on level l in subset i of a ug::MultiGridSubsetHandler
There are even more classes that support this way of geometric-object iteration.
Through attachments custom data can be associated with the geometric objects in a ug::Grid or a subset of a ug::GridSubsetHandler or ug::MultiGridSubsetHandler. Data is attached to all objects of the same basic type at once (ug::Vertex, ug::Edge, ug::Face, ug::Volume).
Lets say we wanted to associate an integer with each vertex in a grid g. This could be done as follows:
When aInt is being attached to the vertices of the grid, memory is automatically allocated and associated with the vertices. If you add or remove vertices, the memory is adjusted in the background.
To access the integer-value that is associated with each vertex, an attachment-accessor is required:
The vertex-attachment-accessor features the operator [] that takes a pointer to a vertex and returns a reference to the associated value.
Data can be attached to elements of a subset of an ug::GridSubsetHandler or ug::MultiGridSubsetHandler like this:
Given a geometric object, there are several methods to access neighbor elements in a grid. The most powerful methods in this context is the method ug::Grid::associated_elements. It can be used with any combination of geometric base objects. E.g., it can be used to retrieve all faces which are connected to an edge or all faces, which are connected to a volume element. Here is an example, where we retrieve a container with all edges, which are connected to a volume element:
The code works for all combinations of Vertex, Edge, Face and Volume. Note however, that the method does not guarantee, that the order of the elements in the returned container is the same as the order of the reference element, e.g., when collecting sides of a volume. Since some methods rely on the order, a second method exist, which guarantees that the order matches reference elements order: ug::Grid::associated_elements_sorted. The method can basically be used as associated_elements, but has the restriction, that the dimension of the elements in the returned container has to be lower than the dimension of the element in the second argument. Otherwise no order could be defined. Furthermore ug::Grid::associated_elements_sorted may be a little slower than ug::Grid::associated_elements. The latter should thus be preferred, if the order is not important.
While those two methods allow to completely access all neighbors in a grid (possibly with a little work), some conveniance methods exist to, e.g., to retrieve a single side of an element or to retrieve all neighbors of the same geometric object type (e.g. all faces which are adjacent to a given face). All related methods are listed below.
The main methods to access associated elements, as explained above. Note that while those methods can be used to retrieve the vertices of, e.g., a Face, the direct way through Face::vertex or Face::vertices should be preferred if possible.
Returns the geometric object given a couple of vertices
Returns the i-th side of a geometric object (use e.g. Face::num_sides to retrieve the number of sides of that object).
Furthermore methods exist to collect, e.g., all faces which are adjacent to a given face (same for vertices, edges and volumes):
There are some classes that help tremendously when implementing algorithms: the Selector and the SubsetHandler.