Home | Doxygen Documentation | Tutorials | Developer Tools (restricted)

space/tmatrix.hh
Go to the documentation of this file.
00001 /* Tmatrix
00002  * T matrices map local dofs to global dofs and are used for the
00003  * assembling process
00004  */
00005 
00006 #ifndef tmatrix_hh
00007 #define tmatrix_hh
00008 
00009 #include <iostream>
00010 #include <map>
00011 #include "toolbox/array.hh"
00012 #include "toolbox/set.hh"
00013 #include "basics/outputOperator.hh"
00014 #include "basics/typedefs.hh"
00015 
00016 
00017 namespace concepts {
00018 
00019   // forward declaration
00020   template<class F>
00021   class ElementMatrix;
00022 
00023   template<class F>
00024   class Vector;
00025 
00026   template<class F, int dim>
00027   class TColumnBlock;
00028 
00029   // *************************************************************** TColumn **
00030 
00037   template<class F>
00038     class TColumn : public OutputOperator {
00039       public:
00040         // FIXME: of what use is a TColumn which has no entries, and can never get entries?
00042         TColumn() : val_(0), lnk_(0), n_(0), idx_(0)  {}
00048         TColumn(uint n, uint idx, TColumn<F>* lnk = 0, F def = 0);
00053         TColumn(const TColumn<F>& t);
00054         virtual ~TColumn();
00055 
00057         F operator[](uint i) const { return val_[i]; }
00059         F& operator[](uint i) { return val_[i]; }
00060 
00062         const F* values() const { return (const F*)val_; }
00064         F* values() { return (F*)val_; }
00065 
00067         uint index() const { return idx_; }
00068 
00070         TColumn<F>* link() const { return lnk_; }
00071 
00073         void append(TColumn<F>* T);
00074 
00076         void clear();
00077 
00079         uint n() const { return n_; }
00080 
00082         virtual TColumn<F>* clone() const;
00083       protected:
00084         virtual std::ostream& info(std::ostream& os) const;
00086         uint successors_() const;
00088         Array<F> val_;
00089       private:
00091         TColumn<F>* lnk_;
00092 
00094         uint n_;
00095 
00097         uint idx_;
00098     };
00099 
00101   template<class F>
00102     std::ostream& operator<<(std::ostream& os, TColumn<F>* T) {
00103       if (T != 0) {
00104         os << *T;
00105         if (T->link()) os << ", " << T->link();
00106       } else os << "TColumn(0)";
00107       return os;
00108     }
00109 
00110   // ********************************************************* TColumnTensor **
00111 
00124   template<class F, int dim>
00125     class TColumnTensor : public TColumn<F> {
00126       public:
00133         TColumnTensor(const uint* n, const uint idx, TColumn<F>* lnk = 0);
00138         TColumnTensor(const TColumnTensor<F, dim>& t);
00140         TColumnTensor(const TColumnBlock<F, dim>& t, uint k);
00142         TColumnTensor(const TColumnTensor<F, dim>& t, const uint* n);
00143 
00145         F operator[](uint* i) const {
00146 #ifdef DEBUG
00147           for (uint j = 0; j < dim; ++j)
00148             conceptsAssert3(i[j] < n_[j], Assertion(), "j = " << j << ", i[j] = "
00149                 << i[j] << ", n_[j] = " << n_[j]);
00150 #endif
00151           return TColumn<F>::operator[](
00152               dim == 2 ? i[0]+i[1]*n_[0] 
00153               : i[0]+i[1]*n_[0]+i[2]*n_[0]*n_[1]); 
00154         }
00156         F& operator[](uint* i) {
00157 #ifdef DEBUG
00158           for (uint j = 0; j < dim; ++j)
00159             conceptsAssert3(i[j] < n_[j], Assertion(), "j = " << j << ", i[j] = "
00160                 << i[j] << ", n_[j] = " << n_[j]);
00161 #endif
00162           return TColumn<F>::operator[](dim == 2 ? i[0]+i[1]*n_[0] :
00163               i[0]+i[1]*n_[0]+i[2]*n_[0]*n_[1]); }
00164 
00166           const uint* n() const { return n_; }
00167 
00168           virtual TColumnTensor<F, dim>* clone() const;
00169       protected:
00170           virtual std::ostream& info(std::ostream& os) const;
00171       private: 
00173           uint n_[dim];
00174           void recursiveOut_(const int d, uint* n, std::ostream& os) const;
00175     };
00176 
00177   // ********************************************************** TColumnBlock **
00178 
00206   template<class F, int dim>
00207     class TColumnBlock : public TColumn<F> {
00208       public:
00217         TColumnBlock(const uint* n, const uint idx,
00218             TColumn<F>* lnk = 0);
00223         TColumnBlock(const TColumnBlock<F, dim>& t);
00225         TColumnBlock(const TColumnBlock<F, dim>& t, const uint* n);
00226 
00230         F operator[](uint* i) const {
00231           return TColumn<F>::operator[](ldof(i));
00232         }
00233 
00235         F& operator[](uint* i) {
00236           return TColumn<F>::operator[](ldof(i));
00237         }
00238 
00242         void write(TColumnTensor<F,dim>& t, uint k);
00243 
00247         uint ldof(uint* i) const;
00248 
00250         inline const uint* n() const { return n_;} 
00252         inline const uint n(uint i) const { return n_[i]; }
00253 
00254         virtual TColumnBlock<F, dim>* clone() const;
00255       protected:
00256         virtual std::ostream& info(std::ostream& os) const;
00257       private: 
00259         uint n_[dim*dim];
00261         void recursiveOut_(const int d, uint* n, ushort& position, std::ostream& os) const;
00262     };
00263 
00264   // *********************************************************** TColumnsSet **
00265 
00282   template<class F, int dim>
00283     class TColumnSet : public OutputOperator {
00284       public:
00285         // Destructor
00286         ~TColumnSet();
00288         bool operator()(uint key);
00293         TColumn<F>* appendT(uint key, TColumn<F>* T);
00295         TColumn<F>* T(uint key) const;
00298         void p(uint key, ushort p[dim]);
00301         void p(uint key, ushort p);
00303         Array<ushort> p(uint key) const;
00305         void clear();
00306       protected:
00307         virtual std::ostream& info(std::ostream& os) const;
00308       private:
00310         std::map<uint, TColumn<F>*> T_;
00312         std::map<uint, Array<ushort> > p_;
00313     };
00314 
00315   // *********************************************************** TMatrixBase **
00316 
00339   template<class F> 
00340     class TMatrixBase : public OutputOperator {
00341       public:
00346         TMatrixBase(const uint n);
00347         virtual ~TMatrixBase();
00348 
00364         virtual void operator()(const ElementMatrix<F>& A, 
00365                                 ElementMatrix<F>& B) const = 0;
00366         virtual void operator()(const ElementMatrix<std::complex<F> >& A, 
00367                                 ElementMatrix<std::complex<F> >& B) const = 0;
00368 
00371         virtual uint index(const uint i) const = 0;
00372 
00374         inline uint m() const { return m_; }
00375         
00376         inline void setM(uint m) { m_ = m; }
00377 
00379         inline uint n() const { return n_; }
00380 
00386         virtual void usedIdx(TColumn<bool>& c) const = 0;
00387 
00396         virtual void extract(const concepts::Vector<F>& solution,
00397                              concepts::Array<F>& coeff) const = 0;
00398         virtual void extract(const concepts::Vector<std::complex<F> >& solution,
00399                              concepts::Array<std::complex<F> >& coeff) const = 0;
00400       protected:
00401         virtual std::ostream& info(std::ostream& os) const;
00402 
00404         uint n_;
00406         uint m_;
00407     };
00408 
00409   // **************************************************************** TIndex **
00410 
00413   template<class F> 
00414     class TIndex : public TMatrixBase<F> {
00415       public:
00421         TIndex(const uint m, const uint n, uint idx[]);
00422 
00428         TIndex(const uint m, const uint n, const Array<uint>& idx);
00429         virtual ~TIndex();
00430 
00441         void operator()(const ElementMatrix<F>& A, ElementMatrix<F>& B) const;
00442         void operator()(const ElementMatrix<std::complex<F> >& A,
00443                         ElementMatrix<std::complex<F> >& B) const;
00444 
00448         inline uint index(const uint i) const { return idx_[i]; }
00449 
00456         virtual void usedIdx(TColumn<bool>& c) const;
00457         virtual void extract(const concepts::Vector<F>& solution,
00458                              concepts::Array<F>& coeff) const;
00459         virtual void extract(const concepts::Vector<std::complex<F> >& solution,
00460                              concepts::Array<std::complex<F> >& coeff) const;
00461       protected:
00462         virtual std::ostream& info(std::ostream& os) const;
00463       private:
00464         Array<uint> idx_;
00465     };
00466 
00467   // *************************************************************** TMatrix **
00468 
00479   template<class F>
00480   class TMatrix : public TMatrixBase<F> { 
00481   public:
00483     struct Control : public OutputOperator {
00485       uint idx;
00487       uint sz;
00488     protected:
00489       virtual std::ostream& info(std::ostream& os) const;
00490     };
00491 
00493     struct Data : public OutputOperator {
00495       uint idx;
00497       F data;
00498     protected:
00499       virtual std::ostream& info(std::ostream& os) const;
00500     };
00501 
00506     TMatrix(TColumn<F>* T);
00511     TMatrix(const TMatrix<F>& T, Set<uint>* idx = 0);
00512     virtual ~TMatrix();
00513 
00515     template<class G>
00516     TMatrix(const TMatrix<G>& T);
00533     void operator()(const ElementMatrix<F>& A, ElementMatrix<F>& B) const;
00534     void operator()(const ElementMatrix<std::complex<F> >& A,
00535                     ElementMatrix<std::complex<F> >& B) const;
00536     void applyOne(const ElementMatrix<F>& A, ElementMatrix<F>& B) const;
00537 
00550     uint index(uint i) const { return ctrl_[i].idx; }
00551 
00559     void append(TColumn<F>* T);
00560 
00564     const typename TMatrix::Control* control(uint i) const { return &ctrl_[i]; };
00565 
00567     const typename TMatrix::Data* data(uint i) const { return data_+i; };
00568 
00569     // Returns the T-Matrix as linked list of columns
00570     TColumn<F>* columns() const;
00571 
00573     uint nEntries() const {
00574       return sz_;
00575     }
00576 
00577     virtual void usedIdx(TColumn<bool>& c) const;
00578     virtual void usedIdx(Set<uint>& c) const;
00579     virtual void extract(const concepts::Vector<F>& solution,
00580                          concepts::Array<F>& coeff) const;
00581     virtual void extract(const concepts::Vector<std::complex<F> >& solution,
00582                          concepts::Array<std::complex<F> >& coeff) const;
00583     void extractOne(const concepts::Vector<F>& solution,
00584                     concepts::Array<F>& coeff) const;
00585 
00586     std::ostream& outputLocalMap(std::ostream& os) const;
00587   protected:
00588     virtual std::ostream& info(std::ostream& os) const;
00589   private:
00593     Array<Control> ctrl_;
00594 
00596     Array<Data> data_;
00597 
00599     uint sz_;
00600   };
00601 
00602   template<class F>
00603   template<class G>
00604     TMatrix<F>::TMatrix(const TMatrix<G>& T)
00605     : TMatrixBase<F>(T.n())
00606       , ctrl_(T.n())
00607       , data_(T.nEntries())
00608       , sz_(T.nEntries())
00609     {
00610       setM( T.m() );
00611 
00612       for(uint i=0; i < this->n(); ++i) {
00613         ctrl_[i].idx = T.control(i)->idx;
00614         ctrl_[i].sz = T.control(i)->sz;
00615       }
00616       for(uint i=0; i < sz_; ++i) {
00617         data_[i].idx = T.data(i)->idx;
00618         data_[i].data = T.data(i)->data;
00619       }
00620 
00621     }
00622 
00623 } // namespace concepts
00624 
00625 #endif // tmatrix_hh

Home | Doxygen Documentation | Tutorials | Developer Tools (restricted)