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"
16 #include "basics/outputOperator.hh"
17 #include "basics/typedefs.hh"
18 
19 #if __cplusplus >= 201103L
20 #include <vector>
21 #endif
22 
23 namespace 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);
62  TColumn(const TColumn<F>& t);
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 
82  void append(TColumn<F>* T);
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;
95  uint successors_() const;
98  private:
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);
151  TColumnTensor(const TColumnTensor<F, dim>& t, const uint* n);
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
160  return TColumn<F>::operator[](
161  dim == 2 ? i[0]+i[1]*n_[0]
162  : i[0]+i[1]*n_[0]+i[2]*n_[0]*n_[1]);
163  }
165  F& operator[](uint* i) {
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);
234  TColumnBlock(const TColumnBlock<F, dim>& t, const uint* n);
235 
239  F operator[](uint* i) const {
240  return TColumn<F>::operator[](ldof(i));
241  }
242 
244  F& operator[](uint* i) {
245  return TColumn<F>::operator[](ldof(i));
246  }
247 
251  void write(TColumnTensor<F,dim>& t, uint k);
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
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:
355  TMatrixBase(const uint n);
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 
418  uint n_;
420  uint m_;
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 
455  void operator()(const ElementMatrix<F>& A, ElementMatrix<F>& B) const;
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:
479  };
480 
481  // *************************************************************** TMatrix **
482 
493  template<class F>
494  class TMatrix : public TMatrixBase<F> {
495  public:
497  struct Control : public virtual OutputOperator {
499  uint idx;
501  uint sz;
502  protected:
503  virtual ::std::ostream& info(::std::ostream& os) const;
504  };
505 
507  struct Data : public virtual OutputOperator {
509  uint idx;
511  F data;
512  protected:
513  virtual ::std::ostream& info(::std::ostream& os) const;
514  };
515 
521 
522 #if __cplusplus >= 201103L
523 
534  TMatrix(const uint nShapeFunctions,
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>
549  TMatrix(const TMatrix<G>& T);
566  void operator()(const ElementMatrix<F>& A, ElementMatrix<F>& B) const;
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 
596  void append(TColumn<F>* T);
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:
635 
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>
682 class TMatrixBlock: public TMatrix<F> {
683 public:
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 
715 protected:
716  virtual ::std::ostream& info(::std::ostream& os) const;
717 
718 private:
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
725 };
726 
727 
728 
729 
730 } // namespace concepts
731 
732 #endif // tmatrix_hh
virtual ~TMatrixBlock()
Definition: tmatrix.hh:690
virtual uint index(const uint i) const =0
Maps the local index i to the global index.
A column of a T matrix.
Definition: analytical.hh:18
F operator[](uint *i) const
Returns the ith entry in the column.
Definition: tmatrix.hh:239
The matrix entries: row index and data.
Definition: tmatrix.hh:507
F * values()
Returns the array of entries.
Definition: tmatrix.hh:73
::std::map< uint, TColumn< F > * > T_
List of TColumns.
Definition: tmatrix.hh:319
uint sz_
Size of the stored data.
Definition: tmatrix.hh:640
virtual uint index(const uint i) const
Mapping of the column index to the global degree of freedom.
Definition: tmatrix.hh:587
TColumn< F > * appendT(uint key, TColumn< F > *T)
Appends a TColumn.
F & operator[](uint *i)
Returns the ith entry in the column. i an array of size dim.
Definition: tmatrix.hh:165
void applyOne(const ElementMatrix< F > &A, ElementMatrix< F > &B) const
TColumnBlock(const TColumnBlock< F, dim > &t, const uint *n)
Transformation constructor to higher number of rows.
The column header: column index and length of the column data.
Definition: tmatrix.hh:497
F & operator[](uint i)
Returns the ith entry in the column.
Definition: tmatrix.hh:68
virtual void extract(const concepts::Vector< F > &solution, concepts::Array< F > &coeff) const
void clear()
Deletes all member of the linked list.
void insert_(const TMatrix< F > &T, uint offset, uint size, F weight)
A T matrix in sparse notation.
Definition: edgeTest.hh:17
uint n_[dim]
Number of rows.
Definition: tmatrix.hh:182
TMatrixBlock are special Tmatrices in block diagonal structure, builded with two Tmatrices itsself.
Definition: tmatrix.hh:682
uint idx_
Index of the column in a matrix.
Definition: tmatrix.hh:106
void operator()(const Vector< F > &A, Vector< F > &B) const
TColumnTensor(const uint *n, const uint idx, TColumn< F > *lnk=0)
Constructor.
const TMatrix::Data * data(uint i) const
Returns the ith entry of the data array.
Definition: tmatrix.hh:604
Array< Control > ctrl_
Control data array (column header: column index and length of the column data)
Definition: tmatrix.hh:634
virtual TColumnBlock< F, dim > * clone() const
virtual void operator()(const ElementMatrix< F > &A, ElementMatrix< F > &B) const =0
Application operator.
F data
Data at this entry.
Definition: tmatrix.hh:511
TMatrix(TColumn< F > *T)
Constructor.
virtual ~TMatrix()
virtual void usedIdx(Set< uint > &c) const
Definition: tmatrix.hh:696
F & operator[](uint *i)
Returns the /c i th entry in the column. /c i an array of size dim.
Definition: tmatrix.hh:244
void write(TColumnTensor< F, dim > &t, uint k)
Copies data of T matrix in tensorised structure into block k.
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.
Definition: tmatrix.hh:66
uint index(const uint i) const
Returns the number of the global degree of freedom assigned to the ith local degree of freedom.
Definition: tmatrix.hh:462
Array< ushort > p(uint key) const
Returns the polynomial degrees.
virtual ::std::ostream & info(::std::ostream &os) const
const uint * n() const
Returns the number of rows as an array.
Definition: tmatrix.hh:175
virtual ::std::ostream & info(::std::ostream &os) const
::std::ostream & outputLocalMap(::std::ostream &os) const
virtual void extract(const concepts::Vector<::std::complex< F > > &solution, concepts::Array<::std::complex< F > > &coeff) const
Definition: tmatrix.hh:703
uint ldof(uint *i) const
Returns the number of local dof for ith entry in the column.
virtual ~TIndex()
virtual void operator()(const ElementMatrix<::std::complex< F > > &A, ElementMatrix<::std::complex< F > > &B) const =0
const TMatrix::Control * control(uint i) const
Returns the ith entry of the control data array.
Definition: tmatrix.hh:601
uint idx
Column index.
Definition: tmatrix.hh:499
virtual ::std::ostream & info(::std::ostream &os) const
TMatrixBlock(const TMatrix< F > *T0, F weight0=1.0, const TMatrix< F > *T1=0, F weight1=0.0)
Constructor.
virtual TColumn< F > * clone() const
Returns a copy of itself.
bool operator()(uint key)
True if a entrance exists.
TColumnBlock(const uint *n, const uint idx, TColumn< F > *lnk=0)
Constructor.
virtual TColumnTensor< F, dim > * clone() const
Returns a copy of itself.
uint m() const
Returns the number of rows.
Definition: tmatrix.hh:388
F operator[](uint *i) const
Returns the ith entry in the column. i an array of size dim.
Definition: tmatrix.hh:154
An array of objects.
Definition: bilinearForm.hh:23
Exception class for assertions.
Definition: exceptions.hh:258
virtual ::std::ostream & info(::std::ostream &os) const
uint nEntries() const
number of entries in the data vector
Definition: tmatrix.hh:610
TColumn(const TColumn< F > &t)
Copy constructor.
virtual void usedIdx(TColumn< bool > &c) const =0
Marks the used local indices in c with true, the local indices which are not set to false.
void p(uint key, ushort p[dim])
Sets the polynomial degrees (anisotropic)
Array< uint > idx_
Definition: tmatrix.hh:478
virtual void extract(const concepts::Vector<::std::complex< F > > &solution, concepts::Array<::std::complex< F > > &coeff) const
uint index() const
Returns the index of the column in a matrix.
Definition: tmatrix.hh:76
virtual ~TColumn()
uint successors_() const
number of successors
std::ostream & operator<<(std::ostream &os, const Level< dim > &c)
A column of a T matrix.
Definition: tmatrix.hh:36
void append(TColumn< F > *T)
Appends the columns to the matrix.
virtual ::std::ostream & info(::std::ostream &os) const
uint m_
Number of rows.
Definition: tmatrix.hh:420
void recursiveOut_(const int d, uint *n, ::std::ostream &os) const
virtual ::std::ostream & info(::std::ostream &os) const
virtual void usedIdx(TColumn< bool > &c) const
Definition: tmatrix.hh:692
virtual ::std::ostream & info(::std::ostream &os) const
uint idx
Row index.
Definition: tmatrix.hh:509
virtual void extract(const concepts::Vector< F > &solution, concepts::Array< F > &coeff) const
Definition: tmatrix.hh:699
void recursiveOut_(const int d, uint *n, ushort &position, ::std::ostream &os) const
For output.
void operator()(const ElementMatrix< F > &A, ElementMatrix< F > &B) const
Application operator.
uint n_[dim *dim]
Number of rows.
Definition: tmatrix.hh:268
TMatrixBase(const uint m, const uint n)
Constructor.
void append(TColumn< F > *T)
Appends a linked list of TColumns at the end.
virtual void extract(const concepts::Vector<::std::complex< F > > &solution, concepts::Array<::std::complex< F > > &coeff) const
void p(uint key, ushort p)
Set the polynomial degrees (isotropic)
virtual void usedIdx(TColumn< bool > &c) const
::std::map< uint, Array< ushort > > p_
List of polynomial degreess.
Definition: tmatrix.hh:321
An abstract class for a T matrix.
Definition: element.hh:37
virtual ::std::ostream & info(::std::ostream &os) const
void operator()(const ElementMatrix<::std::complex< F > > &A, ElementMatrix<::std::complex< F > > &B) const
void operator()(const ElementMatrix< F > &A, ElementMatrix< F > &B) const
Application operator.
virtual void usedIdx(Set< uint > &c) const
TIndex(const uint m, const uint n, uint idx[])
Constructor.
A set of TColumns and polynomial degrees, sorted by a key, eg.
Definition: tmatrix.hh:292
const F * values() const
Returns the array of entries.
Definition: tmatrix.hh:71
TColumn< F > * columns() const
virtual void extract(const concepts::Vector<::std::complex< F > > &solution, concepts::Array<::std::complex< F > > &coeff) const =0
Element matrix.
Definition: linearForm.hh:18
unsigned short ushort
Abbreviation for unsigned short.
Definition: typedefs.hh:48
TColumnBlock(const TColumnBlock< F, dim > &t)
Copy constructor The link to the next element in the linear list (lnk_) is not copied!
void extractOne(const concepts::Vector< F > &solution, concepts::Array< F > &coeff) const
virtual void extract(const concepts::Vector< F > &solution, concepts::Array< F > &coeff) const
Extracts the part of solution belonging to this T matrix into coeff.
const uint n(uint i) const
Returns the range of the multiindex for one direction i.
Definition: tmatrix.hh:261
TColumnTensor(const TColumnTensor< F, dim > &t, const uint *n)
Transformation constructor to higher number of rows.
TIndex(const uint m, const uint n, const Array< uint > &idx)
Constructor.
void setM(uint m)
Definition: tmatrix.hh:390
virtual void extract(const concepts::Vector< F > &solution, concepts::Array< F > &coeff) const =0
Extracts the part of solution belonging to this T matrix into coeff.
TColumnTensor(const TColumnTensor< F, dim > &t)
Copy constructor The link to the next element in the linear list (lnk_) is not copied!
void clear()
Deletes all TColumns (with linked list) and clear all entrances.
#define conceptsAssert3(cond, exc, msg)
Assert that a certain condition is fulfilled.
Definition: exceptions.hh:442
A column of a T matrix.
Definition: tmatrix.hh:134
virtual ::std::ostream & info(::std::ostream &os) const
uint n() const
Returns the number of columns.
Definition: tmatrix.hh:393
TColumn< F > * T(uint key) const
Gives a pointer to the TColumns of this entrance (or 0)
TColumn< F > * lnk_
Pointer to the next column in a linked list.
Definition: tmatrix.hh:100
uint sz
Column length.
Definition: tmatrix.hh:501
TMatrix(const TMatrix< G > &T)
to "upcast" TMatrix<Real> to TMatrix<Cmplx>
Definition: tmatrix.hh:645
Array< F > val_
The data of the column itself.
Definition: tmatrix.hh:97
Class providing an output operator.
TColumn(uint n, uint idx, TColumn< F > *lnk=0, F def=0)
Constructor.
uint offsetrow() const
Returns the offset row, that is starting row of the (possible) second matrix block.
Definition: tmatrix.hh:711
void operator()(const ElementMatrix<::std::complex< F > > &A, ElementMatrix<::std::complex< F > > &B) const
TMatrixBase(const uint n)
Constructor.
const uint * n() const
Returns the range of the multiindices as an array.
Definition: tmatrix.hh:259
uint n() const
Returns the number of rows.
Definition: tmatrix.hh:88
virtual void usedIdx(TColumn< bool > &c) const
The entries in c are true iff the corresponding local dof in any Column of this Matrix is non-zero,...
virtual ::std::ostream & info(::std::ostream &os) const
uint n_
Number of rows.
Definition: tmatrix.hh:103
T matrix for linear and regular elements.
Definition: tmatrix.hh:428
Array< Data > data_
Data array (matrix entries: row index and data)
Definition: tmatrix.hh:637
Basic namespace for Concepts-2.
Definition: pml_formula.h:16
uint n_
Number of columns.
Definition: tmatrix.hh:418
TMatrix(const TMatrix< F > &T, Set< uint > *idx=0)
Copy-Constructor.
TColumn< F > * link() const
Returns the pointer to the next column of the linked list.
Definition: tmatrix.hh:79
Page URL: http://wiki.math.ethz.ch/bin/view/Concepts/WebHome
21 August 2020
© 2020 Eidgenössische Technische Hochschule Zürich