How to set up finite element space for 1d periodic mesh correctly?

Hallo!

I’m trying to define a finite element space on 1d periodic mesh with the following simple codes:

########################
from ngsolve import *
from ngsolve.meshes import Make1DMesh

n = 3
mymesh = Make1DMesh(n, periodic = True)

fes = Periodic(H1(mymesh,order=1))
u,v = fes.TnT()

a = BilinearForm(fes)
a += uvds

a.Assemble()
print(a.mat)
########################

When I ran these codes, it said “used dof inconsistency
(silence this warning by setting BilinearForm(…check_unused=False) )”
with “print(a.mat)” to be:

Row 0: 0: 2 1: 0 2: 0
Row 1: 0: 0 1: 0 2: 0
Row 2: 0: 0 1: 0 2: 0
Row 3:

this mass matrix is definitely not correct for periodic setting.

Does anyone know what’s wrong in the codes? Thank you very much!

Hi,

with
uvds
you are integrating only over the boundary of the mesh. To obtain the mass matrix you have to use dx instead of ds.

Best,
Michael

Thank you Michael! I’m new to NGsolve. May I ask another simple question?

After I changed ds to dx, “print(fes.ndof)” is 4 instead of 3 (actual nodes number). Moreover if I set the gridfunction below

gfu = GridFunction(fes)
gfu.Set(cos(2pix))

the first entry does not coincide with the 4th entry. So it seems to break the periodic condition. Do you have any idea?

Hi,

the behavior is correct. If you plot fes.FreeDofs() you observe that the last dof is “not-free”, it depends on the first one due to periodicity. If you draw the function you get a periodic function

from ngsolve.internal import visoptions
from ngsolve.internal import viewoptions
visoptions.showsurfacesolution=True
viewoptions.drawedges=1
visoptions.deformation=1
Draw(gfu, mymesh, “gfu”)

With fes = Compress(Periodic(H1(mymesh,order=1))) the last dof is compressed out and you have only 3 dofs left.

Best,
Michael