MathTL
|
00001 // -*- c++ -*- 00002 00003 // +--------------------------------------------------------------------+ 00004 // | This file is part of WaveletTL - the Wavelet Template Library | 00005 // | | 00006 // | Copyright (c) 2002-2009 | 00007 // | Thorsten Raasch, Manuel Werner | 00008 // +--------------------------------------------------------------------+ 00009 00010 #ifndef _WAVELETTL_QS_MATRIX_H 00011 #define _WAVELETTL_QS_MATRIX_H 00012 00013 #include <cmath> 00014 #include <map> 00015 #include <algebra/matrix.h> 00016 #include <algebra/sparse_matrix.h> 00017 00018 namespace MathTL 00019 { 00028 template <class C> 00029 class QuasiStationaryMatrix 00030 { 00031 public: 00035 typedef typename Vector<C>::size_type size_type; 00036 00038 QuasiStationaryMatrix(); 00039 00049 QuasiStationaryMatrix(const int j0, 00050 const size_type mj0, const size_type nj0, 00051 const Matrix<C>& ML, const Matrix<C>& MR, 00052 const Vector<C>& bandL, const Vector<C>& bandR, 00053 const size_type offsetL, const size_type offsetR, 00054 const double factor = 1.0); 00055 00057 QuasiStationaryMatrix<C>& operator = (const QuasiStationaryMatrix<C>& M); 00058 00062 const size_type row_dimension() const; 00063 00067 const size_type column_dimension() const; 00068 00072 const size_type ML_column_dimension() const { return ML_.column_dimension(); } 00073 00077 const size_type MR_column_dimension() const { return MR_.column_dimension(); } 00078 00082 void set_level(const int j) const; 00083 00087 const C get_entry(const size_type row, const size_type column) const; 00088 00092 void to_sparse(SparseMatrix<C>& S) const; 00093 00101 template <class VECTOR> 00102 void apply(const VECTOR& x, VECTOR& Mx, 00103 const size_type x_offset = 0, 00104 const size_type Mx_offset = 0, 00105 const bool add_to = false) const; 00106 00111 void apply(const std::map<size_type, C>& x, std::map<size_type, C>& Mx, 00112 const size_type x_offset = 0, 00113 const size_type Mx_offset = 0, 00114 const bool add_to = false) const; 00115 00121 template <class VECTOR> 00122 void apply_transposed(const VECTOR& x, VECTOR& Mtx, 00123 const size_type x_offset = 0, 00124 const size_type Mtx_offset = 0, 00125 const bool add_to = false) const; 00126 00131 void apply_transposed(const std::map<size_type, C>& x, std::map<size_type, C>& Mtx, 00132 const size_type x_offset = 0, 00133 const size_type Mtx_offset = 0, 00134 const bool add_to = false) const; 00135 00139 void apply_central_block 00140 (const std::map<size_type, C>& x, std::map<size_type, C>& Mx, 00141 const size_type x_offset = 0, 00142 const size_type Mx_offset = 0, 00143 const bool add_to = false) const; 00144 00148 void apply_central_block_transposed 00149 (const std::map<size_type, C>& x, std::map<size_type, C>& Mtx, 00150 const size_type x_offset = 0, 00151 const size_type Mtx_offset = 0, 00152 const bool add_to = false) const; 00153 00157 void apply_central_columns 00158 (const std::map<size_type, C>& x, std::map<size_type, C>& Mx, 00159 const size_type x_offset = 0, 00160 const size_type Mx_offset = 0, 00161 const bool add_to = false) const; 00162 00166 void apply_central_columns_transposed 00167 (const std::map<size_type, C>& x, std::map<size_type, C>& Mtx, 00168 const size_type x_offset = 0, 00169 const size_type Mtx_offset = 0, 00170 const bool add_to = false) const; 00171 00176 void print(std::ostream& os, 00177 const unsigned int tabwidth = 8, 00178 const unsigned int precision = 3) const; 00179 00180 protected: 00181 int j0_; 00182 mutable int j_; 00183 size_type mj0_, nj0_; 00184 Matrix<C> ML_, MR_; 00185 Vector<C> bandL_,bandR_; 00186 size_type offsetL_, offsetR_; 00187 double factor_; 00188 }; 00189 00193 template <class C> 00194 std::ostream& operator << (std::ostream& os, const QuasiStationaryMatrix<C>& M); 00195 00196 00205 template <class C> 00206 class PeriodicQuasiStationaryMatrix 00207 { 00208 public: 00212 typedef typename Vector<C>::size_type size_type; 00213 00221 PeriodicQuasiStationaryMatrix(const int j0, 00222 const int offset, 00223 const Array1D<C>& band, 00224 const double factor = 1.0); 00225 00227 PeriodicQuasiStationaryMatrix<C>& operator = (const PeriodicQuasiStationaryMatrix<C>& M); 00228 00232 const size_type row_dimension() const { return 1<<(j_+1); } 00233 00237 const size_type column_dimension() const { return 1<<j_; } 00238 00242 void set_level(const int j) const; 00243 00247 const C get_entry(const size_type row, const size_type column) const; 00248 00252 void to_sparse(SparseMatrix<C>& S) const; 00253 00261 template <class VECTOR> 00262 void apply(const VECTOR& x, VECTOR& Mx, 00263 const size_type x_offset = 0, 00264 const size_type Mx_offset = 0, 00265 const bool add_to = false) const; 00266 00272 template <class VECTOR> 00273 void apply_transposed(const VECTOR& x, VECTOR& Mtx, 00274 const size_type x_offset = 0, 00275 const size_type Mtx_offset = 0, 00276 const bool add_to = false) const; 00277 00282 void print(std::ostream& os, 00283 const unsigned int tabwidth = 8, 00284 const unsigned int precision = 3) const; 00285 00286 protected: 00287 int j0_, offset_; 00288 mutable int j_; 00289 Array1D<C> band_; 00290 double factor_; 00291 }; 00292 00296 template <class C> 00297 std::ostream& operator << (std::ostream& os, const PeriodicQuasiStationaryMatrix<C>& M); 00298 00299 } 00300 00301 #include <algebra/qs_matrix.cpp> 00302 00303 #endif