DOLFIN User Manual - FEniCS Project

DOLFIN User Manual - FEniCS Project DOLFIN User Manual - FEniCS Project

fenicsproject.org
from fenicsproject.org More from this publisher
12.07.2015 Views

DOLFIN User ManualHoffman, Jansson, Logg, Wellsuint M = 100;uint N = 100;Matrix A(M,N);Similarly, the vector class Vector allows for a simple initialization of a Mvector:Vector b(M);Further, wrappers for some basic linear algebra functionality, such as matrixvector multiplication, norms etc., are provided with an intentionally simpleinterface, for example, matrix vector multiplication is defined by:Vector Ax;A.mult(b,Ax);For more advanced operations, a pointer to the PETSc matrix and vector isaccessed by mat() and vec() respectively.3.2 Matrix-free matricesThe DOLFIN class VirtualMatrix represents a matrix-free matrix of dimensionM × M. The matrix-free matrix is a simple wrapper for a PETScshell matrix. The interface is intentionally simple, and for advanced usagethe PETSc Mat pointer is accessed by the function mat().The class VirtualMatrix enables the use of Krylov subspace methods forlinear systems Ax = b, without having to explicitly store the matrix A. Allthat is needed is that the user-defined VirtualMatrix implements multiplicationwith vectors. Note that the multiplication operator needs to bedefined in terms of PETSc data structures (Vec), since it will be called fromPETSc.26

DOLFIN User ManualHoffman, Jansson, Logg, Wells3.3 Linear solversA general interface to all linear solvers for systems of the form Ax = b isprovided through the class LinearSolver.In particular, wrappers for a direct LU solver and an iterative Krylov GMRESsolver are implemented in the classes LU and GMRES.To solve the linear system Ax = b using GMRES in DOLFIN, simply write:Vec x;GMRES solver;solver.solve(A,x,b);DOLFIN also provides a wrapper for an eigenvalue solver in PETSc. Thefollowing code computes the eigenvalues of the matrix A,Vector er, ec;EigenvalueSolver esolver;esolver.eigen(A,er,ec);The real components of the eigenvalues are returned in the vector er andthe complex components of the eigenvalues are returned in the vector ec.The procedure for computing the eigenvalues of a matrix is computationallyintensive and should only be used for relatively small matrices.3.4 PreconditioningThe Preconditioner class specifies the interface for user-defined Krylovmethod preconditioners. To implement our own preconditioner we only needto supply a function that approximately solves the linear system given aright-hand side.27

<strong>DOLFIN</strong> <strong>User</strong> <strong>Manual</strong>Hoffman, Jansson, Logg, Wells3.3 Linear solversA general interface to all linear solvers for systems of the form Ax = b isprovided through the class LinearSolver.In particular, wrappers for a direct LU solver and an iterative Krylov GMRESsolver are implemented in the classes LU and GMRES.To solve the linear system Ax = b using GMRES in <strong>DOLFIN</strong>, simply write:Vec x;GMRES solver;solver.solve(A,x,b);<strong>DOLFIN</strong> also provides a wrapper for an eigenvalue solver in PETSc. Thefollowing code computes the eigenvalues of the matrix A,Vector er, ec;EigenvalueSolver esolver;esolver.eigen(A,er,ec);The real components of the eigenvalues are returned in the vector er andthe complex components of the eigenvalues are returned in the vector ec.The procedure for computing the eigenvalues of a matrix is computationallyintensive and should only be used for relatively small matrices.3.4 PreconditioningThe Preconditioner class specifies the interface for user-defined Krylovmethod preconditioners. To implement our own preconditioner we only needto supply a function that approximately solves the linear system given aright-hand side.27

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

Saved successfully!

Ooh no, something went wrong!