19.06.2015 Views

A FEniCS Tutorial - FEniCS Project

A FEniCS Tutorial - FEniCS Project

A FEniCS Tutorial - FEniCS Project

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

derivative ∂F i /∂U j becomes<br />

⎡<br />

∫<br />

(<br />

N∑ N∑<br />

N<br />

) ⎤<br />

∑<br />

⎣q ′ ( Ul k φ l )φ j ∇( Uj k φ j )·∇ˆφ i +q Ul k φ l ∇φ j ·∇ˆφ i<br />

⎦ dx. (52)<br />

Ω<br />

l=1 j=1<br />

l=1<br />

The following results were used to obtain (52):<br />

∂u<br />

= ∂ ∑ N<br />

U j φ j = φ j ,<br />

∂U j ∂U j<br />

j=1<br />

∂<br />

∂U j<br />

∇u = ∇φ j ,<br />

∂<br />

∂U j<br />

q(u) = q ′ (u)φ j . (53)<br />

We can reformulate the Jacobian matrix in (52) by introducing the short notation<br />

u k = ∑ N<br />

j=1 Uk j φ j:<br />

∫<br />

∂F<br />

]<br />

i<br />

=<br />

[q ′ (u k )φ j ∇u k ·∇ˆφ i +q(u k )∇φ j ·∇ˆφ i dx. (54)<br />

∂U j<br />

Ω<br />

In order to make <strong>FEniCS</strong> compute this matrix, we need to formulate a corresponding<br />

variational problem. Looking at the linear system of equations in<br />

Newton’s method,<br />

N∑<br />

j=1<br />

∂F i<br />

∂U j<br />

δU j = −F i , i = 1,...,N,<br />

wecanintroducev asageneraltestfunctionreplacing ˆφ i ,andwecanidentifythe<br />

unknownδu = ∑ N<br />

j=1 δU jφ j . Fromthelinearsystemwecannowgo”backwards”<br />

to construct the corresponding linear discrete weak form to be solved in each<br />

Newton iteration:<br />

∫<br />

[<br />

q ′ (u k )δu∇u k ·∇v +q(u k )∇δu·∇v ] ∫<br />

dx = − q(u k )∇u k ·∇vdx. (55)<br />

Ω<br />

This variational form fits the standard notation a(δu,v) = L(v) with<br />

∫<br />

[<br />

a(δu,v) = q ′ (u k )δu∇u k ·∇v +q(u k )∇δu·∇v ] dx<br />

Ω<br />

∫<br />

L(v) = − q(u k )∇u k ·∇vdx.<br />

Ω<br />

Note the important feature in Newton’s method that the previous solution u k<br />

replaces u in the formulas when computing the matrix ∂F i /∂U j and vector F i<br />

for the linear system in each Newton iteration.<br />

We now turn to the implementation. To obtain a good initial guess u 0 , we<br />

can solve a simplified, linear problem, typically with q(u) = 1, which yields<br />

the standard Laplace equation ∇ 2 u 0 = 0. The recipe for solving this problem<br />

appears in Sections 1.2, 1.3, and 1.13. The code for computing u 0 becomes as<br />

follows:<br />

Ω<br />

52

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

Saved successfully!

Ooh no, something went wrong!