Create indicator function for boundary segment
- sindresb
- Topic Author
- New Member
Less
More
2 years 4 months ago - 2 years 4 months ago #4472
by sindresb
Create indicator function for boundary segment was created 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 havetwo 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
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
1.
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 new image: github.com/blakseth/images/blob/main/indicator2.PNG
Last edit: 2 years 4 months ago by sindresb. Reason: Missing line in the code
2 years 4 months ago #4473
by joachim
Replied by joachim on topic Create indicator function for boundary segment
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
one on top, zero on the left, and continuous is not possible alltogether.
Joachim
The following user(s) said Thank You: sindresb
- sindresb
- Topic Author
- New Member
Less
More
2 years 4 months ago - 2 years 4 months ago #4475
by sindresb
Replied by sindresb on topic Create indicator function for boundary segment
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
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 4 months ago by sindresb.
2 years 4 months ago #4476
by joachim
Replied by joachim on topic Create indicator function for boundary segment
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.
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
Time to create page: 0.123 seconds