Constraining the solution and its derivative on the boundary
Hi,
I'm trying to solve the Poisson equation on the unit interval with the following boundary conditions:
u''(x) = 1 for 0 <= x <= 1 BC1: u(1) = 0 BC2: u'(1) = 0
Mathematically, this is a well-posed problem, but it is not possible to apply BC2 as a natural boundary condition in the variational form, because the test function is defined to be zero at x=1 due to the constraint posed by BC1. I was able to solve this problem using a mixed formulation similar to mixed-poisson demo problem. However, this seems to be an inefficient method because it uses 2 degrees of freedom for every node in the mesh.
I saw a similar question (https:/
from dolfin import *
# Create mesh and define function space
mesh = UnitInterval(32)
Wp = FunctionSpace(mesh, "CG", 1)
R = FunctionSpace(mesh, "R", 0)
W = Wp * R
# Define trial and test functions
(u, lmbda) = TrialFunctions(W)
(v, w) = TestFunctions(W)
# Define source function
f = Constant(-1.0)
# # Define variational form ***** CORRECT SOLUTION OBTAINED BY SPECIFYING u'(0) INSTEAD OF u'(1) *****
# a = inner(grad(u), grad(v))*dx
# L = f*v*dx + v*ds(0)
# Define variational form ***** ATTEMPT USING LAGRANGE MULTIPLIER - DOES NOT WORK *****
a = inner(grad(u), grad(v))*dx - lmbda*v*ds(0) + w*(lmbda - grad(u))*ds(0)
L = f*v*dx
# Define boundary condition
def right(x):
return x[0] > 1.0 - DOLFIN_EPS
bc = DirichletBC(
# Compute solution
U = Function(W)
solve(a == L, U, bc)
(u, lmbda) = U.split(True)
grad_u = project(grad(u), FunctionSpace(mesh, 'Lagrange', 1))
# Plot solution
print u.vector(
print lmbda.vector(
plot(u, title='Solution')
plot(grad_u, title='Gradient')
interactive()
Thanks for the help.
Aravind
Question information
- Language:
- English Edit question
- Status:
- Solved
- Assignee:
- No assignee Edit question
- Solved by:
- Aravind
- Solved:
- Last query:
- Last reply: