00001 #ifndef DUNE_PRECONDITIONERS_HH
00002 #define DUNE_PRECONDITIONERS_HH
00003
00004 #include<math.h>
00005 #include<complex>
00006 #include<iostream>
00007 #include<iomanip>
00008 #include<string>
00009
00010 #include"solvercategory.hh"
00011 #include "istlexception.hh"
00012 #include "matrixutils.hh"
00013 #include "io.hh"
00014 #include "gsetc.hh"
00015 #include "ilu.hh"
00016
00017
00018 namespace Dune {
00056
00066
00067 template<class X, class Y>
00068 class Preconditioner {
00069 public:
00071 typedef X domain_type;
00073 typedef Y range_type;
00075 typedef typename X::field_type field_type;
00076
00092 virtual void pre (X& x, Y& b) = 0;
00093
00104 virtual void apply (X& v, const Y& d) = 0;
00105
00114 virtual void post (X& x) = 0;
00115
00116
00117 virtual ~Preconditioner () {}
00118 };
00119
00120
00121
00122
00123
00124
00125
00132 template<class M, class X, class Y, int l=1>
00133 class SeqSSOR : public Preconditioner<X,Y> {
00134 public:
00136 typedef M matrix_type;
00138 typedef X domain_type;
00140 typedef Y range_type;
00142 typedef typename X::field_type field_type;
00143
00144
00145 enum {
00147 category=SolverCategory::sequential};
00148
00156 SeqSSOR (const M& A, int n, field_type w)
00157 : _A_(A), _n(n), _w(w)
00158 {
00159 CheckIfDiagonalPresent<l>::check(_A_);
00160 }
00161
00167 virtual void pre (X& x, Y& b) {}
00168
00174 virtual void apply (X& v, const Y& d)
00175 {
00176 for (int i=0; i<_n; i++){
00177 bsorf(_A_,v,d,_w,BL<l>());
00178 bsorb(_A_,v,d,_w,BL<l>());
00179 }
00180 }
00181
00187 virtual void post (X& x) {}
00188
00189 private:
00191 const M& _A_;
00193 int _n;
00195 field_type _w;
00196 };
00197
00198
00199
00206 template<class M, class X, class Y, int l=1>
00207 class SeqSOR : public Preconditioner<X,Y> {
00208 public:
00210 typedef M matrix_type;
00212 typedef X domain_type;
00214 typedef Y range_type;
00216 typedef typename X::field_type field_type;
00217
00218
00219 enum {
00221 category=SolverCategory::sequential
00222 };
00223
00231 SeqSOR (const M& A, int n, field_type w)
00232 : _A_(A), _n(n), _w(w)
00233 {
00234 CheckIfDiagonalPresent<l>::check(_A_);
00235 }
00236
00242 virtual void pre (X& x, Y& b) {}
00243
00249 virtual void apply (X& v, const Y& d)
00250 {
00251 for (int i=0; i<_n; i++){
00252 bsorf(_A_,v,d,_w,BL<l>());
00253 }
00254 }
00255
00261 virtual void post (X& x) {}
00262
00263 private:
00265 const M& _A_;
00267 int _n;
00269 field_type _w;
00270 };
00271
00272
00278 template<class M, class X, class Y, int l=1>
00279 class SeqGS : public Preconditioner<X,Y> {
00280 public:
00282 typedef M matrix_type;
00284 typedef X domain_type;
00286 typedef Y range_type;
00288 typedef typename X::field_type field_type;
00289
00290
00291 enum {
00293 category=SolverCategory::sequential
00294 };
00295
00303 SeqGS (const M& A, int n, field_type w)
00304 : _A_(A), _n(n), _w(w)
00305 {
00306 CheckIfDiagonalPresent<l>::check(_A_);
00307 }
00308
00314 virtual void pre (X& x, Y& b) {}
00315
00321 virtual void apply (X& v, const Y& d)
00322 {
00323 for (int i=0; i<_n; i++){
00324 dbgs(_A_,v,d,_w,BL<l>());
00325 }
00326 }
00327
00333 virtual void post (X& x) {}
00334
00335 private:
00337 const M& _A_;
00339 int _n;
00341 field_type _w;
00342 };
00343
00344
00350 template<class M, class X, class Y, int l=1>
00351 class SeqJac : public Preconditioner<X,Y> {
00352 public:
00354 typedef M matrix_type;
00356 typedef X domain_type;
00358 typedef Y range_type;
00360 typedef typename X::field_type field_type;
00361
00362
00363 enum {
00365 category=SolverCategory::sequential
00366 };
00367
00375 SeqJac (const M& A, int n, field_type w)
00376 : _A_(A), _n(n), _w(w)
00377 {
00378 CheckIfDiagonalPresent<l>::check(_A_);
00379 }
00380
00386 virtual void pre (X& x, Y& b) {}
00387
00393 virtual void apply (X& v, const Y& d)
00394 {
00395 for (int i=0; i<_n; i++){
00396 dbjac(_A_,v,d,_w,BL<l>());
00397 }
00398 }
00399
00405 virtual void post (X& x) {}
00406
00407 private:
00409 const M& _A_;
00411 int _n;
00413 field_type _w;
00414 };
00415
00416
00417
00424 template<class M, class X, class Y>
00425 class SeqILU0 : public Preconditioner<X,Y> {
00426 public:
00428 typedef M matrix_type;
00430 typedef X domain_type;
00432 typedef Y range_type;
00434 typedef typename X::field_type field_type;
00435
00436
00437 enum {
00439 category=SolverCategory::sequential
00440 };
00441
00448 SeqILU0 (const M& A, field_type w)
00449 : ILU(A)
00450 {
00451 _w =w;
00452 bilu0_decomposition(ILU);
00453 }
00454
00460 virtual void pre (X& x, Y& b) {}
00461
00467 virtual void apply (X& v, const Y& d)
00468 {
00469 bilu_backsolve(ILU,v,d);
00470 v *= _w;
00471 }
00472
00478 virtual void post (X& x) {}
00479
00480 private:
00482 field_type _w;
00484 M ILU;
00485 };
00486
00487
00494 template<class M, class X, class Y>
00495 class SeqILUn : public Preconditioner<X,Y> {
00496 public:
00498 typedef M matrix_type;
00500 typedef X domain_type;
00502 typedef Y range_type;
00504 typedef typename X::field_type field_type;
00505
00506
00507 enum {
00509 category=SolverCategory::sequential
00510 };
00511
00519 SeqILUn (const M& A, int n, field_type w)
00520 : ILU(A.N(),A.M(),M::row_wise)
00521 {
00522 _n = n;
00523 _w = w;
00524 bilu_decomposition(A,n,ILU);
00525 }
00526
00532 virtual void pre (X& x, Y& b) {}
00533
00539 virtual void apply (X& v, const Y& d)
00540 {
00541 bilu_backsolve(ILU,v,d);
00542 v *= _w;
00543 }
00544
00550 virtual void post (X& x) {}
00551
00552 private:
00554 M ILU;
00556 int _n;
00558 field_type _w;
00559 };
00560
00561
00562
00565 }
00566
00567 #endif