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

operator/denseMatrix.hh
Go to the documentation of this file.
00001 /* A dense matrix
00002  */
00003 
00004 #ifndef denseMatrix_hh
00005 #define denseMatrix_hh
00006 
00007 #include "space/element.hh"
00008 #include "compositions.hh"
00009 #include "matrix.hh"
00010 #include <new>              // exception handling for function new
00011 
00012 namespace concepts {
00013 
00014   // forward declaration
00015   template<class F>
00016   class Space;
00017 
00018   template<class F, class G>
00019   class BilinearForm;
00020 
00021   // *********************************************************** DenseMatrix **
00022 
00038   template<class F>
00039   class DenseMatrix : public Matrix<F>, public ElementMatrix<F> {
00040   public:
00042     typedef typename Realtype<F>::type r_type;
00044     typedef typename Cmplxtype<F>::type c_type;
00045 
00068     template<class G>
00069     DenseMatrix(const Space<G>& spcX, const Space<G>& spcY,
00070                 BilinearForm<F,G>& bf);
00071 
00084     template<class G>
00085     DenseMatrix(const Space<G>& spc, BilinearForm<F,G>& bf);
00091     template<class G>
00092     DenseMatrix(const Space<G>& spcX, const Space<G>& spcY);
00093 
00100     DenseMatrix(int m, int n, bool transpose = false)
00101       : Matrix<F>(m, n), ElementMatrix<F>(transpose ? n : m, transpose ? m : n)
00102     {
00103   if(transpose)
00104     this->transpose();
00105     }
00106 
00110     DenseMatrix(const LiCo<F>& L);
00114     DenseMatrix(const Compose<F>& L);
00116     DenseMatrix(const DenseMatrix<F>& m);
00120     DenseMatrix(const Matrix<F>& m, bool t = false);
00125     DenseMatrix(const Vector<F>& v, bool t = false);
00126 
00127     virtual void operator()(const Function<r_type>& fncY,
00128                             Function<F>& fncX);
00129     virtual void operator()(const Function<c_type>& fncY,
00130                             Function<c_type>& fncX);
00131 
00132     template<class H, class I>
00133     void operator()(const Vector<H>& fncY, Vector<I>& fncX);
00134 
00135     virtual void transpMult(const Vector<r_type>& fncY,
00136                             Vector<F>& fncX);
00137     virtual void transpMult(const Vector<c_type>& fncY,
00138                             Vector<c_type>& fncX);
00139 
00140     virtual F operator()(const uint i, const uint j) const {
00141       return ElementMatrix<F>::operator()(i,j);
00142     }
00143 
00144     virtual F& operator()(const uint i, const uint j) {
00145       return ElementMatrix<F>::operator()(i,j);
00146     }
00147 
00152     void addInto(Matrix<F>& dest, const F fact,
00153                  const uint rowoffset = 0, const uint coloffset = 0) const;
00154     
00156     template<class T>
00157     void addInto(Matrix<T>& dest, const T fact,
00158                  const uint rowoffset = 0, const uint coloffset = 0) const
00159     {
00160       conceptsAssert(dest.dimX() >= this->dimX() + rowoffset, Assertion());
00161       conceptsAssert3(dest.dimY() >= this->dimY() + coloffset, Assertion(),
00162                       "dest.dimY() = " << dest.dimY() << ", dimY() = " <<
00163                       this->dimY() << ", coloffset = " << coloffset);
00164       for (uint i = 0; i < this->dimX(); ++i)
00165         for (uint j = 0; j < this->dimY(); ++j) {
00166           const F a = operator()(i,j);
00167           dest(i+rowoffset,j+coloffset) += a*fact;
00168         }
00169     };
00170 
00172     template<class T>
00173     void addIntoT(Matrix<T>& dest, const T fact,
00174                   const uint rowoffset = 0, const uint coloffset = 0) const {
00175       conceptsAssert(dest.dimY() >= this->dimX() + coloffset, Assertion());
00176       conceptsAssert3(dest.dimX() >= this->dimY() + rowoffset, Assertion(),
00177                       "dest.dimY() = " << dest.dimY() << ", dimY() = " <<
00178                       this->dimY() << ", coloffset = " << coloffset);
00179       for (uint i = 0; i < this->dimX(); ++i)
00180         for (uint j = 0; j < this->dimY(); ++j) {
00181           const F a = operator()(i,j);
00182           dest(j+rowoffset,i+coloffset) += a*fact;
00183         }
00184     };
00185 
00186   protected:
00187     virtual std::ostream& info(std::ostream& os) const;
00188   };
00189 
00190   template<class F>
00191   template<class H, class I>
00192   void DenseMatrix<F>::operator()(const Vector<H>& fncY, Vector<I>& fncX)
00193   {
00194     conceptsAssert(ElementMatrix<F>::m() == fncX.dim(), Assertion());
00195     conceptsAssert(ElementMatrix<F>::n() == fncY.dim(), Assertion());
00196     const F* m = (const F*)(*this);
00197     I* x(fncX); 
00198     for (uint i = 0; i < ElementMatrix<F>::m(); ++i) {
00199       H* y(fncY); 
00200       I fi = 0.0;
00201       for (uint j = 0; j < ElementMatrix<F>::n(); ++j)
00202         fi += *m++ * *y++;
00203       *x++ = fi;
00204     }
00205   }
00206 
00207 } // namespace concepts
00208 
00209 #endif // senseMatrix_hh

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