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.

problem = NonlinearVariationalProblem(F, u, bcs, J)<br />

solver = NonlinearVariationalSolver(problem)<br />

solver.solve()<br />

where F corresponds to the nonlinear form F(u;v), u is the unknown Function<br />

object, bcs represents the essential boundary conditions (in general a list of<br />

DirichletBC objects), and J is a variational form for the Jacobian of F.<br />

Let us explain in detail how to use the built-in tools for nonlinear variational<br />

problems and their solution. The F form corresponding to (41) is straightforwardly<br />

defined as follows, assuming q(u) is coded as a Python function:<br />

u_ = Function(V) # most recently computed solution<br />

v = TestFunction(V)<br />

F = inner(q(u_)*nabla_grad(u_), nabla_grad(v))*dx<br />

Note here that u_ is a Function (not a TrialFunction). An alternative and<br />

perhaps more intuitive formula for F is to define F(u;v) directly in terms of a<br />

trial function for u and a test function for v, and then create the proper F by<br />

u = TrialFunction(V)<br />

v = TestFunction(V)<br />

F = inner(q(u)*nabla_grad(u), nabla_grad(v))*dx<br />

u_ = Function(V) # the most recently computed solution<br />

F = action(F, u_)<br />

The latter statement is equivalent to F(u = u − ;v), where u − is an existing<br />

finite element function representing the most recently computed approximation<br />

to the solution. (Note that u k and u k+1 in the previous notation correspond to<br />

u − and u in the present notation. We have changed notation to better align the<br />

mathematics with the associated UFL code.)<br />

ThederivativeJ (J)ofF (F)isformallytheGateauxderivativeDF(u k ;δu,v)<br />

of F(u;v) at u = u − in the direction of δu. Technically, this Gateaux derivative<br />

is derived by computing<br />

lim<br />

ǫ→0<br />

d<br />

dǫ F i(u − +ǫδu;v). (62)<br />

The δu is now the trial function and u − is the previous approximation to the<br />

solution u. We start with<br />

∫<br />

d<br />

∇v ·(q(u − +ǫδu)∇(u − +ǫδu)) dx<br />

dǫ<br />

Ω<br />

and obtain<br />

∫<br />

∇v ·[q ′ (u − +ǫδu)δu∇(u − +ǫδu)+q(u − +ǫδu)∇δu] dx,<br />

Ω<br />

which leads to<br />

∫<br />

Ω<br />

∇v ·[q ′ (u − )δu∇(u − )+q(u − )∇δu] dx, (63)<br />

56

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

Saved successfully!

Ooh no, something went wrong!