From 9ef73c5ea681c897ab9d67bf79aac97b2786c1bf Mon Sep 17 00:00:00 2001 From: Elias Pipping <elias.pipping@fu-berlin.de> Date: Mon, 25 Jul 2016 14:57:34 +0200 Subject: [PATCH] Incorporate Promote from Arithmetic/StaticMatrix --- dune/matrix-vector/CMakeLists.txt | 1 + dune/matrix-vector/promote.hh | 50 +++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 dune/matrix-vector/promote.hh diff --git a/dune/matrix-vector/CMakeLists.txt b/dune/matrix-vector/CMakeLists.txt index f654ddf..c3d9227 100644 --- a/dune/matrix-vector/CMakeLists.txt +++ b/dune/matrix-vector/CMakeLists.txt @@ -8,6 +8,7 @@ install(FILES genericvectortools.hh ldlt.hh matrixtraits.hh + promote.hh scalartraits.hh singlenonzerocolumnmatrix.hh singlenonzerorowmatrix.hh diff --git a/dune/matrix-vector/promote.hh b/dune/matrix-vector/promote.hh new file mode 100644 index 0000000..980384d --- /dev/null +++ b/dune/matrix-vector/promote.hh @@ -0,0 +1,50 @@ +#ifndef DUNE_MATRIX_VECTOR_PROMOTE_HH +#define DUNE_MATRIX_VECTOR_PROMOTE_HH + +#include <dune/common/diagonalmatrix.hh> +#include <dune/common/fmatrix.hh> +#include <dune/istl/scaledidmatrix.hh> + +namespace Dune { +namespace MatrixVector { + // type promotion (smallest matrix that can hold the sum of two matrices + // ******************* + template <class MatrixA, class MatrixB> + struct Promote { + typedef Dune::FieldMatrix<typename MatrixA::field_type, MatrixA::rows, + MatrixA::cols> + Type; + }; + + template <class Matrix> + struct Promote<Matrix, Matrix> { + typedef Matrix Type; + }; + + template <typename FieldType, int n> + struct Promote<Dune::FieldMatrix<FieldType, n, n>, + Dune::DiagonalMatrix<FieldType, n>> { + typedef Dune::FieldMatrix<FieldType, n, n> Type; + }; + + template <typename FieldType, int n> + struct Promote<Dune::DiagonalMatrix<FieldType, n>, + Dune::FieldMatrix<FieldType, n, n>> { + typedef Dune::FieldMatrix<FieldType, n, n> Type; + }; + + template <typename FieldType, int n> + struct Promote<Dune::DiagonalMatrix<FieldType, n>, + Dune::ScaledIdentityMatrix<FieldType, n>> { + typedef Dune::DiagonalMatrix<FieldType, n> Type; + }; + + template <typename FieldType, int n> + struct Promote<Dune::ScaledIdentityMatrix<FieldType, n>, + Dune::DiagonalMatrix<FieldType, n>> { + typedef Dune::DiagonalMatrix<FieldType, n> Type; + }; +} +} + +#endif -- GitLab