19.06.2015 Views

A FEniCS Tutorial - FEniCS Project

A FEniCS Tutorial - FEniCS Project

A FEniCS Tutorial - FEniCS Project

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

The demo program d2_p2D.py in the stationary/poisson directory incorporates<br />

the above shown control of the linear solver and precnditioner, but is<br />

otherwise similar to the previous d1_p2D.py program.<br />

We remark that default values for the global parameter database can be<br />

defined in an XML file, see the example file dolfin_parameters.xml in the<br />

directory stationary/poisson. If such a file is found in the directory where a<br />

<strong>FEniCS</strong> program is run, this file is read and used to initialize the parameters<br />

object. Otherwise, the file .config/fenics/dolfin_parameters.xml in the<br />

user’s home directory is read, if it exists. The XML file can also be in gzip’ed<br />

form with the extension .xml.gz.<br />

1.5 Linear Variational Problem and Solver Objects<br />

The solve(a == L, u, bc) call is just a compact syntax alternative to a<br />

slightly more comprehensive specification of the variational equation and the<br />

solution of the associated linear system. This alternative syntax is used in a lot<br />

of <strong>FEniCS</strong> applications and will also be used later in this tutorial, so we show<br />

it already now:<br />

u = Function(V)<br />

problem = LinearVariationalProblem(a, L, u, bc)<br />

solver = LinearVariationalSolver(problem)<br />

solver.solve()<br />

Many objects have an attribute parameters corresponding to a parameter<br />

set in the global parameters database, but local to the object. Here,<br />

solver.parameters play that role. Setting the CG method with ILU preconditiong<br />

as solution method and specifying solver-specific parameters can be<br />

done like this:<br />

solver.parameters[’linear_solver’] = ’cg’<br />

solver.parameters[’preconditioner’] = ’ilu’<br />

cg_prm = solver.parameters[’krylov_solver’] # short form<br />

cg_prm[’absolute_tolerance’] = 1E-7<br />

cg_prm[’relative_tolerance’] = 1E-4<br />

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

Calling info(solver.parameters, True) lists all the available parameter sets<br />

with default values for each parameter. Settings in the global parameters<br />

database are propagated to parameter sets in individual objects, with the possibility<br />

of being overwritten as done above.<br />

The d3_p2D.py program modifies the d2_p2D.py file to incorporate objects<br />

for the variational problem and solver.<br />

1.6 Examining the Discrete Solution<br />

Weknowthat, intheparticularboundary-valueproblemofSection1.3, thecomputed<br />

solution u should equal the exact solution at the vertices of the cells. An<br />

17

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

Saved successfully!

Ooh no, something went wrong!