AMDiS  2.10
The Adaptive Multi-Dimensional Simulation Toolbox
Operations.hpp
1 #pragma once
2 
3 #include <amdis/linearalgebra/petsc/MatrixBackend.hpp>
4 #include <amdis/linearalgebra/petsc/VectorBackend.hpp>
5 
6 namespace AMDiS {
7 
8  // ||b - A*x||
9  template <class Matrix, class RowDofMap, class ColDofMap>
10  auto residuum(Matrix const& A, PetscVector<ColDofMap> const& x, PetscVector<RowDofMap> const& b)
11  {
12  Vec r;
13  VecDuplicate(b.vector(), &r);
14  MatMult(A.matrix(), x.vector(), r);
15  VecAXPY(r, -1.0, b.vector());
16 
17  PetscReal res;
18  VecNorm(r, NORM_2, &res);
19  VecDestroy(&r);
20  return res;
21  }
22 
23  // ||b - A*x|| / ||b||
24  template <class Matrix, class RowDofMap, class ColDofMap>
25  auto relResiduum(Matrix const& A, PetscVector<ColDofMap> const& x, PetscVector<RowDofMap> const& b)
26  {
27  PetscReal bNrm;
28  VecNorm(b.vector(), NORM_2, &bNrm);
29  return residuum(A,x,b) / bNrm;
30  }
31 
32 } // end namespace AMDiS
Definition: AdaptBase.hpp:6