A FEniCS Tutorial - FEniCS Project
A FEniCS Tutorial - FEniCS Project
A FEniCS Tutorial - FEniCS Project
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Let us continue to use our favorite solution u(x,y) = 1 + x 2 + 2y 2 and<br />
then prescribe p(x,y) = x + y. It follows that u 0 (x,y) = 1 + x 2 + 2y 2 and<br />
f(x,y) = −8x−10y.<br />
What are the modifications we need to do in the d4_p2D.py program from<br />
Section 1.6?<br />
• f must be an Expression since it is no longer a constant,<br />
• a new Expression ‘p‘ must be defined for the variable coefficient,<br />
• the variational problem is slightly changed.<br />
First we address the modified variational problem. Multiplying the PDE by a<br />
test function v and integrating by parts now results in<br />
∫ ∫<br />
p∇u·∇vdx− p ∂u<br />
∂n<br />
∫Ω<br />
vds = fvdx.<br />
Ω<br />
∂Ω<br />
The function spaces for u and v are the same as in Section 1.2, implying that<br />
the boundary integral vanishes since v = 0 on ∂Ω where we have Dirichlet<br />
conditions. The weak form a(u,v) = L(v) then has<br />
∫<br />
a(u,v) = p∇u·∇vdx, (22)<br />
Ω<br />
∫<br />
L(v) = fvdx. (23)<br />
In the code from Section 1.3 we must replace<br />
a = inner(nabla_grad(u), nabla_grad(v))*dx<br />
by<br />
a = p*inner(nabla_grad(u), nabla_grad(v))*dx<br />
The definitions of p and f read<br />
p = Expression(’x[0] + x[1]’)<br />
f = Expression(’-8*x[0] - 10*x[1]’)<br />
Ω<br />
No additional modifications are necessary. The complete code can be found in<br />
in the file vcp2D.py (variable-coefficient Poisson problem in 2D). You can run<br />
it and confirm that it recovers the exact u at the nodes.<br />
The flux −p∇u may be of particular interest in variable-coefficient Poisson<br />
problems as it often has an interesting physical significance. As explained in<br />
Section 1.9, we normally want the piecewise discontinuous flux or gradient to be<br />
approximated by a continuous vector field, using the same elements as used for<br />
29