AMDiS 2.10
The Adaptive Multi-Dimensional Simulation Toolbox
Operations.hpp
1#pragma once
2
3#include <boost/numeric/mtl/operation/two_norm.hpp>
4
5#include <amdis/linearalgebra/mtl/MatrixBackend.hpp>
6#include <amdis/linearalgebra/mtl/VectorBackend.hpp>
7
8namespace AMDiS {
9
10 // ||b - A*x||
11 template <class T1, class T2, class T3>
12 auto residuum(MTLSparseMatrix<T1> const& A, MTLVector<T2> const& x, MTLVector<T3> const& b)
13 {
14 auto r = b.vector();
15 r -= A.matrix() * x.vector();
16 return two_norm(r);
17 }
18
19 // ||b - A*x|| / ||b||
20 template <class T1, class T2, class T3>
21 auto relResiduum(MTLSparseMatrix<T1> const& A, MTLVector<T2> const& x, MTLVector<T3> const& b)
22 {
23 return residuum(A,x,b) / two_norm(b.vector());
24 }
25
26} // end namespace AMDiS