Skip to content

[bugfix][forms] Add a clear() method to CacheManager

This adds a clear() method to the CacheManager class which cleares all stored data and is called in the local assemblers. This is needed in order to correctly reuse these local assemblers:

When being bound to a LocalView before the actual assembly, the local assembler registers the required caches in the CacheManager. These caches normally depend on the LocalView and store pointers to nodes of its tree which are needed to compute shape function values. Since caches are shared between different subexpressions, the CacheManager only stores a cache the first time it is registered and reuses the already stored cache later on. So far his also applies when reusing the local assembler later on. But when used for a second time, the LocalView will normally be different, such that reusing the stored chache which still refers to the old LocalView internally is a bug.

This bug became visible when porting dune-fufem to dune-assembler. There, assembleMatrixPattern() calls bindLocalViews() before assembleMatrix(), i.e. we are reusing the local assembler with a different LocalView which may trigger the above mentioned problem. Unfortunately with the classical usage pattern, the compiler seems to place the LocalView of assembleMatrixPattern() and assembleMatrix() on the same stack location most of the time, such that the bug is hardly ever triggered and thus hard especially hard to debug.

In fact this turned out to be a Heisenbug, that disapears e.g. without optimization in valgrind or if you add certain debug output and thus took quite a bit of time to find.

Merge request reports

Loading