This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Very newbie question: Dirichlet boundary conditions

0 votes

Hi,

I'm a newbie to Fenics (installed it yesterday) and I have a very fundamental question. I will try to make it simple. Suppose the case of the temperature distribution on a 2D square plate with constant temperatures at its four faces according to the equation ∇²T = 0. How do I specify those temperatures as BCs? Suppose the temperatures are Te = 50, Tn = 100, Tw = 150 and Ts = 75, where "e", "n", "w" and "s" are east, north, west and south faces respectively. I have seen examples where one Dirichlet boundary is specified, but don't know how to specify more than one of those BCs.

Any help is much appreciated. Thanks.

Fausto

asked Jul 9, 2014 by fbarbuto FEniCS Novice (160 points)

1 Answer

+3 votes

Define a Dirichlet boundary condition for each side and then pass all the bcs to the solve method, i.e.

class East(SubDomain):
    def inside(self, x , on_boundary):
       return near(x[0], 1.0)

class West(SubDomain):
    def inside(self, x , on_boundary):
       return near(x[0], 0.0)

class North(SubDomain):
    def inside(self, x , on_boundary):
       return near(x[1], 1.0)

class South(SubDomain):
    def inside(self, x , on_boundary):
       return near(x[1], 0.0)

bcs = [DirichletBC(V, Constant(50), East()),
       DirichletBC(V, Constant(100), North()),
       DirichletBC(V, Constant(150), West()),
       DirichletBC(V, Constant(75), South())]

a =...
L = ...
u = Function(V)
solve(a == L, u, bcs=bcs)
answered Jul 9, 2014 by cevito FEniCS User (5,550 points)

Brilliant! With your hints I put together a script that worked as a charm at the first attempt. Better yet, it produced the correct answer.

The shape of the plate bugged me a little though. It's kind of twisted/bent on the borders when it should be a perfectly plane surface. I wonder where my mistake is, or what I missed.

Thanks!

Fausto

...