00001 #ifndef DUNE_AMGSMOOTHER_HH
00002 #define DUNE_AMGSMOOTHER_HH
00003
00004 #include<dune/istl/paamg/construction.hh>
00005 #include<dune/istl/preconditioners.hh>
00006 #include<dune/istl/schwarz.hh>
00007
00008 namespace Dune
00009 {
00010 namespace Amg
00011 {
00012
00027 template<class T>
00028 struct DefaultSmootherArgs
00029 {
00033 typedef T RelaxationFactor;
00034
00038 int iterations;
00042 RelaxationFactor relaxationFactor;
00043
00047 DefaultSmootherArgs()
00048 : iterations(1), relaxationFactor(1.0)
00049 {}
00050 };
00051
00055 template<class T>
00056 struct SmootherTraits
00057 {
00058 typedef DefaultSmootherArgs<typename T::matrix_type::field_type> Arguments;
00059
00060 };
00061
00062 template<class X, class Y, class C, class T>
00063 struct SmootherTraits<BlockPreconditioner<X,Y,C,T> >
00064 {
00065 typedef DefaultSmootherArgs<typename T::matrix_type::field_type> Arguments;
00066
00067 };
00068
00069 template<class T>
00070 class ConstructionTraits;
00071
00075 template<class T>
00076 class DefaultConstructionArgs
00077 {
00078 typedef T Matrix;
00079
00080 typedef DefaultSmootherArgs<typename Matrix::field_type> SmootherArgs;
00081
00082 public:
00083 void setMatrix(const Matrix& matrix)
00084 {
00085 matrix_=&matrix;
00086 }
00087
00088 const Matrix& getMatrix() const
00089 {
00090 return *matrix_;
00091 }
00092
00093 void setArgs(const SmootherArgs& args)
00094 {
00095 args_=&args;
00096 }
00097
00098 template<class T1>
00099 void setComm(T1& comm)
00100 {}
00101
00102 const SmootherArgs getArgs() const
00103 {
00104 return *args_;
00105 }
00106
00107 private:
00108 const Matrix* matrix_;
00109 const SmootherArgs* args_;
00110 };
00111
00112 template<class T>
00113 struct ConstructionArgs
00114 : public DefaultConstructionArgs<typename T::matrix_type>
00115 {};
00116
00117 template<class T, class C=SequentialInformation>
00118 class DefaultParallelConstructionArgs
00119 : public ConstructionArgs<T>
00120 {
00121 public:
00122 void setComm(const C& comm)
00123 {
00124 comm_ = &comm;
00125 }
00126
00127 const C& getComm() const
00128 {
00129 return *comm_;
00130 }
00131 private:
00132 const C* comm_;
00133 };
00134
00135
00139 template<class M, class X, class Y>
00140 struct ConstructionTraits<SeqSSOR<M,X,Y> >
00141 {
00142 typedef DefaultConstructionArgs<M> Arguments;
00143
00144 static inline SeqSSOR<M,X,Y>* construct(Arguments& args)
00145 {
00146 return new SeqSSOR<M,X,Y>(args.getMatrix(), args.getArgs().iterations,
00147 args.getArgs().relaxationFactor);
00148 }
00149
00150 static inline void deconstruct(SeqSSOR<M,X,Y>* ssor)
00151 {
00152 delete ssor;
00153 }
00154
00155 };
00156
00157
00161 template<class M, class X, class Y>
00162 struct ConstructionTraits<SeqSOR<M,X,Y> >
00163 {
00164 typedef DefaultConstructionArgs<M> Arguments;
00165
00166 static inline SeqSOR<M,X,Y>* construct(Arguments& args)
00167 {
00168 return new SeqSOR<M,X,Y>(args.getMatrix(), args.getArgs().iterations,
00169 args.getArgs().relaxationFactor);
00170 }
00171
00172 static inline void deconstruct(SeqSOR<M,X,Y>* sor)
00173 {
00174 delete sor;
00175 }
00176
00177 };
00181 template<class M, class X, class Y>
00182 struct ConstructionTraits<SeqJac<M,X,Y> >
00183 {
00184 typedef DefaultConstructionArgs<M> Arguments;
00185
00186 static inline SeqJac<M,X,Y>* construct(Arguments& args)
00187 {
00188 return new SeqJac<M,X,Y>(args.getMatrix(), args.getArgs().iterations,
00189 args.getArgs().relaxationFactor);
00190 }
00191
00192 static void deconstruct(SeqJac<M,X,Y>* jac)
00193 {
00194 delete jac;
00195 }
00196
00197 };
00198
00199
00203 template<class M, class X, class Y>
00204 struct ConstructionTraits<SeqILU0<M,X,Y> >
00205 {
00206 typedef DefaultConstructionArgs<M> Arguments;
00207
00208 static inline SeqILU0<M,X,Y>* construct(Arguments& args)
00209 {
00210 return new SeqILU0<M,X,Y>(args.getMatrix(),
00211 args.getArgs().relaxationFactor);
00212 }
00213
00214 static void deconstruct(SeqILU0<M,X,Y>* ilu)
00215 {
00216 delete ilu;
00217 }
00218
00219 };
00220
00221 template<class M, class X, class Y>
00222 class ConstructionArgs<SeqILUn<M,X,Y> >
00223 : public DefaultConstructionArgs<M>
00224 {
00225 public:
00226 ConstructionArgs(int n=1)
00227 : n_(n)
00228 {}
00229
00230 void setN(int n)
00231 {
00232 n_ = n;
00233 }
00234 int getN()
00235 {
00236 return n_;
00237 }
00238
00239 private:
00240 int n_;
00241 };
00242
00243
00247 template<class M, class X, class Y>
00248 struct ConstructionTraits<SeqILUn<M,X,Y> >
00249 {
00250 typedef ConstructionArgs<SeqILUn<M,X,Y> > Arguments;
00251
00252 static inline SeqILUn<M,X,Y>* construct(Arguments& args)
00253 {
00254 return new SeqILUn<M,X,Y>(args.getMatrix(), args.getN(),
00255 args.getArgs().relaxationFactor);
00256 }
00257
00258 static void deconstruct(SeqILUn<M,X,Y>* ilu)
00259 {
00260 delete ilu;
00261 }
00262
00263 };
00264
00265
00269 template<class M, class X, class Y, class C>
00270 struct ConstructionTraits<ParSSOR<M,X,Y,C> >
00271 {
00272 typedef DefaultParallelConstructionArgs<M,C> Arguments;
00273
00274 static inline ParSSOR<M,X,Y,C>* construct(Arguments& args)
00275 {
00276 return new ParSSOR<M,X,Y,C>(args.getMatrix(), args.getArgs().iterations,
00277 args.getArgs().relaxationFactor,
00278 args.getComm());
00279 }
00280 static inline void deconstruct(ParSSOR<M,X,Y,C>* ssor)
00281 {
00282 delete ssor;
00283 }
00284 };
00285
00286 template<class X, class Y, class C, class T>
00287 struct ConstructionTraits<BlockPreconditioner<X,Y,C,T> >
00288 {
00289 typedef DefaultParallelConstructionArgs<T,C> Arguments;
00290 typedef ConstructionTraits<T> SeqConstructionTraits;
00291 static inline BlockPreconditioner<X,Y,C,T>* construct(Arguments& args)
00292 {
00293 return new BlockPreconditioner<X,Y,C,T>(*SeqConstructionTraits::construct(args),
00294 args.getComm());
00295 }
00296
00297 static inline void deconstruct(BlockPreconditioner<X,Y,C,T>* bp)
00298 {
00299 SeqConstructionTraits::deconstruct(static_cast<T*>(&bp->preconditioner));
00300 delete bp;
00301 }
00302
00303 };
00304 }
00305 }
00306
00307
00308
00309 #endif