Having trouble with Poisson()

Asked by Matt

Hello!

I seem to be struggling with how to actually pass Dirichlet BC's to Poission(). A very prototype example, consider the "First Steps" example in the manual. If I want to change this to f=0 (Laplace's eqn.) and set the BC's such that u = 0 on the lower and left edges, but set u = 1 on the upper and right edges, how might I go about doing this?

Many thanks in advance!

Question information

Language:
English Edit question
Status:
Solved
For:
esys-escript Edit question
Assignee:
No assignee Edit question
Solved by:
Matt
Solved:
Last query:
Last reply:
Revision history for this message
Lutz Gross (l-gross) said :
#1

Unfortunately Poisson does not support inhomogeneous Dirichlet boundary conditions, so you need
to build the PDE from scratch yourself using LinearSinglePDE .

The bit which is a bit tricky is the
"u = 0 on the lower and left edges, but set u = 1 on the upper and right edges"

Here comes the script

from esys.escript import *
from esys.escript.linearPDEs import LinearSinglePDE
from esys.finley import Rectangle
#
# generate domain:
#
mydomain = Rectangle(l0=1.,l1=1.,n0=40, n1=20)
#
# define characteristic function of GammaˆD
#
x = mydomain.getX()
#
# set the solution on the entire boundary:
#
gammaD = whereZero(x[0])+whereZero(x[1])+ whereZero(x[0]-1.)+whereZero(x[1]-1.)
# "uD = 0 on the lower and left edges and uD = 1 on the upper and right edges"
# Notice that uD is used at locations where gammaD>0 only! There could be other ways to set uD.
uD=wherePositive(whereZero(x[0]-1.)+whereZero(x[1]-1.))
#
# define PDE and get its solution u
#
mypde = LinearSinglePDE(domain=mydomain)
mypde.setValue(A=kronecker(mydomain), q=gammaD, r=uD)
u = mypde.getSolution()

Revision history for this message
Matt (matt.s) said :
#2

Brilliant!

I had in fact tried defining the BC's in this manner, but I did not realize the problem was the lack of support in Poisson() and was focusing on the wrong thing it would seem. How embarrassing!

Thanks for the help, this is very useful to me.

Cheers!