SubDomain::mark does not always work (with odd number of mesh points)

Issue #565 invalid
Chaffra Affouda created an issue
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)

  1. Martin Sandve Alnæs

    You need to add/subtract small numbers from your limits to include endpoints robustly.

    Only cells where all vertices are inside will be marked.

  2. Chaffra Affouda reporter

    Ok. Does DOLFIN_EPS always work as that small number or does it depend on the mesh coordinates?

  3. Martin Sandve Alnæs

    Depends on the extent of the mesh coordinates yes.

    Personally I avoid DOLFIN_EPS, near() and between() and use my own epsilons.

  4. Chaffra Affouda 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?

  5. Martin Sandve Alnæs

    Actually your limits in between don't make any sense. Take a close look at those numbers.

  6. Chaffra Affouda 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?

  7. Martin Sandve Alnæs

    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.

  8. Log in to comment