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.

where backendname is a string, either ’PETSc’, ’uBLAS’, ’Epetra’, or ’MTL4’.<br />

All these backends offer high-quality implementations of both iterative and direct<br />

solvers for linear systems of equations.<br />

A common platform for <strong>FEniCS</strong> users is Ubuntu Linux. The <strong>FEniCS</strong> distribution<br />

for Ubuntu contains PETSc, making this package the default linear<br />

algebra backend. The default solver is sparse LU decomposition (’lu’), and<br />

the actual software that is called is then the sparse LU solver from UMFPACK<br />

(which PETSc has an interface to).<br />

We will normally like to control the tolerance in the stopping criterion and<br />

the maximum number of iterations when running an iterative method. Such<br />

parameters can be set by accessing the global parameter database, which is called<br />

parameters and which behaves as a nested dictionary. Write<br />

info(parameters, True)<br />

to list all parameters and their default values in the database. The nesting of<br />

parameter sets is indicated through indentation in the output from info. According<br />

to this output, the relevant parameter set is named ’krylov_solver’,<br />

and the parameters are set like this:<br />

prm = parameters[’krylov_solver’] # short form<br />

prm[’absolute_tolerance’] = 1E-10<br />

prm[’relative_tolerance’] = 1E-6<br />

prm[’maximum_iterations’] = 1000<br />

Stopping criteria for Krylov solvers usually involve the norm of the residual,<br />

which must be smaller than the absolute tolerance parameter or smaller than<br />

the relative tolerance parameter times the initial residual.<br />

To see the number of actual iterations to reach the stopping criterion, we<br />

can insert<br />

set_log_level(PROGRESS)<br />

# or<br />

set_log_level(DEBUG)<br />

A message with the equation system size, solver type, and number of iterations<br />

arises from specifying the argument PROGRESS, while DEBUG results in more information,<br />

includingCPUtimespentinthevariouspartsofthematrixassembly<br />

and solve process.<br />

The complete solution process with control of the solver parameters now<br />

contains the statements<br />

prm = parameters[’krylov_solver’] # short form<br />

prm[’absolute_tolerance’] = 1E-10<br />

prm[’relative_tolerance’] = 1E-6<br />

prm[’maximum_iterations’] = 1000<br />

set_log_level(PROGRESS)<br />

solve(a == L, u, bc,<br />

solver_parameters={’linear_solver’: ’cg’,<br />

’preconditioner’: ’ilu’})<br />

16

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

Saved successfully!

Ooh no, something went wrong!