From d65d94d75ba65316a72587e122f53e003d7ca241 Mon Sep 17 00:00:00 2001
From: wolf
Date: Fri, 16 Jun 2006 14:55:43 +0000
Subject: [PATCH] Add FullMatrix::trace
git-svn-id: https://svn.dealii.org/trunk@13268 0785d39b-7218-0410-832d-ea1e28bc413d
---
deal.II/doc/news/changes.html | 17 +++++--
deal.II/lac/include/lac/full_matrix.h | 10 ++++
.../lac/include/lac/full_matrix.templates.h | 19 +++++++
tests/lac/Makefile | 2 +-
tests/lac/trace.cc | 49 +++++++++++++++++++
tests/lac/trace/.cvsignore | 1 +
tests/lac/trace/cmp/generic | 2 +
7 files changed, 94 insertions(+), 6 deletions(-)
create mode 100644 tests/lac/trace.cc
create mode 100644 tests/lac/trace/.cvsignore
create mode 100644 tests/lac/trace/cmp/generic
diff --git a/deal.II/doc/news/changes.html b/deal.II/doc/news/changes.html
index e34397eaf9..97045cf775 100644
--- a/deal.II/doc/news/changes.html
+++ b/deal.II/doc/news/changes.html
@@ -520,12 +520,19 @@ inconvenience this causes.
+ -
New: There is now a function FullMatrix::trace
that does what its name suggests
+ it does.
+
+ (WB 2006/06/16)
+
+
-
Improved: PointerMatrixAux
now has a
- default constructor and a function for setting the VectorMemory
object.
-
- (GK 2006/06/14)
-
+ default constructor and a function for setting the VectorMemory
object.
+
+ (GK 2006/06/14)
+
Fixed: FullMatrix::print
would yield a link error
diff --git a/deal.II/lac/include/lac/full_matrix.h b/deal.II/lac/include/lac/full_matrix.h
index 9aeddd4905..165366640d 100644
--- a/deal.II/lac/include/lac/full_matrix.h
+++ b/deal.II/lac/include/lac/full_matrix.h
@@ -510,6 +510,16 @@ class FullMatrix : public Table<2,number>
*/
double determinant () const;
+ /**
+ * Return the trace of the matrix,
+ * i.e. the sum of the diagonal values
+ * (which happens to also equal the sum
+ * of the eigenvalues of a matrix).
+ * Obviously, the matrix needs to
+ * be quadratic for this function.
+ */
+ double trace () const;
+
/**
* Output of the matrix in
* user-defined format.
diff --git a/deal.II/lac/include/lac/full_matrix.templates.h b/deal.II/lac/include/lac/full_matrix.templates.h
index bb21adf9f5..89401b9064 100644
--- a/deal.II/lac/include/lac/full_matrix.templates.h
+++ b/deal.II/lac/include/lac/full_matrix.templates.h
@@ -1920,6 +1920,25 @@ FullMatrix::determinant () const
}
+
+template
+double
+FullMatrix::trace () const
+{
+ Assert (!this->empty(), ExcEmptyMatrix());
+
+ Assert (this->n_cols() == this->n_rows(),
+ ExcDimensionMismatch(this->n_cols(), this->n_rows()));
+
+ double tr = 0;
+ for (unsigned int i=0; in_rows(); ++i)
+ tr += this->el(i,i);
+
+ return tr;
+}
+
+
+
template
number
FullMatrix::frobenius_norm () const
diff --git a/tests/lac/Makefile b/tests/lac/Makefile
index 6018121e63..8365ca85b1 100644
--- a/tests/lac/Makefile
+++ b/tests/lac/Makefile
@@ -28,7 +28,7 @@ tests_x = vector-vector \
matrix_lib matrix_out \
solver eigen \
sparse_ilu sparse_ilu_t lapack lapack_fill block_minres \
- identity_matrix*
+ identity_matrix* trace
# from above list of regular expressions, generate the real set of
diff --git a/tests/lac/trace.cc b/tests/lac/trace.cc
new file mode 100644
index 0000000000..adf2e5126e
--- /dev/null
+++ b/tests/lac/trace.cc
@@ -0,0 +1,49 @@
+//---------------------------------------------------------------------------
+// $Id$
+// Version: $Name$
+//
+// Copyright (C) 2005, 2006 by the deal.II authors
+//
+// This file is subject to QPL and may not be distributed
+// without copyright and license information. Please refer
+// to the file deal.II/doc/license.html for the text and
+// further information on this license.
+//
+//---------------------------------------------------------------------------
+
+// check FullMatrix::trace
+
+
+#include "../tests.h"
+#include
+#include
+
+#include
+#include
+#include
+
+
+int main()
+{
+ std::ofstream logfile("trace/output");
+ logfile.setf(std::ios::fixed);
+ logfile.precision(0);
+ deallog.attach(logfile);
+ deallog.depth_console(0);
+ deallog.threshold_double(1.e-10);
+
+ const unsigned int N=20;
+ FullMatrix m (N,N);
+
+ double tr = 0;
+ for (unsigned int i=0; i