I would like to solve a Laplace equation on a 2D domain built as a polygon. I would like to set up a combination of Dirichlet boundary conditions on different portions of the boundary.
How do I select a desired portion of a boundary (i.e, a portion of a polygon)?
To be more specific here is an example I was playing with but I know that I did not correctly specify the condition for the top boundary.
How could I specify a boundary conditions for the top boundary?
define a domain
domain_vertices = [
Point(0, 0),
Point(1, 0),
Point(1, 1),
Point(0.75, 1.1),
Point(0.7, 1.2),
Point(0.6, 1.2),
Point(0.5, 1.15),
Point(0.2, 1.1),
Point(0, 1),
Point(0, 0),
]
domain = Polygon(domain_vertices)
mesh = generate_mesh(domain,20)
V = FunctionSpace(mesh, āPā, 1)
Define boundary condition
def boundary_top(x, on_boundary):
return on_boundary and near(x[1], 1) # this is wrong
def boundary_bottom(x, on_boundary):
return on_boundary and near(x[1], 0)
u_top = Constant(2.0)
u_bottom = Constant(1.0)
bc_top = DirichletBC(V,u_top,boundary_top)
bc_bottom = DirichletBC(V,u_bottom,boundary_bottom)
bcs = [bc_top, bc_bottom]
Define variational problem
u = TrialFunction(V)
v = TestFunction(V)
f = Constant(0) # no source for the Laplace equation
a = dot(grad(u), grad(v))dx
L = fv*dx
Compute solution
u = Function(V)
solve(a == L, u, bcs)
Plot solution and mesh
plot(u,title=āsolutionā)
plot(mesh,title=āmeshā)
plt.show()