SubDomain::mark does not always work (with odd number of mesh points)
from dolfin import *
mesh = IntervalMesh(201, 0,1e-6)
def region1(x,on_boundary): return between(x[0],(0.0,0.5e-6))
def region2(x,on_boundary): return between(x[0],(0.5e-6,1e-6))
r1 = AutoSubDomain(region1)
r2 = AutoSubDomain(region2)
f = CellFunction('size_t',mesh)
r1.mark(f,1)
r2.mark(f,2)
f.array()
There is a zero at the interface but I should not have to make my inside functions overlap at the interface. And it works as expected if I use 200 points instead of 201 points.
Comments (10)
-
-
- changed status to invalid
Please use the QA forum for usage questions.
-
reporter Ok. Does DOLFIN_EPS always work as that small number or does it depend on the mesh coordinates?
-
Depends on the extent of the mesh coordinates yes.
Personally I avoid DOLFIN_EPS, near() and between() and use my own epsilons.
-
reporter Also after looking at the implementation for "between" it looks like DOLFIN_EPS is already accounted for, but the marking still fails. Where does this break in the code?
-
Actually your limits in between don't make any sense. Take a close look at those numbers.
-
reporter - edited description
-
reporter Yes that was a typo. I fixed it. The problem still remains for me. I tried it with a UnitIntervalMesh too. So just out of curiosity why do you have to use mesh dependent epsilons?
-
This is wrong:
def region1(x,on_boundary): return between(x[0],(0.0,0.5e-6)) def region2(x,on_boundary): return between(x[0],(0.5e-6,1e-6))
should be
def region1(x,on_boundary): return between(x[0],(0.0,0.5)) def region2(x,on_boundary): return between(x[0],(0.5,1.0))
Because floats are approximations to real numbers: https://en.wikipedia.org/wiki/Floating_point
Please use the QA forum for questions.
-
- removed milestone
Removing milestone: 1.7 (automated comment)
- Log in to comment
You need to add/subtract small numbers from your limits to include endpoints robustly.
Only cells where all vertices are inside will be marked.