[dune-functions] tree-like structure of hierarchic matrix

Simon Praetorius simon.praetorius at tu-dresden.de
Sat Feb 24 13:38:44 CET 2018


Hi,

Playing around with a hierarchicMatrixWrapper (see the other 
discussions) with dune-istl, I notices that one needs more functionality 
than just

- resize all blocks in a matrix
- access an entry on the matrix using multiindices

e.g. for a BCRSMatrix you maybe want to set a BuildMode and set 
properties for some modes, or call a different access method for 
insertion and reading, e.g. entry(i,j) and operator[][]. For other 
matrix implementations we may need to initialize an inserter or finish 
the insertion (e.g. call compress()). So, it seems necessary to invoke 
arbitrary functions on the different blocks of a matrix.

A hierarchic matrix is basically something like a type-tree with 
composite nodes (e.g. MultiTypeMatrix) and power nodes (e.g. 
BlockMatrix) or leaf nodes (e.g. BCRSMatrix) and there is also a 
tree-path identifying each block in the matrix-tree. So, maybe one could 
abstract the matrix nesting structure like a type-tree and then 
implementing things like a visitor for nodes in the tree. Currently only 
one visitor is implemented explicitly, i.e. the resizer. It gets the 
current matrix and some additional information to perform a resize() 
operation.

I think about something like

```
visit(hierarchicMatrix, [](auto& m, int rows, int cols) { 
m.setSize(rows,cols); });
```
to call the setSize method on each block of the matrix using traversal 
of the block-structure.

If your hierarchicMatrix is build up of sub-matrices that have different 
resize methods, one could implement an overloadset for each different 
type, like

```
visit(hierarchicMatrix, oberloaded(
   [](BCRSMatrix& m, int rows, int cols) {
     m.setBuildMode(BCRSMatrix::implicit);
     m.setImplicitBuildModeParameters(50,0.1);
     m.setSize(rows, cols);
   },
   [](Matrix& m, int rows, int cols) { m.resize(rows,cols); }
));
```

This is just an illustration.

Some open questions in the approach:
- we need a break condition for the recursion. This could be the same as 
for the proposed hierarchicMatrixWrapper.
- how to restrict the visitor to only a few nodes, like only the leaf 
nodes? Does this restriction makes sense at all? One solution could be 
using Hybrid::ifElse with a concept that checks whether the visitor can 
be applied to the current matrix-block, like it is done for the resize() 
method
- what information to pass to the visitor function? For resize, we need 
size information, but for, e.g., setImplicitBuildModeParameters it would 
be nice to have information about the underlying basis-tree. Can this be 
combined?
- In the type-tree traversal, one gets the tree-node + the tree-path. 
What is a good candidate for the tree-path for matrices? The 
size-prefix? The multiindex? Maybe it can be implemented like in the 
typetree traversal  by creating a treepath object during traversal of 
the tree nodes.

A tree-representation of the matrix could be given by the nesting 
structure (as proposed for the hierarchMatrixWrapper)

What do you think? A preliminary implementation is currently in 
development. I will upload a personal branch in a while.

Simon





More information about the dune-functions mailing list