AMDiS 2.10
The Adaptive Multi-Dimensional Simulation Toolbox
Operations.hpp
1#pragma once
2
3#include <amdis/linearalgebra/istl/MatrixBackend.hpp>
4#include <amdis/linearalgebra/istl/VectorBackend.hpp>
5#include <dune/istl/paamg/pinfo.hh>
6
7namespace AMDiS {
8
9 namespace Impl {
10
11 template <class Vec, class Comm,
12 std::enable_if_t<!std::is_same_v<Comm,Dune::Amg::SequentialInformation>, int> = 0>
13 auto normISTL(Vec const& x, Comm const& comm)
14 {
15 return comm.norm(x);
16 }
17
18 template <class Vec>
19 auto normISTL(Vec const& x, Dune::Amg::SequentialInformation const& comm)
20 {
21 return x.two_norm();
22 }
23
24 } // end namespace Impl
25
26
27 // ||b - A*x||
28 template <class T1, class C1, class T2, class T3>
29 auto residuum(ISTLBCRSMatrix<T1,C1> const& A, ISTLBlockVector<T2> const& x, ISTLBlockVector<T3> const& b)
30 {
31 auto r = b.vector();
32 A.matrix().mmv(x.vector(), r);
33 return Impl::normISTL(r, A.comm().impl());
34 }
35
36 // ||b - A*x|| / ||b||
37 template <class T1, class C1, class T2, class T3>
38 auto relResiduum(ISTLBCRSMatrix<T1,C1> const& A, ISTLBlockVector<T2> const& x, ISTLBlockVector<T3> const& b)
39 {
40 return residuum(A,x,b) / Impl::normISTL(b.vector(), A.comm().impl());
41 }
42
43} // end namespace AMDiS