Hi,
I was wondering if there was a way to switch between nodal values and moments regarding the degrees of freedom of an L2 space. I tried to follow what is written in Dual basis functions without success.
As of now if I run
from ngsolve import *
import matplotlib.pyplot as plt
mesh = Mesh(unit_square.GenerateMesh(maxh = 0.1))
fes = L2(mesh, order = 1)
gfu = GridFunction(fes)
gfu.Set(1)
then gfu.vec.data
has zeros and ones as it should be. How can I get the values at the corresponding Lagrange nodes, so to have all ones for order=1
?
Thanks a lot for your help
You can use
fes = Discontinuous(H1(mesh, order=1))
Oh I see, thanks a lot that is exactly what I was looking for! I now wrote a little script to pass from one version to the other:
from ngsolve import *
from ngsolve.webgui import Draw
from netgen.geom2d import unit_square
mesh = Mesh(unit_square.GenerateMesh(maxh=0.2))
fesl2 = L2(mesh, order=1)
fesdh1 = Discontinuous(H1(mesh, order=1, dgjumps = True))
gful2 = GridFunction(fesl2)
gful2.Set(1)
gfudh1 = GridFunction(fesdh1)
def transform_funct(fesl2, fesdh1, gful2, gfudh1):
amixed = BilinearForm(trialspace=fesl2, testspace=fesdh1)
adh1 = BilinearForm(fesdh1)
u,v = fesdh1.TnT()
vdual = v.Operator('dual')
uh1 = fesl2.TrialFunction()
dS = dx(element_boundary=True)
adh1 += u*vdual * dx + u*vdual * dS
adh1.Assemble()
amixed += uh1*vdual*dx + uh1*vdual*dS
amixed.Assemble()
# build transformation operator:
transform = adh1.mat.Inverse() @ amixed.mat
gfudh1.vec.data = transform * gful2.vec
transform_funct(fesl2, fesdh1, gful2, gfudh1)
print(gfudh1.vec.data)
Draw (gful2)
Draw (gfudh1)
But I have noticed that:
This leads to an empty matrix for adh1
. It seems like using v
instead of vdual
does the job
If I use L2(mesh, order=1, dgjumps = True)
and try to do the inverse conversion then the software just crashes
Any idea on why is it happening?
Thanks,
Alessandro
joachim
February 13, 2025, 8:43pm
4
For H1, the dual basis functions contain co-dimension 2 (and codim 3 for 3D) functionals, see the dual basis function tutorial.
There is a builtin functionality for that purpose, with a lot of options:
transform = ConvertOperator(fesL2, fesH1, geom_free=True)
gfH1.vec.data = transform * gfL2.vec
I see, thank you very much for the clarification