Dune Core Modules (2.3.1)

kamg.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_AMG_KAMG_HH
4 #define DUNE_AMG_KAMG_HH
5 
7 #include "amg.hh"
8 
9 namespace Dune
10 {
11  namespace Amg
12  {
13 
28  template<class AMG>
30  : public Preconditioner<typename AMG::Domain,typename AMG::Range>
31  {
33  typedef typename AMG::Domain Domain;
35  typedef typename AMG::Range Range;
36  public:
37 
38  enum {
41  };
42 
51  : amg_(amg), coarseSolver_(coarseSolver)
52  {}
53 
55  void pre(typename AMG::Domain& x, typename AMG::Range& b)
56  {}
57 
59  void post(typename AMG::Domain& x)
60  {}
61 
63  void apply(typename AMG::Domain& v, const typename AMG::Range& d)
64  {
65  // Copy data
66  *levelContext_->update=0;
67  *levelContext_->rhs = d;
68  *levelContext_->lhs = v;
69 
70  presmooth(*levelContext_, amg_.preSteps_);
71  bool processFineLevel =
72  amg_.moveToCoarseLevel(*levelContext_);
73 
74  if(processFineLevel) {
75  typename AMG::Range b=*levelContext_->rhs;
76  typename AMG::Domain x=*levelContext_->update;
78  coarseSolver_->apply(x, b, res);
79  *levelContext_->update=x;
80  }
81 
82  amg_.moveToFineLevel(*levelContext_, processFineLevel);
83 
84  postsmooth(*levelContext_, amg_.postSteps_);
85  v=*levelContext_->update;
86  }
87 
93  {
94  return coarseSolver_;
95  }
96 
102  {
103  levelContext_=p;
104  }
105 
108  {}
109 
110  private:
112  AMG& amg_;
117  };
118 
119 
120 
131  template<class M, class X, class S, class PI=SequentialInformation,
132  class K=GeneralizedPCGSolver<X>, class A=std::allocator<X> >
133  class KAMG : public Preconditioner<X,X>
134  {
135  public:
139  typedef K KrylovSolver;
143  typedef typename Amg::CoarseSolver CoarseSolver;
147  typedef typename Amg::SmootherArgs SmootherArgs;
149  typedef typename Amg::Operator Operator;
151  typedef typename Amg::Domain Domain;
153  typedef typename Amg::Range Range;
157  typedef typename Amg::ScalarProduct ScalarProduct;
158 
159  enum {
162  };
176  KAMG(const OperatorHierarchy& matrices, CoarseSolver& coarseSolver,
177  const SmootherArgs& smootherArgs, std::size_t gamma,
178  std::size_t preSmoothingSteps =1, std::size_t postSmoothingSteps = 1,
179  std::size_t maxLevelKrylovSteps = 3 , double minDefectReduction =1e-1);
180 
197  template<class C>
198  KAMG(const Operator& fineOperator, const C& criterion,
199  const SmootherArgs& smootherArgs, std::size_t gamma=1,
200  std::size_t preSmoothingSteps=1, std::size_t postSmoothingSteps=1,
201  std::size_t maxLevelKrylovSteps=3, double minDefectReduction=1e-1,
203 
205  void pre(Domain& x, Range& b);
207  void post(Domain& x);
209  void apply(Domain& v, const Range& d);
210 
211  std::size_t maxlevels();
212 
213  private:
215  Amg amg;
216 
218  std::size_t maxLevelKrylovSteps;
219 
221  double levelDefectReduction;
222 
224  std::vector<shared_ptr<typename Amg::ScalarProduct> > scalarproducts;
225 
227  std::vector<shared_ptr<KAmgTwoGrid<Amg> > > ksolvers;
228  };
229 
230  template<class M, class X, class S, class P, class K, class A>
232  const SmootherArgs& smootherArgs,
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)
238  {}
239 
240  template<class M, class X, class S, class P, class K, class A>
241  template<class C>
242  KAMG<M,X,S,P,K,A>::KAMG(const Operator& fineOperator, const C& criterion,
243  const SmootherArgs& smootherArgs, std::size_t gamma,
244  std::size_t preSmoothingSteps, std::size_t postSmoothingSteps,
245  std::size_t ksteps, double reduction,
246  const ParallelInformation& pinfo)
247  : amg(fineOperator, criterion, smootherArgs, gamma, preSmoothingSteps,
248  postSmoothingSteps, false, pinfo), maxLevelKrylovSteps(ksteps), levelDefectReduction(reduction)
249  {}
250 
251 
252  template<class M, class X, class S, class P, class K, class A>
254  {
255  amg.pre(x,b);
256  scalarproducts.reserve(amg.levels());
257  ksolvers.reserve(amg.levels());
258 
259  typename OperatorHierarchy::ParallelMatrixHierarchy::Iterator
260  matrix = amg.matrices_->matrices().coarsest();
262  pinfo = amg.matrices_->parallelInformation().coarsest();
263  bool hasCoarsest=(amg.levels()==amg.maxlevels());
264 
265  if(hasCoarsest) {
266  if(matrix==amg.matrices_->matrices().finest())
267  return;
268  --matrix;
269  --pinfo;
270  ksolvers.push_back(shared_ptr<KAmgTwoGrid<Amg> >(new KAmgTwoGrid<Amg>(amg, amg.solver_)));
271  }else
273 
274  std::ostringstream s;
275 
276  if(matrix!=amg.matrices_->matrices().finest())
277  while(true) {
278  scalarproducts.push_back(shared_ptr<typename Amg::ScalarProduct>(Amg::ScalarProductChooser::construct(*pinfo)));
280  shared_ptr<InverseOperator<Domain,Range> >(new KrylovSolver(*matrix, *(scalarproducts.back()),
281  *(ksolvers.back()), levelDefectReduction,
282  maxLevelKrylovSteps, 0));
283  ksolvers.push_back(shared_ptr<KAmgTwoGrid<Amg> >(new KAmgTwoGrid<Amg>(amg, ks)));
284  --matrix;
285  --pinfo;
286  if(matrix==amg.matrices_->matrices().finest())
287  break;
288  }
289  }
290 
291 
292  template<class M, class X, class S, class P, class K, class A>
294  {
295  amg.post(x);
296 
297  }
298 
299  template<class M, class X, class S, class P, class K, class A>
301  {
302  if(ksolvers.size()==0)
303  {
304  Range td=d;
306  amg.solver_->apply(v,td,res);
307  }else
308  {
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);
316  }
317  }
318 
319  template<class M, class X, class S, class P, class K, class A>
320  std::size_t KAMG<M,X,S,P,K,A>::maxlevels()
321  {
322  return amg.maxlevels();
323  }
324 
326  } // Amg
327 } // Dune
328 
329 #endif
The AMG preconditioner.
Parallel algebraic multigrid based on agglomeration.
Definition: amg.hh:57
an algebraic multigrid method using a Krylov-cycle.
Definition: kamg.hh:134
Amg::Domain Domain
the type of the domain.
Definition: kamg.hh:151
Amg::SmootherArgs SmootherArgs
The type of the arguments for construction of the smoothers.
Definition: kamg.hh:147
Amg::ParallelInformation ParallelInformation
the type of the parallelinformation to use.
Definition: kamg.hh:145
Amg::CoarseSolver CoarseSolver
The type of the coarse solver.
Definition: kamg.hh:143
Amg::OperatorHierarchy OperatorHierarchy
The type of the hierarchy of operators.
Definition: kamg.hh:141
Amg::Range Range
The type of the range.
Definition: kamg.hh:153
Amg::ScalarProduct ScalarProduct
The type of the scalar product.
Definition: kamg.hh:157
AMG< M, X, S, PI, A > Amg
The type of the underlying AMG.
Definition: kamg.hh:137
Amg::Operator Operator
the type of the lineatr operator.
Definition: kamg.hh:149
Amg::ParallelInformationHierarchy ParallelInformationHierarchy
The type of the hierarchy of parallel information.
Definition: kamg.hh:155
K KrylovSolver
The type of the Krylov solver for the cycle.
Definition: kamg.hh:139
@ category
The solver category.
Definition: kamg.hh:161
Two grid operator for AMG with Krylov cycle.
Definition: kamg.hh:31
void pre(typename AMG::Domain &x, typename AMG::Range &b)
Prepare the preconditioner.
Definition: kamg.hh:55
InverseOperator< Domain, Range > * coarseSolver()
Get a pointer to the coarse grid solver.
Definition: kamg.hh:92
~KAmgTwoGrid()
Destructor.
Definition: kamg.hh:107
KAmgTwoGrid(AMG &amg, shared_ptr< InverseOperator< Domain, Range > > coarseSolver)
Constructor.
Definition: kamg.hh:50
void post(typename AMG::Domain &x)
Clean up.
Definition: kamg.hh:59
void setLevelContext(Dune::shared_ptr< typename AMG::LevelContext > p)
Set the level context pointer.
Definition: kamg.hh:101
void apply(typename AMG::Domain &v, const typename AMG::Range &d)
Apply one step of the preconditioner to the system A(v)=d.
Definition: kamg.hh:63
@ category
The solver category.
Definition: kamg.hh:40
The hierarchies build by the coarsening process.
Definition: hierarchy.hh:318
Generalized preconditioned conjugate gradient solver.
Definition: solvers.hh:1365
Enables iteration over all entities of a given codimension and level of a grid. See also the document...
Definition: leveliterator.hh:31
Base class for matrix free definition of preconditioners.
Definition: preconditioner.hh:26
A reference counting smart pointer.
Definition: shared_ptr.hh:64
void apply(Domain &v, const Range &d)
Apply one step of the preconditioner to the system A(v)=d.
Definition: kamg.hh:300
X Domain
The domain type.
Definition: amg.hh:79
SmootherTraits< Smoother >::Arguments SmootherArgs
The argument type for the construction of the smoother.
Definition: amg.hh:92
M Operator
The matrix operator type.
Definition: amg.hh:65
void post(Domain &x)
Clean up.
Definition: kamg.hh:293
X Range
The range type.
Definition: amg.hh:81
void presmooth(LevelContext &levelContext, size_t steps)
Apply pre smoothing on the current level.
Definition: smoother.hh:408
void postsmooth(LevelContext &levelContext, size_t steps)
Apply post smoothing on the current level.
Definition: smoother.hh:430
KAMG(const OperatorHierarchy &matrices, CoarseSolver &coarseSolver, const SmootherArgs &smootherArgs, std::size_t gamma, std::size_t preSmoothingSteps=1, std::size_t postSmoothingSteps=1, std::size_t maxLevelKrylovSteps=3, double minDefectReduction=1e-1)
Construct a new amg with a specific coarse solver.
Definition: kamg.hh:231
void pre(Domain &x, Range &b)
Prepare the preconditioner.
Definition: kamg.hh:253
PI ParallelInformation
The type of the parallel information. Either OwnerOverlapCommunication or another type describing the...
Definition: amg.hh:72
@ category
The solver category.
Definition: amg.hh:96
Dune namespace.
Definition: alignment.hh:14
Define general preconditioner interface.
Statistics about the application of an inverse operator.
Definition: solver.hh:32
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 16, 22:29, 2024)