submatrix.hh

Go to the documentation of this file.
1 
6 #ifndef submatrix_hh
7 #define submatrix_hh
8 
9 #include "matrix.hh"
10 #include "matrixMult.hh"
11 #include "subMatrixIterator.hh"
12 #include "CRS.hh"
13 #include "space/spaceSet.hh"
14 #include "basics/outputOperator.hh"
15 
16 #include <type_traits>
17 #include <typeinfo>
18 
19 namespace concepts {
20 
21  // forward declaration
22  template<class F, class G>
23  class SubMatrix;
24 
25  template<class F>
26  class SubMatrixN;
27 
28 
29  // ************************************************************* SubMatrix **
30 
39  template<class F>
40  class SubMatrixN : public Matrix<typename F::type>,
41  public CRSConvertable<typename F::type> {
42  public:
43  typedef typename F::type type;
45  typedef typename Realtype<type>::type r_type;
47  typedef typename Cmplxtype<type>::type c_type;
49  typedef typename std::conditional<std::is_same<typename Realtype<F>::type, F>::value ,
51 
54 
56  SubMatrixN(F& m,
58  const Set<IndexRange>& indicesY);
61 
62  virtual ~SubMatrixN() {}
63 
64  virtual void operator()(const Function<r_type>& fncY,
65  Function<type>& fncX);
66  virtual void operator()(const Function<c_type>& fncY,
67  Function<c_type>& fncX);
68 
69  virtual void transpMult(const Vector<r_type>& fncY,
70  Vector<type>& fncX);
71  virtual void transpMult(const Vector<c_type>& fncY,
72  Vector<c_type>& fncX);
73 
74  template<class H, class I>
75  void multiply(const H& fact, I& dest) const {
76  matrixMultiplyRowSorting(*this, fact, dest);
77  }
78 
80  virtual type operator()(const uint i, const uint j) const;
81  virtual type& operator()(const uint i, const uint j);
82 
84  iterator begin(uint r = 0);
86  const_iterator begin(uint r = 0) const;
89 
95  uint used() const;
96 
98  virtual void convertCRS(type* a, int* asub, int* xa) const;
100  virtual void convertCCS(type* a, int* asub, int* xa) const;
102  virtual void convertIJK(type* , int* , int* ) const;
103 
111  template<class H, class I>
112  void addInto(Matrix<H>& dest, const I fact,
113  const uint rowoffset = 0, const uint coloffset = 0) const;
114 
116  const Set<IndexRange>& indicesX() const { return indicesX_; }
118  const Set<IndexRange>& indicesY() const { return indicesY_; }
119 
121  F& matrix() { return *m_; }
122  const F& matrix() const { return *m_; }
123  protected:
124  virtual std::ostream& info(std::ostream& os) const;
127  private:
129  F* m_;
130  };
131 
132  template<class F>
133  template<class H, class I>
134  void SubMatrixN<F>::addInto(Matrix<H>& dest, const I fact,
135  const uint rowoffset,
136  const uint coloffset) const {
137  for(const_iterator i = begin(); i != end(); ++i)
138  dest(rowoffset + i.row(), coloffset + i.col()) += fact * *i;
139  }
140 
141 } // namespace concepts
142 
143 #endif // submatrix_hh
144 
virtual type operator()(const uint i, const uint j) const
Index operator.
virtual void convertIJK(type *, int *, int *) const
Converts sub matrix to IJK format.
const_iterator begin(uint r=0) const
Constant iterator over the elements, standing at position (0,0)
Cmplxtype< type >::type c_type
Complex type of data type.
Definition: submatrix.hh:47
virtual void convertCRS(type *a, int *asub, int *xa) const
Converts sub matrix to CRS format.
virtual void convertCCS(type *a, int *asub, int *xa) const
Converts sub matrix to CCS format.
const F & matrix() const
Definition: submatrix.hh:122
void multiply(const H &fact, I &dest) const
Definition: submatrix.hh:75
Abstract class for a function.
Definition: basis.hh:21
virtual void operator()(const Function< r_type > &fncY, Function< type > &fncX)
_SubMatrix_iterator< F, const type &, const type * > const_iterator
Definition: submatrix.hh:53
virtual void transpMult(const Vector< c_type > &fncY, Vector< c_type > &fncX)
const Set< IndexRange > indicesX_
Index sets of sub matrix.
Definition: submatrix.hh:126
uint used() const
Number of elements in the sub matrix.
const Set< IndexRange > & indicesX() const
Returns index range for the rows.
Definition: submatrix.hh:116
const Set< IndexRange > indicesY_
Definition: submatrix.hh:126
virtual void operator()(const Function< c_type > &fncY, Function< c_type > &fncX)
virtual type & operator()(const uint i, const uint j)
std::conditional< std::is_same< typename Realtype< F >::type, F >::value, typename Realtype< F >::type, typename Cmplxtype< F >::type >::type d_type
Data type, depending if F is real or complex.
Definition: submatrix.hh:50
Abstract class for an operator, which is a sub matrix of another matrix.
Definition: submatrix.hh:26
Abstract class for an operator.
Definition: compositions.hh:31
Realtype< type >::type r_type
Real type of data type.
Definition: submatrix.hh:45
const Set< IndexRange > & indicesY() const
Returns index range for the columns.
Definition: submatrix.hh:118
Base class for operators which can be converted to Sparse Row Storage (CRS) or Sparse Column Storage ...
Definition: CRS.hh:30
STL like iterator for sub matrices.
virtual std::ostream & info(std::ostream &os) const
SubMatrixN()
Standard constructor.
SubMatrixN(F &m, const Set< IndexRange > &indicesX, const Set< IndexRange > &indicesY)
Constructor.
void addInto(Matrix< H > &dest, const I fact, const uint rowoffset=0, const uint coloffset=0) const
This matrix is added as block into to the given matrix.
Definition: submatrix.hh:134
std::complex< F > type
Definition: typedefs.hh:116
const_iterator end() const
Constant iterator, standing behind last element.
virtual void transpMult(const Vector< r_type > &fncY, Vector< type > &fncX)
virtual ~SubMatrixN()
Definition: submatrix.hh:62
_SubMatrix_iterator< F, type &, type * > iterator
Definition: submatrix.hh:52
void matrixMultiplyRowSorting(const F &factL, const G &factR, Matrix< H > &dest)
Multiplies two matrices, which deliver at least a row sorted iterator, and adds (!...
Definition: matrixMult.hh:28
F & matrix()
Matrix, which the sub matrix is based on.
Definition: submatrix.hh:121
iterator begin(uint r=0)
Iterator over the elements, standing at position (0,0)
Basic namespace for Concepts-2.
Definition: pml_formula.h:16
Page URL: http://wiki.math.ethz.ch/bin/view/Concepts/WebHome
21 August 2020
© 2020 Eidgenössische Technische Hochschule Zürich