NiHu
2.0
|
Cluster trees are hierarchical oc-trees built up based on a sequence of nodal locations. Cluster trees provide the interface for various tree traversal methods, needed for implementing Fast Multipole Methods. This tutorial demonstrates the usage of cluster trees in NiHu's fast multipole module.
Cluster trees are a hierarchical collections of clusters, therefore, the cluster type needs to be defined first. In our simplest example, we work with a cluster tree containing three-dimensional empty clusters (see NiHu::fmm::empty_cluster).
We create an array of random nodal locations.
The cluster tree is built with its constructor. In the simplest case the constructor needs three parameters:
Alternatively, NiHu contains built in dividing functors for building balanced trees of specified depth or prescribed leaf level cluster diameter:
In the above trees, each node is both source and receiver. In order to define source and receiver nodes separately, the alternative constructor can be used that takes two ranges as input:
In most boundary element applications, the cluster tree is not built based on a sequence of nodal locations, rather based on elements of a boundary element mesh. NiHu provides built-in iterators NiHu::fmm::elem_center_iterator that traverse mesh elements but return the element center when dereferenced:
The cluster tree (see NiHu::fmm::cluster_tree) is a vector container of clusters, and clusters can be accessed by indexing. The following snippet, for example, traverses each cluster of a tree:
The clusters are stored in a level-contiguous way that makes level-by-level traversing possible by getting the begin and end index of clusters within a specified level:
In an unbalanced tree, the leaf clusters are not stored continuously. Therefore, NiHu cluster trees provide an index vector to traverse leaf clusters:
Similarly, source and receiver leaf clusters can be traveresed by getting their index vectors:
Depth first search (DFS) traverse of the tree is provided by the cluster class that contains indices of its children in the tree.