Consider the following example:
from dolfin import *
mesh = UnitSquareMesh(1, 1)
sub_domains = CellFunction("size_t", mesh)
sub_domains.set_all(0)
switched_element_expression = Expression("x[0]")
class SwitchedElementSet(SubDomain):
def __init__(self, switched_expression):
SubDomain.__init__(self)
self.switched_expression = switched_expression
self.count = 0
def inside(self, x, on_boundary):
y = self.switched_expression(x)
self.count += 1
print self.count, y, y > 0.2
return y > 0.2 #with this it gets called only once
#return True #with this it gets called six times
switched_element_set = SwitchedElementSet(switched_element_expression)
switched_element_set.mark(sub_domains, 1)
Why inside gets called only once?