Issue with vector-valued FacetSpace

So I have this space:

Bdy_Space = FacetFESpace(mesh, order=0, dim=2, definedon=“”, definedonbound=“Gamma”)

Note: this space has two components, or at least it should.

I then do this:

zero_vec = CoefficientFunction((0.0, 0.0))

And when I try this:

gf = GridFunction(Bdy_Space)
gf.Set(zero_vec, dual=True)

I get this error:
netgen.libngpy._meshing.NgException: Error in SetValues: gridfunction-dim = 1, but coefficient-dim = 2

It seems to think the grid function has only one component. But the Bdy_Space was specified with 2. What is the deal?

Did this get fixed? I noticed Joachim made a commit related to this.

Hey,

yes, it should be fixed now and is available in the latest nightly build.

Best,
Michael

Ok, so I guess this doesn’t update the conda ngsolve package. So I should switch to compiling everything.

So I tried using the PIP installer with the --pre flag, which supposedly gives the latest release. Everything installed properly, but I still get the error noted above about the dimension of the space.

here is a standalone code to reproduce the issue:

import numpy as np

import netgen.gui
from ngsolve import *

#from netgen.geom2d import unit_square
from netgen.geom2d import SplineGeometry

make the mesh

geo = SplineGeometry()
geo.AddRectangle( (0,0), (1,1), bc = “Gamma”)
Om_mesh = Mesh(geo.GenerateMesh(maxh=1.0))
for r in range(3):
Om_mesh.Refine()
Draw(Om_mesh)
print(Om_mesh.GetBoundaries())

bdy space

Bdy_Space = FacetFESpace(Om_mesh, order=0, dim=2, definedon=“”, definedonbound=“Gamma”)

print(" ")
num_Gm_dofs = np.sum(Bdy_Space.FreeDofs())
print("number of FreeDofs for Bdy_Space: ", num_Gm_dofs)
print("Bdy_Space FreeDof mask: ")
print(Bdy_Space.FreeDofs())

gf = GridFunction(Bdy_Space)

this does not work

#gf.Set((x*y,y), dual=True)

(this “works”, but shouldn’t)

gf.Set(x*y, dual=True)

print(gf)
#help(gf)

uu = Bdy_Space.TrialFunction()

IP = InnerProduct(gf,uu)

input(“Press Enter to finish…”)

the line: gf.Set((x*y,y), dual=True)

is what I need to work, but it doesn’t.

For the latest nightly build (self-compiled)
gf.Set((xy,y), dual=True)
works, whereas
gf.Set(x
y, dual=True)
does not work as expected.

You can try using
Bdy_Space = VectorFacetFESpace(Om_mesh, order=0, definedon=“”, definedonbound=“Gamma”)
instead of
Bdy_Space = FacetFESpace(Om_mesh, order=0, dim=2, definedon=“”, definedonbound=“Gamma”)

VectorFacetFESpace has automatically the dimension of the mesh, i.e. 2 in your example.

Best,
Michael

Thank you for this. I think the reason it did not work is because I didn’t have the latest build. The other forum thread told me what to do.

Note: I need to use the “dim” argument, because in 3-D, I need to set dim=5 (not the spatial dimension).