I want to dynamically define subdomains. However, passing some values and using an __init__
in the subdomain class definition, leads to troubles when marking an instance of the subdomain later.
Any ideas, how to do this right?
The codesnippet below leads to the error
TypeError: in method 'SubDomain__mark', argument 1 of type 'dolfin::SubDomain const *'
caused by the last line in here:
from dolfin import *
mesh = UnitSquareMesh(12, 12)
cdcoo = dict(xmin=0.4, xmax=0.6, ymin=0.2, ymax=0.3)
# Subdomains of Control
class ContDomain(SubDomain):
def __init__(self, ddict):
self.xmin, self.xmax = ddict['xmin'], ddict['xmax']
self.ymin, self.ymax = ddict['ymin'], ddict['ymax']
def inside(self, x, on_boundary):
return ( between(x[0], (self.xmin, self.xmax)) and
between(x[1], (self.ymin, self.ymax)) )
class ContDom2(SubDomain):
def inside(self, x, on_boundary):
return ( between(x[0], (0.4, 0.6)) and
between(x[1], (0.2, 0.3)) )
domains = CellFunction('uint', mesh)
domains.set_all(0)
# dynamically defined subdomain
contdomain = ContDomain(cdcoo)
# static subdomain
contdomain2 = ContDom2()
# this works
contdomain2.mark(domains, 1)
#this fails
contdomain.mark(domains, 1)