From ce62bfe7733dc3a618570b6af23071337ac591da Mon Sep 17 00:00:00 2001
From: Manuel Weberndorfer <manuel.weberndorfer@id.ethz.ch>
Date: Tue, 31 Aug 2021 08:56:49 +0000
Subject: [PATCH] use real_type to return norm

- norm is real even if entries are complex
---
 cpppetsc/src/include/ae108/cpppetsc/Matrix.h | 7 ++++---
 cpppetsc/src/include/ae108/cpppetsc/Vector.h | 7 ++++---
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/cpppetsc/src/include/ae108/cpppetsc/Matrix.h b/cpppetsc/src/include/ae108/cpppetsc/Matrix.h
index 0cf28573..911506d0 100644
--- a/cpppetsc/src/include/ae108/cpppetsc/Matrix.h
+++ b/cpppetsc/src/include/ae108/cpppetsc/Matrix.h
@@ -40,6 +40,7 @@ template <class Policy> class Matrix {
 public:
   using size_type = PetscInt;
   using value_type = PetscScalar;
+  using real_type = PetscReal;
 
   /**
    * @brief Allocates a matrix with global_rows rows and global_columns columns.
@@ -148,7 +149,7 @@ public:
   /**
    * @brief Computes the Frobenius norm of the matrix.
    */
-  value_type norm() const;
+  real_type norm() const;
 
   /**
    * @brief Print the matrix to world stdout.
@@ -515,8 +516,8 @@ Matrix<Policy>::localRowRange() const {
 }
 
 template <class Policy>
-typename Matrix<Policy>::value_type Matrix<Policy>::norm() const {
-  auto result = value_type{};
+typename Matrix<Policy>::real_type Matrix<Policy>::norm() const {
+  auto result = real_type{};
   Policy::handleError(MatNorm(_mat.get(), NORM_FROBENIUS, &result));
   return result;
 }
diff --git a/cpppetsc/src/include/ae108/cpppetsc/Vector.h b/cpppetsc/src/include/ae108/cpppetsc/Vector.h
index c10262c1..d5c68684 100644
--- a/cpppetsc/src/include/ae108/cpppetsc/Vector.h
+++ b/cpppetsc/src/include/ae108/cpppetsc/Vector.h
@@ -43,6 +43,7 @@ template <class Policy> class Vector {
 public:
   using size_type = PetscInt;
   using value_type = PetscScalar;
+  using real_type = PetscReal;
   using matrix_type = Matrix<Policy>;
 
   /**
@@ -148,7 +149,7 @@ public:
   /**
    * @brief Computes the 2-norm of the vector.
    */
-  value_type norm() const;
+  real_type norm() const;
 
   /**
    * @brief Print the vector to world stdout.
@@ -402,8 +403,8 @@ Vector<Policy>::fromList(const std::initializer_list<value_type> list) {
 }
 
 template <class Policy>
-typename Vector<Policy>::value_type Vector<Policy>::norm() const {
-  auto result = value_type{};
+typename Vector<Policy>::real_type Vector<Policy>::norm() const {
+  auto result = real_type{};
   Policy::handleError(VecNorm(_vec.get(), NORM_2, &result));
   return result;
 }
-- 
GitLab