From 157c684f39c176f1e958834f955bfeac826569a3 Mon Sep 17 00:00:00 2001 From: Christoph Gersbacher <gersbach@dune-project.org> Date: Wed, 6 Feb 2013 15:18:03 +0000 Subject: [PATCH] Interface check for DiagonalMatrix + minor fixes. [[Imported from SVN: r7103]] --- dune/common/diagonalmatrix.hh | 10 ++++++- dune/common/test/diagonalmatrixtest.cc | 41 ++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/dune/common/diagonalmatrix.hh b/dune/common/diagonalmatrix.hh index 128a0e391..d8ac3a799 100644 --- a/dune/common/diagonalmatrix.hh +++ b/dune/common/diagonalmatrix.hh @@ -50,7 +50,8 @@ namespace Dune { //===== type definitions and constants //! export the type representing the field - typedef K field_type; + typedef K value_type; + typedef value_type field_type; //! export the type representing the components typedef K block_type; @@ -67,8 +68,10 @@ namespace Dune { //! Each row is implemented by a field vector typedef DiagonalRowVector<K,n> row_type; typedef row_type reference; + typedef row_type row_reference; typedef DiagonalRowVectorConst<K,n> const_row_type; typedef const_row_type const_reference; + typedef const_row_type const_row_reference; //! export size enum { @@ -78,7 +81,12 @@ namespace Dune { cols = n }; + //==== size + size_type size () const + { + return rows; + } //===== constructors diff --git a/dune/common/test/diagonalmatrixtest.cc b/dune/common/test/diagonalmatrixtest.cc index 21157f989..4383e5350 100644 --- a/dune/common/test/diagonalmatrixtest.cc +++ b/dune/common/test/diagonalmatrixtest.cc @@ -10,9 +10,36 @@ #include <dune/common/fvector.hh> #include <dune/common/exceptions.hh> +#include "checkmatrixinterface.hh" + using namespace Dune; +namespace CheckMatrixInterface +{ + + namespace Capabilities + { + template< class K, int n > + struct hasStaticSizes< Dune::DiagonalMatrix<K,n> > + { + static const bool v = true; + static const int rows = n; + static const int cols = n; + }; + + template< class K, int n > + struct isRegular< Dune::DiagonalMatrix<K,n> > + { + static const bool v = true; + }; + + } // namespace Capabilities + +} // namespace CheckMatrixInterface + + + template<class K, int n> void test_matrix() { @@ -50,12 +77,26 @@ void test_matrix() DUNE_UNUSED FieldMatrix<K,n,n> AFM = FieldMatrix<K,n,n>(A); } +template<class K, int n> +void test_interface() +{ + typedef CheckMatrixInterface::UseFieldVector<K,n,n> Traits; + typedef Dune::DiagonalMatrix<K,n> DiagonalMatrix; + + const DiagonalMatrix A(1); + checkMatrixInterface< DiagonalMatrix >( A ); + checkMatrixInterface< DiagonalMatrix, Traits >( A ); +} + int main() { try { test_matrix<float, 1>(); + test_interface<float, 1>(); test_matrix<double, 1>(); + test_interface<double, 1>(); test_matrix<double, 5>(); + test_interface<double, 5>(); } catch (Dune::Exception & e) { -- GitLab