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.
an implementation where u is the TrialFunction. We have implemented both<br />
approaches in two files: vp1_np.py with u as TrialFunction, and vp2_np.py<br />
with du as TrialFunction. The directory stationary/nonlinear_poisson<br />
contains both files. The first command-line argument determines if the Jacobian<br />
is to be automatically derived or computed from the hand-derived formula.<br />
The following code defines the nonlinear variational problem and an associated<br />
solver based on Newton’s method. We here demonstrate how key parameters<br />
in Newton’s method can be set, as well as the choice of solver and<br />
preconditioner, and associated parameters, for the linear system occurring in<br />
the Newton iteration.<br />
problem = NonlinearVariationalProblem(F, u_, bcs, J)<br />
solver = NonlinearVariationalSolver(problem)<br />
prm = solver.parameters<br />
prm[’newton_solver’][’absolute_tolerance’] = 1E-8<br />
prm[’newton_solver’][’relative_tolerance’] = 1E-7<br />
prm[’newton_solver’][’maximum_iterations’] = 25<br />
prm[’newton_solver’][’relaxation_parameter’] = 1.0<br />
if iterative_solver:<br />
prm[’linear_solver’] = ’gmres’<br />
prm[’preconditioner’] = ’ilu’<br />
prm[’krylov_solver’][’absolute_tolerance’] = 1E-9<br />
prm[’krylov_solver’][’relative_tolerance’] = 1E-7<br />
prm[’krylov_solver’][’maximum_iterations’] = 1000<br />
prm[’krylov_solver’][’gmres’][’restart’] = 40<br />
prm[’krylov_solver’][’preconditioner’][’ilu’][’fill_level’] = 0<br />
set_log_level(PROGRESS)<br />
solver.solve()<br />
A list of available parameters and their default values can as usual be printed by<br />
calling info(prm, True). The u_ we feed to the nonlinear variational problem<br />
object is filled with the solution by the call solver.solve().<br />
3 Time-Dependent Problems<br />
The examples in Section 1 illustrate that solving linear, stationary PDE problems<br />
with the aid of <strong>FEniCS</strong> is easy and requires little programming. That is,<br />
<strong>FEniCS</strong> automates the spatial discretization by the finite element method. The<br />
solutionofnonlinearproblems, asweshowedinSection2, canalsobeautomated<br />
(cf. Section 2.4), but many scientists will prefer to code the solution strategy of<br />
the nonlinear problem themselves and experiment with various combinations of<br />
strategies in difficult problems. Time-dependent problems are somewhat similar<br />
in this respect: we have to add a time discretization scheme, which is often quite<br />
simple, making it natural to explicitly code the details of the scheme so that the<br />
programmer has full control. We shall explain how easily this is accomplished<br />
through examples.<br />
58