Shifting of Gridfunction

Hi,
I have a 1d Gridfunction, and I would like to shift it by a fixed amount (extending by a constant outside) and re-interpolate it to the same grid. Is there a convenient way to do this in ngsolve? It seems like I can’t just write something like u_shifted=u(ngsolve.x+shift) to generate a shifted CoefficientFunction.

Thanks,
Alex

in 2 (and 3) dimension it works like this:


from netgen.occ import *
from ngsolve import *
from ngsolve.fem import CoordinateTrafo

cf = sin(10*x)

mesh = Mesh(unit_square.GenerateMesh(maxh=0.1))

fes = H1(mesh, order=3)

u = GridFunction(fes)

shift = 0.3
u.Set(IfPos(x-0.3, cf(CoordinateTrafo((IfPos(x-0.3, x-0.3, 0), y, 0), mesh.Materials(".*"))), 0))

Draw(cf, mesh, "cf")
Draw(u, mesh, "u")

I think 1d should also work, but I think untested. if there are problems let me know

The inner ifpos guard is just so that it never evaluates outside of the domain the cf which would lead to a segfault