From bcea7b01192fec3056491c2091c2281b504d8471 Mon Sep 17 00:00:00 2001 From: Max Kahnt <max.kahnt@fu-berlin.de> Date: Thu, 5 Oct 2017 15:12:43 +0200 Subject: [PATCH] Add helper to obtain matrix with fieldmatrix type leaves. --- dune/matrix-vector/CMakeLists.txt | 1 + dune/matrix-vector/asfieldmatrix.hh | 53 +++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 dune/matrix-vector/asfieldmatrix.hh diff --git a/dune/matrix-vector/CMakeLists.txt b/dune/matrix-vector/CMakeLists.txt index d25563c..cbfd6a5 100644 --- a/dune/matrix-vector/CMakeLists.txt +++ b/dune/matrix-vector/CMakeLists.txt @@ -6,6 +6,7 @@ add_subdirectory(types) install(FILES addtodiagonal.hh algorithm.hh + asfieldmatrix.hh axpy.hh axy.hh blockmatrixview.hh diff --git a/dune/matrix-vector/asfieldmatrix.hh b/dune/matrix-vector/asfieldmatrix.hh new file mode 100644 index 0000000..af4ba6a --- /dev/null +++ b/dune/matrix-vector/asfieldmatrix.hh @@ -0,0 +1,53 @@ +#ifndef DUNE_MATRIX_VECTOR_ASFIELDMATRIX_HH +#define DUNE_MATRIX_VECTOR_ASFIELDMATRIX_HH + +#include <dune/common/fmatrix.hh> +#include <dune/common/diagonalmatrix.hh> +#include <dune/istl/scaledidmatrix.hh> +#include <dune/istl/bcrsmatrix.hh> +#include <dune/istl/multitypeblockmatrix.hh> +#include <dune/matrix-vector/types/multitypematrix.hh> + +namespace Dune { +namespace MatrixVector { + +template <class> +struct AsFieldMatrix; + +template <class M> +using AsFieldMatrix_t = typename AsFieldMatrix<M>::type; + +template <class K, int n, int m> +struct AsFieldMatrix<FieldMatrix<K, n, m>> { + using type = FieldMatrix<K, n, m>; +}; + +template <class K, int n> +struct AsFieldMatrix<DiagonalMatrix<K, n>> { + using type = FieldMatrix<K, n, n>; +}; + +template <class K, int n> +struct AsFieldMatrix<ScaledIdentityMatrix<K, n>> { + using type = FieldMatrix<K, n, n>; +}; + +template <class BlockMatrix> +struct AsFieldMatrix<BCRSMatrix<BlockMatrix>> { + using type = BCRSMatrix<AsFieldMatrix_t<BlockMatrix>>; +}; + +template <class... Args> +struct AsFieldMatrix<MultiTypeBlockMatrix<Args...>> { + using type = MultiTypeBlockMatrix<AsFieldMatrix_t<Args>...>; +}; + +template <class... Args> +struct AsFieldMatrix<MultiTypeMatrix<Args...>> { + using type = MultiTypeMatrix<AsFieldMatrix_t<Args>...>; +}; + +} // end namespace MatrixVector +} // end namespace Dune + +#endif // DUNE_MATRIX_VECTOR_ASFIELDMATRIX_HH -- GitLab