Below is a short script that solves the poisson equation with solution u on a unit square. On one side of the square, the source term f is
f(x,y) = 1.0
The Dirichlet boundary condition is
u(1,y) = 0.0
I would also like to implement the Von Neumann boundary condition
d u(1,y) / dx = 0.0
Is this possible? Note that the script below already satisfies the boundary condition
d u(0,y) / dx = 0.0
The script:
from dolfin import *
# Create mesh and define function space
mesh = UnitSquareMesh(32, 32)
V = FunctionSpace(mesh, "Lagrange", 1)
# Define Dirichlet boundary (x = 0 or x = 1)
def boundary(x):
return x[0] > 1.0 - DOLFIN_EPS
# Define boundary condition
u0 = Constant(0.0)
bc = DirichletBC(V, u0, boundary)
# Define variational problem
u = TrialFunction(V)
v = TestFunction(V)
f = Constant(1.0)
g = Constant(0.0)
a = inner(grad(u), grad(v))*dx
L = f*v*dx + g*v*ds
# Compute solution
u = Function(V)
solve(a == L, u, bc)
# Save solution in VTK format
file = File("poisson.pvd")
file << u
# Plot solution
plot(u, interactive=True)