Hi,
please consider the following code using mshr
# /usr/bin/python
from dolfin import *
from mshr import *
# Create mesh
domain_n_points = 32
domain_points = list()
for n in range(domain_n_points + 1):
x = n*1./domain_n_points
domain_points.append( Point(x, 1 + 0.2*sin(2*pi*x)) )
domain_points.append( Point(1., 0.) )
domain_points.append( Point(0., 0.) )
domain_points = domain_points[::-1] # Polygon vertices must be given in counter clockwise order.
domain = Polygon(domain_points)
mesh = generate_mesh(domain, 42)
plot(mesh)
interactive()
# Create boundaries
class Bottom(SubDomain):
def inside(self, x, on_boundary):
return on_boundary and abs(x[1]) < DOLFIN_EPS
class Right(SubDomain):
def inside(self, x, on_boundary):
return on_boundary and abs(x[0] - 1) < DOLFIN_EPS
class Left(SubDomain):
def inside(self, x, on_boundary):
return on_boundary and abs(x[0]) < DOLFIN_EPS
class Top(SubDomain):
def inside(self, x, on_boundary):
return on_boundary
boundaries = FacetFunction("size_t", mesh)
boundaries.set_all(0)
top = Top() # this will mark all the boundary, but it will be overwritten later
top.mark(boundaries, 3)
bottom = Bottom()
bottom.mark(boundaries, 1)
right = Right()
right.mark(boundaries, 2)
left = Left()
left.mark(boundaries, 4)
plot(boundaries)
interactive()
Best regards,
Francesco