Autoupdate for GridFunctions

Hello all!

I have been working on adaptivity for eigenvalues recently. I am a bit confused with the autoupdate feature of GridFunctions. Is the update after a mesh refinement intended to erase the content of the GridFunction and resize the GridFunction vector into a null vector?

I would like to update the GridFunctions and obtain an updated GridFunction defined over the new mesh (an automatic interpolation), without loosing any data, if that makes sense.

Attached a small example. I would like the second output to be non zero. Specifically, an equivalent of gf_u1.Set(cos(x)) after mesh.Refine() (without resetting cosine, in this example).

from ngsolve import *
from netgen.occ import unit_square

mesh = Mesh(unit_square.GenerateMesh(maxh=0.4))
fes = H1(mesh, order=1, autoupdate=True)

gf_u1 = GridFunction(fes, autoupdate=True)

print("gf_u1.vec.FV().NumPy():\n", gf_u1.vec.FV().NumPy())
print("gf_u1.vec.FV().NumPy():\n", gf_u1.vec.FV().NumPy())

Thanks for the help,

Hi Gabriel,

you have to provide the nested flag to trigger the prolongation:

gf_u1 = GridFunction(fes, autoupdate=True, nested=True)

I am thinking of making it the default behaviour.


This is great!

Thank you, Joachim.