Skip to content
Snippets Groups Projects
Commit 30f20227 authored by Christoph Lehmann's avatar Christoph Lehmann
Browse files

[BL] added Euclidean norm

parent 3984c7a2
No related branches found
No related tags found
No related merge requests found
......@@ -10,6 +10,27 @@
#include "BLAS.h"
// Dense Eigen matrices and vectors ////////////////////////////////////////
#ifdef OGS_USE_EIGEN
#include <Eigen/Core>
namespace MathLib { namespace BLAS
{
// Explicit specialization
// Computes the Euclidean norm of x
template<>
double norm2(Eigen::VectorXd const& x)
{
return x.norm();
}
} } // namespaces
#endif
// Global PETScMatrix/PETScVector //////////////////////////////////////////
#ifdef USE_PETSC
......@@ -52,6 +73,14 @@ void axpby(PETScVector& y, double const a, double const b, PETScVector const& x)
VecAXPBY(y.getRawVector(), a, b, x.getRawVector());
}
// Explicit specialization
// Computes the Euclidean norm of x
template<>
double norm2(PETScVector const& x)
{
return x.getNorm(MathLib::VecNormType::NORM2);
}
// Matrix
......@@ -150,6 +179,14 @@ void axpby(EigenVector& y, double const a, double const b, EigenVector const& x)
y.getRawVector() = a*x.getRawVector() + b*y.getRawVector();
}
// Explicit specialization
// Euclidean norm
template<>
double norm2(EigenVector const& x)
{
return x.getRawVector().norm();
}
// Matrix
......
......@@ -66,6 +66,10 @@ void axpby(MatrixOrVector& y, double const a, double const b, MatrixOrVector con
y = a*x + b*y;
}
//! Computes the Euclidean norm of \c x.
template<typename MatrixOrVector>
double norm2(MatrixOrVector const& x);
// Matrix and Vector
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment