KASKADE 7 development version
Loading...
Searching...
No Matches
matrixTraits.hh
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2/* */
3/* This file is part of the library KASKADE 7 */
4/* https://www.zib.de/research/projects/kaskade7-finite-element-toolbox */
5/* */
6/* Copyright (C) 2015-2016 Zuse Institute Berlin */
7/* */
8/* KASKADE 7 is distributed under the terms of the ZIB Academic License. */
9/* see $KASKADE/academic.txt */
10/* */
11/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
12
13#ifndef LINALG_MATRIX_TRAITS
14#define LINALG_MATRIX_TRAITS
15
16// forward declarations
17namespace Dune
18{
19 template <class Scalar, int n, int m> class FieldMatrix;
20 template <class Scalar, int n> class FieldVector;
21 template <class Entry, class Allocator> class BlockVector;
22}
23
27
28namespace Kaskade
29{
30 // forward declaration
31 template <class Entry, class Index> class NumaBCRSMatrix;
32
33 // --------------------------------------------------------------------------------------
34
39 template <class Matrix>
41 {
50 using NaturalDomain = void;
51
58 using NaturalRange = void;
59
63 static bool isSquare(Matrix const& A);
64 };
65
66 template <class Scalar, int n, int m>
67 struct MatrixTraits<Dune::FieldMatrix<Scalar,n,m>>
68 {
71
72 constexpr static bool isSquare(Dune::FieldMatrix<Scalar,n,m> const&)
73 {
74 return n==m; // has to have the same number of rows and columns
75 }
76 };
77
78 template <class Entry, class Index>
79 struct MatrixTraits<NumaBCRSMatrix<Entry,Index>>
80 {
83
85 {
86 int n = A.N();
87
88 if (A.M() != n) // matrix needs to have the same number
89 return false; // of rows and columns - otherwise it's not square
90
91 for (int i=0; i<n; ++i) // and every diagonal entry needs to be square
92 if ( ! MatrixTraits<Entry>::isSquare(A[i][i]) ) // otherwise it's not square
93 return false;
94
95 return true; // everything's ok - we're square
96 }
97 };
98}
99
100#endif
A NUMA-aware compressed row storage matrix adhering mostly to the Dune ISTL interface (to complete....
Index M() const
The number of columns.
Index N() const
The number of rows.
static constexpr bool isSquare(Dune::FieldMatrix< Scalar, n, m > const &)
static bool isSquare(NumaBCRSMatrix< Entry, Index > const &A)
Dune::BlockVector< typename MatrixTraits< Entry >::NaturalRange > NaturalRange
Dune::BlockVector< typename MatrixTraits< Entry >::NaturalDomain > NaturalDomain
Defines domain and range types for matrix classes.
void NaturalDomain
The natural domain type.
static bool isSquare(Matrix const &A)
Checks whether a matrix is square.
void NaturalRange
The natural range type.