Define circle SubDomains with different radii

Dear all,

for post processing, I need to integrate over different domains equal to circles with identical centres but different radii.

That’s why I am wondering how I could efficiently (in terms of code which has to be written) define integration domains needed.

As far as I can see, it is not possible to define a subclass of SubDomain having a constructor asking for the domain radius as argument: The following code

class intDomain(SubDomain):

def _ _ init _ _(self,r):

self.r=r

def inside (self,x,on_boundary):

return np.sqrt(np.power(x[0]-ct_pos[0],2)+np.power(x[1]-ct_pos[1],2))<(r)

#MeshFunction used for marking integration domain

cfDomain=MeshFunction("size_t",mesh,2)

cfDomain.set_all(0)

intDomain_obj=intDomain(r=0.32)

intDomain_obj.mark(cfDomain,1) #integration domain

dx_cf=Measure("dx",domain=mesh,subdomain_data=cfDomain)

threw an error:

Traceback (most recent call last):

File "test.py", line 58, in <module>

intDomain_obj.mark(cfDomain,1) #integration domain

File "/usr/lib/python3/dist-packages/dolfin/cpp/mesh.py", line 4814, in mark

self._mark(*args)

TypeError: in method ‘SubDomain__mark’, argument 1 of type ‘dolfin::SubDomain const *’

Does anybody have an idea for an approach to this issue?

Consider

from dolfin import *

circle = CompiledSubDomain('(x[0]-x0)*(x[0]-x0) + (x[1]-x1)*(x[1]-x1) < r*r',
                           x0=0, x1=0, r=1)

mesh = UnitSquareMesh(32, 32)
f = MeshFunction('size_t', mesh, 2, 0)

area = Constant(1)*dx(domain=mesh, subdomain_data=f, subdomain_id=1)

circle.mark(f, 1)
print(assemble(area))

f.set_all(0)
circle.x0 = 0.5
circle.x1 = 0.5
circle.r = 0.2
circle.mark(f, 1)
print(assemble(area))
1 Like

Thanks, this solved my problem :slight_smile:

There seems to be an issue concerning attributes of CompiledSubDomain objects in Fenics 2018.1. I created a new post describing this general problem: