Skip to content

Draft: Issue with our singleton concept

Andreas Dedner requested to merge bugfix/singletonAGPkey into master

Issue

The Lagrange space mapper over an AGP is a singleton relying on the AIndexSet which is also singleton. But it stores an AGP which is not singleton. See https://gitlab.dune-project.org/dune-fem/dune-fem/-/blob/master/dune/fem/space/lagrange/storage.hh#L50 which can rely on a dangling reference gridPart_. The same issue can happen in cachedcommmanager.hh.

So the following code (sometimes) fails - compile without NDEBUG to get an assert in dune/fem/gridpart/adaptiveleafgridpart.hh:163

import gc
from dune.grid import structuredGrid
from dune.fem.view import adaptiveLeafGridView as adaptive
from dune.fem.space import lagrange
from ufl import *

x = SpatialCoordinate(triangle)
def test(grid):
    print("Start test",flush=True)
    aGV = adaptive(grid)
    spc = lagrange(aGV, dimRange=2)
    df = spc.interpolate( x, name="tmp" )
    aGV = adaptive(grid) # hope to get different memory
    print("End test",flush=True)

print("Start main",flush=True)
grid = structuredGrid([0,0],[1,1],[10,10])

# need to call 3 times to make sure AGP is really removed
for i in range(10):
    test(grid)
    gc.collect()
print("End main",flush=True)

It does not always fail - it depends on the AGP in one of the calls to test using a different memory location.

Current fix

The fix here is not a good solution but can be used to check the issue

Edited by Andreas Dedner

Merge request reports