Create indicator function for boundary segment

More
2 years 1 month ago - 2 years 1 month ago #4472 by sindresb
Hello!

I want to create an indicator function that is 1 on some chosen boundary segment and 0 elsewhere.
For this purpose, I have attempted to use a GridFunction defined using the following code:

from netgen.geom2d import unit_square
import ngsolve as ng
from ngsolve.webgui import Draw

domain = unit_square
mesh = ng.Mesh(domain.GenerateMesh(maxh=1./32))
fes = ng.H1(mesh, order=1, dirichlet="top|bottom|left|right")
v = ng.GridFunction(fes)
v.Set(1, definedon=mesh.Boundaries("top"))
Draw(v, mesh)

I have two one questions regarding the output of this code (see link at bottom).
1. Why does the non-zero region extend so far into the domain interior? I would assume that it is at least possible for the elements not touching the boundary to be all zero.
2. Is it possible to force v to be zero on the entirety of the left boundary?

Any help would be much appreciated!

Best regards,
Sindre

Link to image: github.com/blakseth/images/blob/main/indicator.PNG
Link to new image: github.com/blakseth/images/blob/main/indicator2.PNG
Last edit: 2 years 1 month ago by sindresb. Reason: Missing line in the code
More
2 years 1 month ago #4473 by joachim
you don't define fes here - maybe you have defined it somewhere else, on a coarse mesh ?

one on top, zero on the left, and continuous is not possible alltogether.

Joachim
The following user(s) said Thank You: sindresb
More
2 years 1 month ago - 2 years 1 month ago #4475 by sindresb
Thank you for the reply, and my apologies for the error in the MWE! The MWE has been fixed and I have uploaded a new image showing the new output.
It seems your suspicion was correct.

So is it correct then that the answer to question two is "no" because the Grid Function must be continuous?

Best,
Sindre
Last edit: 2 years 1 month ago by sindresb.
More
2 years 1 month ago #4476 by joachim
You can use a FacetFESpace(mesh, order=0) instead of the H1.
Then you have a independent constant (polynomial of order 0) for every edge.

It allows 1 on top and 0 on the left.
The following user(s) said Thank You: sindresb
More
2 years 1 month ago - 2 years 1 month ago #4477 by sindresb
That works, thank you!
Best,
Sindre
Last edit: 2 years 1 month ago by sindresb.
Time to create page: 0.120 seconds