Subject: Re: [Ufl] [Question #215444]: how does FEniCS apply the Dirichlet boundary conditions on unitcircle

From: Huadong GAO <[email-masked]>
Date: Thu, 29 Nov 2012 02:55:58 -0000

Question #215444 on UFL changed:
https://answers.launchpad.net/ufl/+question/215444

    Status: Answered => Open

Huadong GAO is still having a problem:
First thanks Johan's help.   A simple python code is attached below. I use quadratic element
solving Poisson Equation on the UnitCircle domain, I do not know how FEniCS apply the Dirichlet boundary conditions. I mean the how to determine the value at the midpoint of the boundary edge ?

######################################
from dolfin import *

mesh = UnitCircle(5)
V = FunctionSpace(mesh, "Lagrange", degree=2)

u = TrialFunction(V)
v = TestFunction(V)

#--------------------------------------------
f = Expression("1.0")
u_e = Expression("exp(x[0]+x[1]-t)",t=0)
#--------------------------------------------

a = inner(nabla_grad(u),nabla_grad(v))*dx
v = f*v*dx

def boundary(x,on_boundary):
    return on_boundary

bc = DirichletBC(V,u_e,boundary)

A = assemble(a)
b = assemble(v)
bc.apply(A,b)
u = Function(V)
solver = KrylovSolver("gmres", "ilu")            
solver.solve(A, u.vector(), b)

plot(mesh)
plot(u)
interactive()
######################################

-- 
You received this question notification because you are a member of UFL
Team, which is an answer contact for UFL.

---

From: Johan Hake <[email-masked]>
Date: Thu, 29 Nov 2012 08:29:57 +0100

You can read more in detail about this in the FEniCS book. Search for
DirichletBC. You can also get some usefull information by

>>> help(DirichletBC)

in a Python session.

As far as I can see there is nothing wrong with your script.

Johan

---

From: Huadong GAO <[email-masked]>
Date: Thu, 29 Nov 2012 07:51:05 -0000

Status: Answered => Open

Thanks Johan again.

I just want to know how does FEniCS define the value of the node at
boundary edge, say,

for the UnitCircle partition the following element is near the boudary,
we can assume edge 1-2-3 is the boundary, and when applying Dirichlet boundary conditions,  we have to know the values of the equation at  nodes 1, 2 and 3,
 
node 1 and node 3 lay on the boundary so we can directly use these values, but the value of node2 is difficult to get, as node 2 is not on the boundary exactly, 

my question is how FEniCS treat this.

1         2              3
o--------o-----------o
 \                       /
   \                   /
    o  4           o 5
       \           /
         \       /   
           \   /
             o  6

---

From: Johan Hake <[email-masked]>
Date: Thu, 29 Nov 2012 10:38:32 +0100

Have you read the docstring of DirichletBC?

Johan

---

From: Huadong GAO <[email-masked]>
Date: Thu, 29 Nov 2012 12:20:59 -0000

Status: Answered => Open

Huadong GAO is still having a problem:
Thanks Johan's help.  Sorry for replying so late, I have  class and TA
duties today.

I have read the document help(DirichletBC), it is said that FEniCS uses
the expression to compute the value of the boundary nodes. I guess for
quadratic and higher element FEniCS will still use the expression to
calculate the values of the boundary nodes directly.

For the unitcircle domain if linear elment is used, all the boundary nodes are exactly on the circle boundary.
But in fact, in the case of quadratic elment method or high order element methods, some boundary nodes  are not on the circle boundary.