19.06.2015 Views

A FEniCS Tutorial - FEniCS Project

A FEniCS Tutorial - FEniCS Project

A FEniCS Tutorial - FEniCS Project

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

accordingly:<br />

f = −6,<br />

{ −4, y = 1<br />

g =<br />

0, y = 0<br />

u 0 = 1+x 2 +2y 2 .<br />

For ease of programming we may introduce a g function defined over the whole<br />

of Ω such that g takes on the right values at y = 0 and y = 1. One possible<br />

extension is<br />

g(x,y) = −4y.<br />

The first task is to derive the variational problem. This time we cannot omit<br />

the boundary term arising from the integration by parts, because v is only zero<br />

on Γ D . We have<br />

∫ ∫ ∫<br />

− (∇ 2 ∂u<br />

u)vdx = ∇u·∇vdx−<br />

Ω Ω ∂Ω ∂n vds,<br />

and since v = 0 on Γ D ,<br />

∫<br />

−<br />

∂Ω<br />

∫<br />

∂u<br />

∂n vds = −<br />

Γ N<br />

∂u<br />

∂n vds = ∫<br />

Γ N<br />

gvds,<br />

by applying the boundary condition on Γ N . The resulting weak form reads<br />

∫ ∫ ∫<br />

∇u·∇vdx+ gvds = fvdx. (33)<br />

Ω Γ N<br />

Expressing this equation in the standard notation a(u,v) = L(v) is straightforward<br />

with<br />

∫<br />

a(u,v) = ∇u·∇vdx, (34)<br />

Ω<br />

∫ ∫<br />

L(v) = fvdx− gvds. (35)<br />

Γ N<br />

Ω<br />

How does the Neumann condition impact the implementation? Starting<br />

with any of the previous files d*_p2D.py, say d4_p2D.py, we realize that the<br />

statements remain almost the same. Only two adjustments are necessary:<br />

• The function describing the boundary where Dirichlet conditions apply<br />

must be modified.<br />

• The new boundary term must be added to the expression in L.<br />

Step 1 can be coded as<br />

Ω<br />

41

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!