Hi, the following snippet uses an instance of SubDomain
class to mark cells of the mesh that are in inside the circle with flag 1. Assembler then uses only these cells to get the approximate area.
from dolfin import *
class Circle(SubDomain):
'Interior of circle with radius r centered at (x_c, y_c).'
def __init__(self, x_c, y_c, r):
self.x_c = x_c
self.y_c = y_c
self.r = r
SubDomain.__init__(self)
def inside(self, x, on_boundary):
return (x[0]-self.x_c)**2 + (x[1]-self.y_c)**2 < self.r**2
mesh = UnitSquareMesh(100, 100)
cell_f = CellFunction('size_t', mesh, 0)
dx = Measure('dx')[cell_f]
x0, y0, r = 0., 0., 0.125
circle = Circle(x0, y0, r)
def displace(circle, step):
if step < 5 or step >= 11:
circle.x_c += 0.1
circle.y_c += 0.1
elif step < 8:
circle.r += 0.1
elif step < 11:
circle.r -= 0.1
t = 0
for step in range(17):
circle.mark(cell_f, 1)
plot(cell_f)
print 'area', assemble(1*dx(1, domain=mesh))
displace(circle, step)
# Set all tags to zero for fresh start in next iteration
cell_f.set_all(0)
interactive()