A FEniCS Tutorial - FEniCS Project
A FEniCS Tutorial - FEniCS Project
A FEniCS Tutorial - FEniCS Project
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
du = Function(V)<br />
u = Function(V) # u = u_k + omega*du<br />
omega = 1.0 # relaxation parameter<br />
eps = 1.0<br />
tol = 1.0E-5<br />
iter = 0<br />
maxiter = 25<br />
while eps > tol and iter < maxiter:<br />
iter += 1<br />
A, b = assemble_system(a, L, bcs_du)<br />
solve(A, du.vector(), b)<br />
eps = numpy.linalg.norm(du.vector().array(), ord=numpy.Inf)<br />
print ’Norm:’, eps<br />
u.vector()[:] = u_k.vector() + omega*du.vector()<br />
u_k.assign(u)<br />
There are other ways of implementing the update of the solution as well:<br />
u.assign(u_k) # u = u_k<br />
u.vector().axpy(omega, du.vector())<br />
# or<br />
u.vector()[:] += omega*du.vector()<br />
The axpy(a, y) operation adds a scalar a times a Vector y to a Vector object.<br />
It is usually a fast operation calling up an optimized BLAS routine for the<br />
calculation.<br />
Mesh construction for a d-dimensional problem with arbitrary degree of the<br />
Lagrange elements can be done as explained in Section 1.16. The complete<br />
program appears in the file alg_newton_np.py.<br />
2.3 A Newton Method at the PDE Level<br />
Although Newton’s method in PDE problems is normally formulated at the<br />
linear algebra level, i.e., as a solution method for systems of nonlinear algebraic<br />
equations, we can also formulate the method at the PDE level. This approach<br />
yields a linearization of the PDEs before they are discretized. <strong>FEniCS</strong> users will<br />
probably find this technique simpler to apply than the more standard method<br />
in Section 2.2.<br />
Given an approximation to the solution field, u k , we seek a perturbation δu<br />
so that<br />
u k+1 = u k +δu (56)<br />
fulfills the nonlinear PDE. However, the problem for δu is still nonlinear and<br />
nothing is gained. The idea is therefore to assume that δu is sufficiently small<br />
so that we can linearize the problem with respect to δu. Inserting u k+1 in the<br />
PDE, linearizing the q term as<br />
q(u k+1 ) = q(u k )+q ′ (u k )δu+O((δu) 2 ) ≈ q(u k )+q ′ (u k )δu, (57)<br />
and dropping nonlinear terms in δu, we get<br />
∇·(q(u k )∇u k) +∇·(q(u k )∇δu ) +∇·(q ′ (u k )δu∇u k) = 0.<br />
54