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.

iter += 1<br />

solve(a == L, u, bcs)<br />

diff = u.vector().array() - u_k.vector().array()<br />

eps = numpy.linalg.norm(diff, ord=numpy.Inf)<br />

print ’iter=%d: norm=%g’ % (iter, eps)<br />

u_k.assign(u) # update for next iteration<br />

We need to define the previous solution in the iterations, u_k, as a finite element<br />

function so that u_k can be updated with u at the end of the loop. We may<br />

create the initial Function u_k by interpolating an Expression or a Constant<br />

to the same vector space as u lives in (V).<br />

Inthecodeabovewedemonstratehowtousenumpyfunctionalitytocompute<br />

the norm of the difference between the two most recent solutions. Here we apply<br />

the maximum norm (l ∞ norm) on the difference of the solution vectors (ord=1<br />

and ord=2 give the l 1 and l 2 vector norms – other norms are possible for numpy<br />

arrays, see pydoc numpy.linalg.norm).<br />

The file picard_np.py contains the complete code for this nonlinear Poisson<br />

problem. The implementation is d dimensional, with mesh construction and<br />

setting of Dirichlet conditions as explained in Section 1.16. For a 33×33 grid<br />

with m = 2 we need 9 iterations for convergence when the tolerance is 10 −5 .<br />

2.2 A Newton Method at the Algebraic Level<br />

After having discretized our nonlinear PDE problem, we may use Newton’s<br />

method to solve the system of nonlinear algebraic equations. From the continuous<br />

variational problem (40), the discrete version (42) results in a system of<br />

equations for the unknown parameters U 1 ,...,U N (by inserting u = ∑ N<br />

j=1 U jφ j<br />

and v = ˆφ i in (42)):<br />

F i (U 1 ,...,U N ) ≡<br />

N∑<br />

∫<br />

j=1<br />

Ω<br />

( ( N<br />

) )<br />

∑<br />

q U l φ l ∇φ j U j ·∇ˆφ i dx = 0, i = 1,...,N .<br />

l=1<br />

(49)<br />

Newton’s method for the system F i (U 1 ,...,U j ) = 0, i = 1,...,N can be formulated<br />

as<br />

N∑<br />

j=1<br />

∂<br />

∂U j<br />

F i (U k 1,...,U k N)δU j = −F i (U k 1,...,U k N), i = 1,...,N, (50)<br />

U k+1<br />

j = U k j +ωδU j , j = 1,...,N, (51)<br />

where ω ∈ [0,1] is a relaxation parameter, and k is an iteration index. An initial<br />

guess u 0 must be provided to start the algorithm.<br />

The original Newton method has ω = 1, but in problems where it is difficult<br />

toobtainconvergence, so-calledunder-relaxation withω < 1mayhelp. Itmeans<br />

that one takes a smaller step than what is suggested by Newton’s method.<br />

We need, in a program, to compute the Jacobian matrix ∂F i /∂U j and the<br />

right-hand side vector −F i . Our present problem has F i given by (49). The<br />

51

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

Saved successfully!

Ooh no, something went wrong!