Skip to content

Implement helper makeTreeContainer() to construct container matching the tree structure

Carsten Gräser requested to merge feature/treecontainer into master

This implements a helper function makeTreeContainer() which creates a nested container matching the structure of a given tree. PowerNodes are represented by std::array while CompositeNodes are represented by Dune::TupleVector. The data (and its type) stored for the leafs is either default constructed or created by a user-provided callback.

For convenience, the nested container is not returned directly but wrapped such that you can use operator[](HybridTreePath) to access it's entries.

This is helpful if you want to associate date to the leaf nodes but want to avoid having to create a full type tree. E.g. for implementing a local grid function spanned by an ansatz tree of local finite elements, each leaf evaluates its basis functions into an std::vector. This is better created only once to avoid costly reallocation. The new utility allows to conveniently store and access one std::vector for each leaf node:

// create container storing different std::vector's for each leaf
auto leafToData = [](const auto& node) {
  return std::vector<decltype(node)::Range>{};
};
auto container = makeTreeContainer(tree, leafToData);

// create a simple container storing int for each leaf
auto simpleContainer = makeTreeContainer<int>(tree);

// Access container
forEachLeafNode(tree, [&](const auto& node, auto treePath){
  simpleContainer[treePath] = node.id();
});

Notice that this relies on core/dune-common!495 (merged) and will not compile until this is merged.

Remark: Notice that the ContainerFactory used as implementation detail also serves as an example how a simplified tree transformation may look like.

Edited by Carsten Gräser

Merge request reports