MathTL
algebra/kronecker_matrix.h
00001 // -*- c++ -*-
00002 
00003 // +--------------------------------------------------------------------+
00004 // | This file is part of MathTL - the Mathematical Template Library    |
00005 // |                                                                    |
00006 // | Copyright (c) 2002-2009                                            |
00007 // | Thorsten Raasch, Manuel Werner                                     |
00008 // +--------------------------------------------------------------------+
00009 
00010 #ifndef _MATHTL_KRONECKER_MATRIX_H
00011 #define _MATHTL_KRONECKER_MATRIX_H
00012 
00013 #include <iostream>
00014 #include <algebra/vector.h>
00015 #include <algebra/matrix_block.h>
00016 
00017 // matrix norms, for convenience
00018 #include <algebra/matrix_norms.h>
00019 
00020 namespace MathTL
00021 {
00030   template <class C, class MATRIX1, class MATRIX2>
00031   class KroneckerMatrix
00032     : public MatrixBlock<C>
00033   {
00034   public:
00036     typedef typename Vector<C>::size_type size_type;
00037     
00039     explicit KroneckerMatrix(const MATRIX1& A, const MATRIX2& B,
00040                              const double factor = 1.0);
00041     
00043     KroneckerMatrix(const KroneckerMatrix<C,MATRIX1,MATRIX2>& M);
00044 
00046     MatrixBlock<C>* clone() const;
00047 
00049     MatrixBlock<C>* clone_transposed() const;
00050 
00052     const size_type row_dimension() const;
00053 
00055     const size_type column_dimension() const;
00056 
00058     bool empty() const;
00059 
00061     const C operator () (const size_type row, const size_type column) const;
00062 
00064     const C get_entry(const size_type row, const size_type column) const;
00065 
00071     template <class VECTOR>
00072     void apply(const VECTOR& x, VECTOR& Mx) const;
00073 
00075     void apply(const Vector<C>& x, Vector<C>& Mx) const;
00076 
00082     template <class VECTOR>
00083     void apply_transposed(const VECTOR& x, VECTOR& Mtx) const;
00084 
00086     void apply_transposed(const Vector<C>& x, Vector<C>& Mtx) const;
00087     
00092     void print(std::ostream& os,
00093                const unsigned int tabwidth = 10,
00094                const unsigned int precision = 3) const;
00095 
00096   protected:
00097     MATRIX1 A;
00098     MATRIX2 B;
00099     C factor_;
00100   };
00101 
00105   template <class C, class MATRIX1, class MATRIX2>
00106   std::ostream& operator << (std::ostream& os, const KroneckerMatrix<C,MATRIX1,MATRIX2>& M);
00107 
00108   
00113   template <class C, class MATRIX1, class MATRIX2>
00114   class KroneckerHelper
00115   {
00116   public:
00118     typedef typename Vector<C>::size_type size_type;
00119     
00121     explicit KroneckerHelper(const MATRIX1& A, const MATRIX2& B,
00122                              const double factor = 1.0);
00123     
00125     KroneckerHelper(const KroneckerHelper<C,MATRIX1,MATRIX2>& M);
00126 
00128     const size_type row_dimension() const;
00129 
00131     const size_type column_dimension() const;
00132 
00134     void apply(const Vector<C>& x, Vector<C>& Mx,
00135                const size_type x_offset,
00136                const size_type Mx_offset,
00137                const bool add_to) const;
00138     
00140     void apply_transposed(const Vector<C>& x, Vector<C>& Mtx,
00141                           const size_type x_offset,
00142                           const size_type Mtx_offset,
00143                           const bool add_to) const;
00144 
00145   protected:
00146     MATRIX1 A;
00147     MATRIX2 B;
00148     C factor_;
00149   };  
00150 }
00151 
00152 // include implementation of inline functions
00153 #include <algebra/kronecker_matrix.cpp>
00154 
00155 #endif
 All Classes Functions Variables Typedefs Enumerations