03.12.2012 Views

C++ for Scientists - Technische Universität Dresden

C++ for Scientists - Technische Universität Dresden

C++ for Scientists - Technische Universität Dresden

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.

14.1. COMPUTING AN EIGENFUNCTION OF THE POISSON EQUATION 265<br />

} // namespace athens<br />

#endif<br />

where we assume that the types X and Y are models of the concept glas::DenseVectorCollection.<br />

14.1.2 Richardson iteration<br />

Richardson iteration is an iterative method <strong>for</strong> the solution of the linear system<br />

Bu = g<br />

that starts from an initial guess u0 and computes ui = ui−1 + ri−1 at iteration i, where ri−1 is<br />

the residual g − Bui−1. It works as follows: The method converges when the eigenvalues of B<br />

1<br />

2<br />

3<br />

4<br />

5<br />

1. For i = 1, . . . , max it:<br />

1.1. Compute residual ri−1 = g − Bui−1<br />

1.2. If �ri−1�2 ≤ τ: return<br />

1.3. Compute new solution ui = ui−1 + ri−1<br />

lie between 0 and 2.<br />

The eigenvalues of the Poisson matrix A are λj = 2(1 − cos(πj/(n + 1))) <strong>for</strong> j = 1, . . . , n. The<br />

eigenvalues are thus bounded by 0 < λj < 4. We there<strong>for</strong>e first multiply Au = f by 0.5 into<br />

(0.5A)u = (0.5f)<br />

Note that the solution u does not change. Define B = 0.5A and g = 0.5f, then Bu = g and the<br />

eigenvalues of B lie in (0, 2). For such matrix, we can use the Richardson iteration method.<br />

We develop the following function<br />

template <br />

double richardson( Op const& op, G const& g, U& u, double const& tol, int max it ) ;<br />

where op is a BinaryFunction op(x,y) that computes y = Bx <strong>for</strong> a given input argument x, and<br />

where u is an initial estimate of the solution on input and the computed solution on output.<br />

The vector g is the right-hand side of the system. The return value of richardson is the residual<br />

norm. This allows us to check how accurate the solution is without having to compute the<br />

residual explicitly. The parameter tol corresponds to the tolerance τ.<br />

First, we set conceptual conditions on all arguments.<br />

• U is a model of concept glas::DenseVectorCollection, i.e. we assume that a dense vector<br />

from GLAS is used.<br />

• Op is a model of BinaryFunction, i.e. the following are valid expressions <strong>for</strong> op of type Op:<br />

– op(x,y) where x and y are instances of type X where X is a model of the concept<br />

glas::DenseVectorCollection.

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

Saved successfully!

Ooh no, something went wrong!