3 #ifndef DUNE_AMG_KAMG_HH
4 #define DUNE_AMG_KAMG_HH
66 *levelContext_->update=0;
67 *levelContext_->rhs = d;
68 *levelContext_->lhs = v;
70 presmooth(*levelContext_, amg_.preSteps_);
71 bool processFineLevel =
72 amg_.moveToCoarseLevel(*levelContext_);
74 if(processFineLevel) {
78 coarseSolver_->apply(x, b, res);
79 *levelContext_->update=x;
82 amg_.moveToFineLevel(*levelContext_, processFineLevel);
85 v=*levelContext_->update;
114 Dune::shared_ptr<InverseOperator<Domain,Range> > coarseSolver_;
116 Dune::shared_ptr<typename AMG::LevelContext> levelContext_;
131 template<
class M,
class X,
class S,
class PI=SequentialInformation,
178 std::size_t preSmoothingSteps =1, std::size_t postSmoothingSteps = 1,
179 std::size_t maxLevelKrylovSteps = 3 ,
double minDefectReduction =1e-1);
200 std::size_t preSmoothingSteps=1, std::size_t postSmoothingSteps=1,
201 std::size_t maxLevelKrylovSteps=3,
double minDefectReduction=1e-1,
218 std::size_t maxLevelKrylovSteps;
221 double levelDefectReduction;
224 std::vector<shared_ptr<typename Amg::ScalarProduct> > scalarproducts;
227 std::vector<shared_ptr<KAmgTwoGrid<Amg> > > ksolvers;
230 template<
class M,
class X,
class S,
class P,
class K,
class A>
233 std::size_t gamma, std::size_t preSmoothingSteps,
234 std::size_t postSmoothingSteps,
235 std::size_t ksteps,
double reduction)
236 : amg(matrices, coarseSolver, smootherArgs, gamma, preSmoothingSteps,
237 postSmoothingSteps), maxLevelKrylovSteps(ksteps), levelDefectReduction(reduction)
240 template<
class M,
class X,
class S,
class P,
class K,
class A>
244 std::size_t preSmoothingSteps, std::size_t postSmoothingSteps,
245 std::size_t ksteps,
double reduction,
247 : amg(fineOperator, criterion, smootherArgs, gamma, preSmoothingSteps,
248 postSmoothingSteps, false, pinfo), maxLevelKrylovSteps(ksteps), levelDefectReduction(reduction)
252 template<
class M,
class X,
class S,
class P,
class K,
class A>
256 scalarproducts.reserve(amg.levels());
257 ksolvers.reserve(amg.levels());
259 typename OperatorHierarchy::ParallelMatrixHierarchy::Iterator
260 matrix = amg.matrices_->matrices().coarsest();
262 pinfo = amg.matrices_->parallelInformation().coarsest();
263 bool hasCoarsest=(amg.levels()==amg.maxlevels());
266 if(matrix==amg.matrices_->matrices().finest())
274 std::ostringstream s;
276 if(matrix!=amg.matrices_->matrices().finest())
278 scalarproducts.push_back(shared_ptr<typename Amg::ScalarProduct>(Amg::ScalarProductChooser::construct(*pinfo)));
279 shared_ptr<InverseOperator<Domain,Range> > ks =
280 shared_ptr<InverseOperator<Domain,Range> >(
new KrylovSolver(*matrix, *(scalarproducts.back()),
281 *(ksolvers.back()), levelDefectReduction,
282 maxLevelKrylovSteps, 0));
286 if(matrix==amg.matrices_->matrices().finest())
292 template<
class M,
class X,
class S,
class P,
class K,
class A>
299 template<
class M,
class X,
class S,
class P,
class K,
class A>
302 if(ksolvers.size()==0)
306 amg.solver_->apply(v,td,res);
309 typedef typename Amg::LevelContext LevelContext;
310 Dune::shared_ptr<LevelContext> levelContext(
new LevelContext);
311 amg.initIteratorsWithFineLevel(*levelContext);
312 typedef typename std::vector<shared_ptr<KAmgTwoGrid<Amg> > >::iterator Iter;
313 for(Iter solver=ksolvers.begin(); solver!=ksolvers.end(); ++solver)
314 (*solver)->setLevelContext(levelContext);
315 ksolvers.back()->apply(v,d);
319 template<
class M,
class X,
class S,
class P,
class K,
class A>
322 return amg.maxlevels();