Forum Message

 

 

We have moved the forum to https://forum.ngsolve.org . This is an archived version of the topics until 05/05/23. All the topics were moved to the new forum and conversations can be continued there. This forum is just kept as legacy to not invalidate old links. If you want to continue a conversation just look for the topic in the new forum.

Notice

The forum is in read only mode.

'Set' of GridFunction do not work correctly for surface mesh.

More
2 years 10 months ago #3788 by yzz
Hi,

When I set a grid function defined on a surface, the results seem wrong. See the following code and output.

When I set the parameter to `BND`, the values of h_n are still all zeros.
Code:
from ngsolve import * from netgen.csg import * from netgen.meshing import MeshingStep # from ngsolve.webgui import Draw geo = CSGeometry() sphere = Sphere(Pnt(0, 0, 0), 1).bc('inner') left = Plane(Pnt(0.75, 0, 0), Vec(-1, 0, 0)) fsphere = sphere*left geo.AddSurface(sphere, fsphere) geo.NameEdge(sphere, fsphere, 'boundary') mesh = Mesh(geo.GenerateMesh(maxh=0.3)) # Draw(mesh) print_vec = lambda u: print([_ for _ in u.vec.data]) V_H = H1(mesh) print(V_H.FreeDofs()) h = CoefficientFunction(1) h_n = GridFunction(V_H) h_n.Set(h) print_vec(h_n) h_n.Set(h, BND) print_vec(h_n) h_n.Set(h, BBND) print_vec(h_n)


Code:
0: 1111111111111111111111111111 [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] [1.0, 1.0, 1.0, 1.0, 0.9999999999999999, 1.0, 1.0, 1.0, 1.0, 0.9999999999999998, 1.0, 0.9999999999999999, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
More
2 years 10 months ago #3789 by mneunteufel
Hi,

to set a function on the whole boundary, which is not marked explicitly as Dirichlet boundary, you have to use the syntax
Code:
h_n.Set(h, definedon=mesh.Boundaries(".*"))

When setting explicitly the whole boundary as Dirichlet boundary then the code works
Code:
V_H = H1(mesh, dirichlet=".*") ... h_n.Set(h, BND)

Best,
Michael
More
2 years 10 months ago #3791 by yzz
Thanks, Michael.

Best wishes,
Zongze Yang
Time to create page: 0.112 seconds