Class documentation of Concepts

Loading...
Searching...
No Matches
tmatrix.hh
Go to the documentation of this file.
1
9#ifndef tmatrix_hh
10#define tmatrix_hh
11
12#include <iostream>
13#include <map>
14#include "toolbox/array.hh"
15#include "toolbox/set.hh"
17#include "basics/typedefs.hh"
18
19#if __cplusplus >= 201103L
20#include <vector>
21#endif
22
23namespace concepts {
24
25 // forward declaration
26 template<class F>
27 class ElementMatrix;
28
29 template<class F>
30 class Vector;
31
32// template<class F>
33// class SparseMatrix;
34
35 template<class F, int dim>
36 class TColumnBlock;
37
38 // *************************************************************** TColumn **
39
46 template<class F>
47 class TColumn : public virtual OutputOperator {
48 public:
49 // FIXME: of what use is a TColumn which has no entries, and can never get entries?
51 TColumn() : val_(0), lnk_(0), n_(0), idx_(0) {}
57 TColumn(uint n, uint idx, TColumn<F>* lnk = 0, F def = 0);
63 virtual ~TColumn();
64
66 F operator[](uint i) const { return val_[i]; }
68 F& operator[](uint i) { return val_[i]; }
69
71 const F* values() const { return (const F*)val_; }
73 F* values() { return (F*)val_; }
74
76 uint index() const { return idx_; }
77
79 TColumn<F>* link() const { return lnk_; }
80
83
85 void clear();
86
88 uint n() const { return n_; }
89
91 virtual TColumn<F>* clone() const;
92 protected:
93 virtual ::std::ostream& info(::std::ostream& os) const;
98 private:
100 TColumn<F>* lnk_;
101
103 uint n_;
104
106 uint idx_;
107 };
108
110 template<class F>
111 ::std::ostream& operator<<(::std::ostream& os, TColumn<F>* T) {
112 if (T != 0) {
113 os << *T;
114 if (T->link()) os << ", " << T->link();
115 } else os << "TColumn(0)";
116 return os;
117 }
118
119 // ********************************************************* TColumnTensor **
120
133 template<class F, int dim>
134 class TColumnTensor : public TColumn<F> {
135 public:
142 TColumnTensor(const uint* n, const uint idx, TColumn<F>* lnk = 0);
152
154 F operator[](uint* i) const {
155#ifdef DEBUG
156 for (uint j = 0; j < dim; ++j)
157 conceptsAssert3(i[j] < n_[j], Assertion(), "j = " << j << ", i[j] = "
158 << i[j] << ", n_[j] = " << n_[j]);
159#endif
161 dim == 2 ? i[0]+i[1]*n_[0]
162 : i[0]+i[1]*n_[0]+i[2]*n_[0]*n_[1]);
163 }
166#ifdef DEBUG
167 for (uint j = 0; j < dim; ++j)
168 conceptsAssert3(i[j] < n_[j], Assertion(), "j = " << j << ", i[j] = "
169 << i[j] << ", n_[j] = " << n_[j]);
170#endif
171 return TColumn<F>::operator[](dim == 2 ? i[0]+i[1]*n_[0] :
172 i[0]+i[1]*n_[0]+i[2]*n_[0]*n_[1]); }
173
175 const uint* n() const { return n_; }
176
177 virtual TColumnTensor<F, dim>* clone() const;
178 protected:
179 virtual ::std::ostream& info(::std::ostream& os) const;
180 private:
182 uint n_[dim];
183 void recursiveOut_(const int d, uint* n, ::std::ostream& os) const;
184 };
185
186 // ********************************************************** TColumnBlock **
187
215 template<class F, int dim>
216 class TColumnBlock : public TColumn<F> {
217 public:
226 TColumnBlock(const uint* n, const uint idx,
227 TColumn<F>* lnk = 0);
235
239 F operator[](uint* i) const {
240 return TColumn<F>::operator[](ldof(i));
241 }
242
245 return TColumn<F>::operator[](ldof(i));
246 }
247
252
256 uint ldof(uint* i) const;
257
259 inline const uint* n() const { return n_;}
261 inline const uint n(uint i) const { return n_[i]; }
262
263 virtual TColumnBlock<F, dim>* clone() const;
264 protected:
265 virtual ::std::ostream& info(::std::ostream& os) const;
266 private:
268 uint n_[dim*dim];
270 void recursiveOut_(const int d, uint* n, ushort& position, ::std::ostream& os) const;
271 };
272
273 // *********************************************************** TColumnsSet **
274
291 template<class F, int dim>
292 class TColumnSet : public virtual OutputOperator {
293 public:
294 // Destructor
295 ~TColumnSet();
297 bool operator()(uint key);
304 TColumn<F>* T(uint key) const;
307 void p(uint key, ushort p[dim]);
310 void p(uint key, ushort p);
312 Array<ushort> p(uint key) const;
314 void clear();
315 protected:
316 virtual ::std::ostream& info(::std::ostream& os) const;
317 private:
319 ::std::map<uint, TColumn<F>*> T_;
321 ::std::map<uint, Array<ushort> > p_;
322 };
323
324 // *********************************************************** TMatrixBase **
325
348 template<class F>
349 class TMatrixBase : public virtual OutputOperator {
350 public:
360 TMatrixBase(const uint m, const uint n);
361 virtual ~TMatrixBase();
362
378 virtual void operator()(const ElementMatrix<F>& A,
379 ElementMatrix<F>& B) const = 0;
380 virtual void operator()(const ElementMatrix<::std::complex<F> >& A,
381 ElementMatrix<::std::complex<F> >& B) const = 0;
382
385 virtual uint index(const uint i) const = 0;
386
388 inline uint m() const { return m_; }
389
390 inline void setM(uint m) { m_ = m; }
391
393 inline uint n() const { return n_; }
394
400 virtual void usedIdx(TColumn<bool>& c) const = 0;
401
410 virtual void extract(const concepts::Vector<F>& solution,
411 concepts::Array<F>& coeff) const = 0;
412 virtual void extract(const concepts::Vector<::std::complex<F> >& solution,
413 concepts::Array<::std::complex<F> >& coeff) const = 0;
414 protected:
415 virtual ::std::ostream& info(::std::ostream& os) const;
416
421 };
422
423 // **************************************************************** TIndex **
424
427 template<class F>
428 class TIndex : public TMatrixBase<F> {
429 public:
435 TIndex(const uint m, const uint n, uint idx[]);
436
442 TIndex(const uint m, const uint n, const Array<uint>& idx);
443 virtual ~TIndex();
444
456 void operator()(const ElementMatrix<::std::complex<F> >& A,
457 ElementMatrix<::std::complex<F> >& B) const;
458
462 inline uint index(const uint i) const { return idx_[i]; }
463
470 virtual void usedIdx(TColumn<bool>& c) const;
471 virtual void extract(const concepts::Vector<F>& solution,
472 concepts::Array<F>& coeff) const;
473 virtual void extract(const concepts::Vector<::std::complex<F> >& solution,
474 concepts::Array<::std::complex<F> >& coeff) const;
475 protected:
476 virtual ::std::ostream& info(::std::ostream& os) const;
477 private:
478 Array<uint> idx_;
479 };
480
481 // *************************************************************** TMatrix **
482
493 template<class F>
494 class TMatrix : public TMatrixBase<F> {
495 public:
497 struct Control : public virtual OutputOperator {
502 protected:
503 virtual ::std::ostream& info(::std::ostream& os) const;
504 };
505
507 struct Data : public virtual OutputOperator {
512 protected:
513 virtual ::std::ostream& info(::std::ostream& os) const;
514 };
515
521
522#if __cplusplus >= 201103L
535 const ::std::vector<::std::pair<uint,uint>>& ids,
536 const ::std::vector<F>& coeffs = ::std::vector<F>(0) );
537#endif // __cplusplus >= 201103L
538
543 TMatrix(const TMatrix<F>& T, Set<uint>* idx = 0);
544
545 virtual ~TMatrix();
546
548 template<class G>
567 void operator()(const ElementMatrix<::std::complex<F> >& A,
568 ElementMatrix<::std::complex<F> >& B) const;
569// void operator()(const SparseMatrix<F>& A,
570// SparseMatrix<F>& B) const;
571 void operator()(const Vector<F>& A,
572 Vector<F>& B) const;
573 void applyOne(const ElementMatrix<F>& A, ElementMatrix<F>& B) const;
574
587 virtual uint index(const uint i) const { return ctrl_[i].idx; }
588
597
601 const typename TMatrix::Control* control(uint i) const { return &ctrl_[i]; };
602
604 const typename TMatrix::Data* data(uint i) const { return data_+i; };
605
606 // Returns the T-Matrix as linked list of columns
607 TColumn<F>* columns() const;
608
610 uint nEntries() const {
611 return sz_;
612 }
613
614 virtual void usedIdx(TColumn<bool>& c) const;
615 virtual void usedIdx(Set<uint>& c) const;
616 virtual void extract(const concepts::Vector<F>& solution,
617 concepts::Array<F>& coeff) const;
618 virtual void extract(const concepts::Vector<::std::complex<F> >& solution,
619 concepts::Array<::std::complex<F> >& coeff) const;
620// Vector<F> extractToVector(const Vector<F>& solution) const;
621 void extractOne(const concepts::Vector<F>& solution,
622 concepts::Array<F>& coeff) const;
623#if __cplusplus >= 201103L
624 void concatenate(const TMatrix<F>& other);
625#endif // __cplusplus >= 201103L
626
627 ::std::ostream& outputLocalMap(::std::ostream& os) const;
628 protected:
629 virtual ::std::ostream& info(::std::ostream& os) const;
630 private:
634 Array<Control> ctrl_;
635
637 Array<Data> data_;
638
640 uint sz_;
641 };
642
643 template<class F>
644 template<class G>
646 : TMatrixBase<F>(T.n())
647 , ctrl_(T.n())
648 , data_(T.nEntries())
649 , sz_(T.nEntries())
650 {
651 setM( T.m() );
652
653 for(uint i=0; i < this->n(); ++i) {
654 ctrl_[i].idx = T.control(i)->idx;
655 ctrl_[i].sz = T.control(i)->sz;
656 }
657 for(uint i=0; i < sz_; ++i) {
658 data_[i].idx = T.data(i)->idx;
659 data_[i].data = T.data(i)->data;
660 }
661
662 }
663
664
665 // *************************************************************** TMatrixBlock **
666
681 template<class F>
682class TMatrixBlock: public TMatrix<F> {
683public:
688 TMatrixBlock(const TMatrix<F>* T0, F weight0 = 1.0, const TMatrix<F>* T1 = 0, F weight1 = 0.0);
689
690 virtual ~TMatrixBlock(){};
691
692 virtual void usedIdx(TColumn<bool>& c) const{
694 }
695
696 virtual void usedIdx(Set<uint>& c) const{
698 }
699 virtual void extract(const concepts::Vector<F>& solution,
700 concepts::Array<F>& coeff) const{
701 TMatrix<F>::extract(solution,coeff);
702 }
703 virtual void extract(const concepts::Vector<::std::complex<F> >& solution,
704 concepts::Array<::std::complex<F> >& coeff) const{
705 TMatrix<F>::extract(solution, coeff);
706 }
707
711 inline uint offsetrow() const{
712 return offsetrow_;
713 }
714
715protected:
716 virtual ::std::ostream& info(::std::ostream& os) const;
717
718private:
719 //routine append TMatrix information at a offset position of row (as longer TColumns)
720 void insert_(const TMatrix<F>& T,uint offset, uint size, F weight);
721
722 //information about the offset characterising the blocks
723 uint offsetrow_;
724 uint offsetcol_;
725};
726
727
728
729
730} // namespace concepts
731
732#endif // tmatrix_hh
TColumnBlock(const uint *n, const uint idx, TColumn< F > *lnk=0)
F operator[](uint *i) const
Definition tmatrix.hh:239
F & operator[](uint *i)
Returns the /c i th entry in the column. /c i an array of size dim.
Definition tmatrix.hh:244
virtual TColumnBlock< F, dim > * clone() const
Returns a copy of itself.
uint ldof(uint *i) const
const uint n(uint i) const
Returns the range of the multiindex for one direction i.
Definition tmatrix.hh:261
void write(TColumnTensor< F, dim > &t, uint k)
TColumnBlock(const TColumnBlock< F, dim > &t, const uint *n)
Transformation constructor to higher number of rows.
const uint * n() const
Returns the range of the multiindices as an array.
Definition tmatrix.hh:259
TColumnBlock(const TColumnBlock< F, dim > &t)
void p(uint key, ushort p)
void clear()
Deletes all TColumns (with linked list) and clear all entrances.
TColumn< F > * T(uint key) const
Gives a pointer to the TColumns of this entrance (or 0)
Array< ushort > p(uint key) const
Returns the polynomial degrees.
bool operator()(uint key)
True if a entrance exists.
TColumn< F > * appendT(uint key, TColumn< F > *T)
void p(uint key, ushort p[dim])
TColumnTensor(const uint *n, const uint idx, TColumn< F > *lnk=0)
TColumnTensor(const TColumnTensor< F, dim > &t)
TColumnTensor(const TColumnBlock< F, dim > &t, uint k)
Copy constructor, takes /c k .th block in /c t.
F operator[](uint *i) const
Returns the ith entry in the column. i an array of size dim.
Definition tmatrix.hh:154
virtual TColumnTensor< F, dim > * clone() const
Returns a copy of itself.
F & operator[](uint *i)
Returns the ith entry in the column. i an array of size dim.
Definition tmatrix.hh:165
const uint * n() const
Returns the number of rows as an array.
Definition tmatrix.hh:175
TColumnTensor(const TColumnTensor< F, dim > &t, const uint *n)
Transformation constructor to higher number of rows.
TColumn< F > * link() const
Returns the pointer to the next column of the linked list.
Definition tmatrix.hh:79
F * values()
Returns the array of entries.
Definition tmatrix.hh:73
void clear()
Deletes all member of the linked list.
F & operator[](uint i)
Returns the ith entry in the column.
Definition tmatrix.hh:68
TColumn(uint n, uint idx, TColumn< F > *lnk=0, F def=0)
Array< F > val_
The data of the column itself.
Definition tmatrix.hh:97
TColumn(const TColumn< F > &t)
uint n() const
Returns the number of rows.
Definition tmatrix.hh:88
const F * values() const
Returns the array of entries.
Definition tmatrix.hh:71
void append(TColumn< F > *T)
Appends a linked list of TColumns at the end.
F operator[](uint i) const
Returns the ith entry in the column.
Definition tmatrix.hh:66
uint index() const
Returns the index of the column in a matrix.
Definition tmatrix.hh:76
virtual TColumn< F > * clone() const
Returns a copy of itself.
uint successors_() const
number of successors
TIndex(const uint m, const uint n, uint idx[])
virtual void extract(const concepts::Vector< F > &solution, concepts::Array< F > &coeff) const
TIndex(const uint m, const uint n, const Array< uint > &idx)
void operator()(const ElementMatrix< F > &A, ElementMatrix< F > &B) const
uint index(const uint i) const
Definition tmatrix.hh:462
virtual void usedIdx(TColumn< bool > &c) const
TMatrixBase(const uint m, const uint n)
virtual void operator()(const ElementMatrix< F > &A, ElementMatrix< F > &B) const =0
virtual void usedIdx(TColumn< bool > &c) const =0
uint m() const
Returns the number of rows.
Definition tmatrix.hh:388
uint n_
Number of columns.
Definition tmatrix.hh:418
uint n() const
Returns the number of columns.
Definition tmatrix.hh:393
TMatrixBase(const uint n)
virtual void extract(const concepts::Vector< F > &solution, concepts::Array< F > &coeff) const =0
uint m_
Number of rows.
Definition tmatrix.hh:420
virtual uint index(const uint i) const =0
virtual void usedIdx(TColumn< bool > &c) const
Definition tmatrix.hh:692
uint offsetrow() const
Definition tmatrix.hh:711
TMatrixBlock(const TMatrix< F > *T0, F weight0=1.0, const TMatrix< F > *T1=0, F weight1=0.0)
virtual void extract(const concepts::Vector< F > &solution, concepts::Array< F > &coeff) const
Definition tmatrix.hh:699
TMatrix(TColumn< F > *T)
TMatrix(const TMatrix< G > &T)
Definition tmatrix.hh:645
const TMatrix::Control * control(uint i) const
Definition tmatrix.hh:601
virtual uint index(const uint i) const
Definition tmatrix.hh:587
void operator()(const ElementMatrix< F > &A, ElementMatrix< F > &B) const
const TMatrix::Data * data(uint i) const
Returns the ith entry of the data array.
Definition tmatrix.hh:604
uint nEntries() const
Definition tmatrix.hh:610
virtual void extract(const concepts::Vector< F > &solution, concepts::Array< F > &coeff) const
void append(TColumn< F > *T)
virtual void usedIdx(TColumn< bool > &c) const
TMatrix(const TMatrix< F > &T, Set< uint > *idx=0)
#define conceptsAssert3(cond, exc, msg)
Set< F > makeSet(uint n, const F &first,...)
Definition set.hh:320
unsigned short ushort
Abbreviation for unsigned short.
Definition typedefs.hh:51
The column header: column index and length of the column data.
Definition tmatrix.hh:497
uint sz
Column length.
Definition tmatrix.hh:501
uint idx
Column index.
Definition tmatrix.hh:499
The matrix entries: row index and data.
Definition tmatrix.hh:507
uint idx
Row index.
Definition tmatrix.hh:509
F data
Data at this entry.
Definition tmatrix.hh:511