3 #ifndef DUNE_AMG_KAMG_HH 4 #define DUNE_AMG_KAMG_HH 30 :
public Preconditioner<typename AMG::Domain,typename AMG::Range>
58 DUNE_UNUSED_PARAMETER(x); DUNE_UNUSED_PARAMETER(b);
64 DUNE_UNUSED_PARAMETER(x);
71 *levelContext_->update=0;
72 *levelContext_->rhs = d;
73 *levelContext_->lhs = v;
75 presmooth(*levelContext_, amg_.preSteps_);
76 bool processFineLevel =
77 amg_.moveToCoarseLevel(*levelContext_);
79 if(processFineLevel) {
83 coarseSolver_->apply(x, b, res);
84 *levelContext_->update=x;
87 amg_.moveToFineLevel(*levelContext_, processFineLevel);
90 v=*levelContext_->update;
119 std::shared_ptr<InverseOperator<Domain,Range> > coarseSolver_;
121 std::shared_ptr<typename AMG::LevelContext> levelContext_;
170 return amg.category();
187 const SmootherArgs& smootherArgs, std::size_t gamma,
188 std::size_t preSmoothingSteps=1, std::size_t postSmoothingSteps=1,
189 std::size_t maxLevelKrylovSteps=3,
double minDefectReduction=1e-1) DUNE_DEPRECATED;
202 KAMG(
const OperatorHierarchy& matrices, CoarseSolver& coarseSolver,
203 const SmootherArgs& smootherArgs,
const Parameters& parms,
204 std::size_t maxLevelKrylovSteps=3,
double minDefectReduction=1e-1);
227 KAMG(
const Operator& fineOperator,
const C& criterion,
228 const SmootherArgs& smootherArgs, std::size_t gamma,
229 std::size_t preSmoothingSteps=1, std::size_t postSmoothingSteps=1,
230 std::size_t maxLevelKrylovSteps=3,
double minDefectReduction=1e-1,
231 const ParallelInformation& pinfo=ParallelInformation()) DUNE_DEPRECATED;
247 KAMG(
const Operator& fineOperator,
const C& criterion,
248 const SmootherArgs& smootherArgs=SmootherArgs(),
249 std::size_t maxLevelKrylovSteps=3,
double minDefectReduction=1e-1,
250 const ParallelInformation& pinfo=ParallelInformation());
253 void pre(Domain& x, Range& b);
255 void post(Domain& x);
257 void apply(Domain& v,
const Range& d);
259 std::size_t maxlevels();
266 std::size_t maxLevelKrylovSteps;
269 double levelDefectReduction;
272 std::vector<std::shared_ptr<typename Amg::ScalarProduct> > scalarproducts;
275 std::vector<std::shared_ptr<KAmgTwoGrid<Amg> > > ksolvers;
278 template<
class M,
class X,
class S,
class P,
class K,
class A>
281 std::size_t gamma, std::size_t preSmoothingSteps,
282 std::size_t postSmoothingSteps,
283 std::size_t ksteps,
double reduction)
284 : amg(matrices, coarseSolver, smootherArgs, gamma, preSmoothingSteps,
285 postSmoothingSteps), maxLevelKrylovSteps(ksteps), levelDefectReduction(reduction)
288 template<
class M,
class X,
class S,
class P,
class K,
class A>
291 std::size_t ksteps,
double reduction)
292 : amg(matrices, coarseSolver, smootherArgs, params),
293 maxLevelKrylovSteps(ksteps), levelDefectReduction(reduction)
296 template<
class M,
class X,
class S,
class P,
class K,
class A>
300 std::size_t preSmoothingSteps, std::size_t postSmoothingSteps,
301 std::size_t ksteps,
double reduction,
303 : amg(fineOperator, criterion, smootherArgs, gamma, preSmoothingSteps,
304 postSmoothingSteps, false, pinfo), maxLevelKrylovSteps(ksteps), levelDefectReduction(reduction)
307 template<
class M,
class X,
class S,
class P,
class K,
class A>
311 std::size_t ksteps,
double reduction,
313 : amg(fineOperator, criterion, smootherArgs, pinfo),
314 maxLevelKrylovSteps(ksteps), levelDefectReduction(reduction)
318 template<
class M,
class X,
class S,
class P,
class K,
class A>
322 scalarproducts.reserve(amg.
levels());
323 ksolvers.reserve(amg.
levels());
326 matrix = amg.matrices_->matrices().coarsest();
328 pinfo = amg.matrices_->parallelInformation().coarsest();
332 if(matrix==amg.matrices_->matrices().finest())
340 std::ostringstream s;
342 if(matrix!=amg.matrices_->matrices().finest())
344 scalarproducts.push_back(createScalarProduct<X>(*pinfo,
category()));
345 std::shared_ptr<InverseOperator<Domain,Range> > ks =
346 std::shared_ptr<InverseOperator<Domain,Range> >(
new KrylovSolver(*matrix, *(scalarproducts.back()),
347 *(ksolvers.back()), levelDefectReduction,
348 maxLevelKrylovSteps, 0));
352 if(matrix==amg.matrices_->matrices().finest())
358 template<
class M,
class X,
class S,
class P,
class K,
class A>
365 template<
class M,
class X,
class S,
class P,
class K,
class A>
368 if(ksolvers.size()==0)
372 amg.solver_->apply(v,td,res);
375 typedef typename Amg::LevelContext LevelContext;
376 std::shared_ptr<LevelContext> levelContext(
new LevelContext);
377 amg.initIteratorsWithFineLevel(*levelContext);
378 typedef typename std::vector<std::shared_ptr<KAmgTwoGrid<Amg> > >::iterator Iter;
379 for(Iter solver=ksolvers.begin(); solver!=ksolvers.end(); ++solver)
380 (*solver)->setLevelContext(levelContext);
381 ksolvers.back()->apply(v,d);
385 template<
class M,
class X,
class S,
class P,
class K,
class A>
virtual SolverCategory::Category category() const
Category of the preconditioner (see SolverCategory::Category)
Definition: kamg.hh:168
X Domain
The domain type.
Definition: amg.hh:81
void postsmooth(LevelContext &levelContext, size_t steps)
Apply post smoothing on the current level.
Definition: smoother.hh:476
K KrylovSolver
The type of the Krylov solver for the cycle.
Definition: kamg.hh:147
void post(Domain &x)
Clean up.
Definition: kamg.hh:359
Amg::OperatorHierarchy OperatorHierarchy
The type of the hierarchy of operators.
Definition: kamg.hh:149
Definition: allocator.hh:7
KAmgTwoGrid(AMG &amg, std::shared_ptr< InverseOperator< Domain, Range > > coarseSolver)
Constructor.
Definition: kamg.hh:51
~KAmgTwoGrid()
Destructor.
Definition: kamg.hh:112
void setLevelContext(std::shared_ptr< typename AMG::LevelContext > p)
Set the level context pointer.
Definition: kamg.hh:106
void apply(Domain &v, const Range &d)
Apply one step of the preconditioner to the system A(v)=d.
Definition: kamg.hh:366
LevelIterator< Hierarchy< MatrixOperator, Allocator >, MatrixOperator > Iterator
Type of the mutable iterator.
Definition: hierarchy.hh:250
All parameters for AMG.
Definition: parameters.hh:390
Amg::Domain Domain
the type of the domain.
Definition: kamg.hh:159
PI ParallelInformation
The type of the parallel information. Either OwnerOverlapCommunication or another type describing the...
Definition: amg.hh:74
Amg::Operator Operator
the type of the lineatr operator.
Definition: kamg.hh:157
M Operator
The matrix operator type.
Definition: amg.hh:67
Generalized preconditioned conjugate gradient solver.
Definition: solvers.hh:1362
void pre(Domain &x, Range &b)
Prepare the preconditioner.
Definition: kamg.hh:319
void pre(Domain &x, Range &b)
Prepare the preconditioner.
Definition: amg.hh:559
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:279
Define general preconditioner interface.
void presmooth(LevelContext &levelContext, size_t steps)
Apply pre smoothing on the current level.
Definition: smoother.hh:454
AMG< M, X, S, PI, A > Amg
The type of the underlying AMG.
Definition: kamg.hh:145
std::size_t maxlevels()
Definition: kamg.hh:386
virtual SolverCategory::Category category() const
Category of the preconditioner (see SolverCategory::Category)
Definition: kamg.hh:39
Amg::ParallelInformationHierarchy ParallelInformationHierarchy
The type of the hierarchy of parallel information.
Definition: kamg.hh:163
Two grid operator for AMG with Krylov cycle.
Definition: amg.hh:44
Abstract base class for all solvers.
Definition: solver.hh:91
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:68
X Range
The range type.
Definition: amg.hh:83
Amg::SmootherArgs SmootherArgs
The type of the arguments for construction of the smoothers.
Definition: kamg.hh:155
The hierarchies build by the coarsening process.
Definition: hierarchy.hh:309
std::size_t maxlevels()
Definition: amg.hh:644
void pre(typename AMG::Domain &x, typename AMG::Range &b)
Prepare the preconditioner.
Definition: kamg.hh:56
Category
Definition: solvercategory.hh:21
void post(typename AMG::Domain &x)
Clean up.
Definition: kamg.hh:62
Base class for scalar product and norm computation.
Definition: scalarproducts.hh:46
virtual SolverCategory::Category category() const
Category of the preconditioner (see SolverCategory::Category)
Definition: amg.hh:138
SmootherTraits< Smoother >::Arguments SmootherArgs
The argument type for the construction of the smoother.
Definition: amg.hh:94
an algebraic multigrid method using a Krylov-cycle.
Definition: amg.hh:41
Amg::CoarseSolver CoarseSolver
The type of the coarse solver.
Definition: kamg.hh:151
void post(Domain &x)
Clean up.
Definition: amg.hh:896
Statistics about the application of an inverse operator.
Definition: solver.hh:40
Base class for matrix free definition of preconditioners.
Definition: preconditioner.hh:30
InverseOperator< Domain, Range > * coarseSolver()
Get a pointer to the coarse grid solver.
Definition: kamg.hh:97
Amg::ParallelInformation ParallelInformation
the type of the parallelinformation to use.
Definition: kamg.hh:153
Amg::ScalarProduct ScalarProduct
The type of the scalar product.
Definition: kamg.hh:165
Amg::Range Range
The type of the range.
Definition: kamg.hh:161
Parallel algebraic multigrid based on agglomeration.
Definition: amg.hh:58
std::size_t levels()
Definition: amg.hh:639