AMDiS  0.3
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 DofMap>
10  auto residuum(PetscMatrix<DofMap> const& A, PetscVector<DofMap> const& x, PetscVector<DofMap> 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  return res;
20  }
21 
22  // ||b - A*x|| / ||b||
23  template <class DofMap>
24  auto relResiduum(PetscMatrix<DofMap> const& A, PetscVector<DofMap> const& x, PetscVector<DofMap> const& b)
25  {
26  PetscReal bNrm;
27  VecNorm(b.vector(), NORM_2, &bNrm);
28  return residuum(A,x,b) / bNrm;
29  }
30 
31 } // end namespace AMDiS
Definition: AdaptBase.hpp:6