3#ifndef DUNE_ISTL_TWOLEVELMETHODCPR_HH
4#define DUNE_ISTL_TWOLEVELMETHODCPR_HH
11#include<dune/istl/operators.hh>
14#include<dune/istl/paamg/amg.hh>
15#include<dune/istl/paamg/galerkin.hh>
16#include<dune/istl/solver.hh>
18#include<dune/common/unused.hh>
19#include<dune/common/version.hh>
42template<
class FO,
class CO>
151template<
class O,
class C>
155 typedef Dune::Amg::AggregatesMap<typename O::matrix_type::size_type> AggregatesMap;
159 typedef SequentialInformation ParallelInformation;
167 prolongDamp_ = criterion_.getProlongationDampingFactor();
168 GalerkinProduct<ParallelInformation> productBuilder;
169 typedef typename Dune::Amg::MatrixGraph<const typename O::matrix_type> MatrixGraph;
170 typedef typename Dune::Amg::PropertiesGraph<MatrixGraph,Dune::Amg::VertexProperties,
171 Dune::Amg::EdgeProperties,Dune::IdentityMap,Dune::IdentityMap> PropertiesGraph;
172 MatrixGraph mg(fineOperator.getmat());
173 PropertiesGraph pg(mg,Dune::IdentityMap(),Dune::IdentityMap());
174 typedef NegateSet<typename ParallelInformation::OwnerSet> OverlapFlags;
176 aggregatesMap_.reset(
new AggregatesMap(pg.maxVertex()+1));
178 int noAggregates, isoAggregates, oneAggregates, skippedAggregates;
180 std::tie(noAggregates, isoAggregates, oneAggregates, skippedAggregates) =
181 aggregatesMap_->buildAggregates(fineOperator.getmat(), pg, criterion_,
true);
182 std::cout<<
"no aggregates="<<noAggregates<<
" iso="<<isoAggregates<<
" one="<<oneAggregates<<
" skipped="<<skippedAggregates<<std::endl;
184 Dune::Amg::IndicesCoarsener<Dune::Amg::SequentialInformation,int> renumberer;
185 typedef std::vector<bool>::iterator Iterator;
186 typedef Dune::IteratorPropertyMap<Iterator, Dune::IdentityMap> VisitedMap;
187 std::vector<bool> excluded(fineOperator.getmat().N(),
false);
188 VisitedMap vm(excluded.begin(), Dune::IdentityMap());
189 ParallelInformation pinfo;
190 std::size_t aggregates = renumberer.coarsen(pinfo, pg, vm,
191 *aggregatesMap_, pinfo,
193 std::vector<bool>& visited=excluded;
195 typedef std::vector<bool>::iterator Iterator;
197 for(Iterator iter= visited.begin(), end=visited.end();
200 matrix_.reset(productBuilder.build(mg, vm,
201 SequentialInformation(),
205 productBuilder.calculate(fineOperator.getmat(), *aggregatesMap_, *matrix_, pinfo, OverlapFlags());
206 this->
lhs_.resize(this->matrix_->M());
207 this->
rhs_.resize(this->matrix_->N());
213 Transfer<std::size_t,typename FatherType::FineRangeType,ParallelInformation>
214 ::restrictVector(*aggregatesMap_, this->
rhs_, fineRhs, ParallelInformation());
220 Transfer<std::size_t,typename FatherType::FineRangeType,ParallelInformation>
221 ::prolongateVector(*aggregatesMap_, this->
lhs_, fineLhs,
222 prolongDamp_, ParallelInformation());
231 typename O::matrix_type::field_type prolongDamp_;
232 std::shared_ptr<AggregatesMap> aggregatesMap_;
233 Criterion criterion_;
234 std::shared_ptr<typename O::matrix_type> matrix_;
243template<
class O,
class S,
class C>
250 typedef typename O::range_type
X;
265 : smootherArgs_(args), criterion_(c)
269 : coarseOperator_(other.coarseOperator_), smootherArgs_(other.smootherArgs_),
270 criterion_(other.criterion_)
279 struct AMGInverseOperator :
public InverseOperator<X,X>
281 AMGInverseOperator(
const typename AMGType::Operator& op,
283 const typename AMGType::SmootherArgs& args)
284 : amg_(op, crit,args), first_(true)
287 void apply(
X& x,
X& b, [[maybe_unused]]
double reduction, [[maybe_unused]] InverseOperatorResult& res)
298 void apply(
X& x,
X& b, InverseOperatorResult& res)
300 return apply(x,b,1e-8,res);
303 virtual SolverCategory::Category category()
const
305 return amg_.category();
308 ~AMGInverseOperator()
313 AMGInverseOperator(
const AMGInverseOperator& other)
314 : x_(other.x_), amg_(other.amg_), first_(other.first_)
337 coarseOperator_=transferPolicy.getCoarseLevelOperator();
338 AMGInverseOperator* inv =
new AMGInverseOperator(*coarseOperator_,
348 std::shared_ptr<Operator> coarseOperator_;
360template<
class FO,
class CSP,
class S>
362 public Preconditioner<typename FO::domain_type, typename FO::range_type>
415 std::shared_ptr<SmootherType> smoother,
419 std::size_t preSteps=1, std::size_t postSteps=1)
420 : operator_(&op), smoother_(smoother),
421 preSteps_(preSteps), postSteps_(postSteps)
423 policy_ = policy.
clone();
425 coarseSolver_=coarsePolicy.createCoarseLevelSolver(*policy_);
429 : operator_(other.operator_), coarseSolver_(new
CoarseLevelSolver(*other.coarseSolver_)),
430 smoother_(other.smoother_), policy_(other.policy_->clone()),
431 preSteps_(other.preSteps_), postSteps_(other.postSteps_)
438 delete coarseSolver_;
442 std::shared_ptr<SmootherType> smoother,
445 updatePreconditioner(smoother, coarsePolicy);
448 void updatePreconditioner(std::shared_ptr<SmootherType> smoother,
452 smoother_ = smoother;
455 coarsePolicy.setCoarseOperator(*policy_);
456 coarseSolver_->updatePreconditioner();
460 coarseSolver_ = coarsePolicy.createCoarseLevelSolver(*policy_);
477 LevelContext context;
478 SequentialInformation info;
482 context.smoother=smoother_;
484 context.matrix=operator_;
486 presmooth(context, preSteps_);
489 InverseOperatorResult res;
493 *context.update += *context.lhs;
495 postsmooth(context, postSteps_);
499 virtual SolverCategory::Category category()
const
501 return SolverCategory::sequential;
511 typedef S SmootherType;
513 std::shared_ptr<SmootherType> smoother;
529 SequentialInformation* pinfo;
541 std::shared_ptr<S> smoother_;
543 LevelTransferPolicyCpr<FO,typename CSP::Operator>* policy_;
545 std::size_t preSteps_;
547 std::size_t postSteps_;
A LeveTransferPolicy that used aggregation to construct the coarse level system.
Definition twolevelmethodcpr.hh:154
void moveToFineLevel(typename FatherType::FineDomainType &fineLhs)
Updates the fine level linear system after the correction of the coarse levels system.
Definition twolevelmethodcpr.hh:218
void createCoarseLevelSystem(const O &fineOperator)
Algebraically creates the coarse level system.
Definition twolevelmethodcpr.hh:165
AggregationLevelTransferPolicyCpr * clone() const
Clone the current object.
Definition twolevelmethodcpr.hh:225
Abstract base class for transfer between levels and creation of the coarse level system.
Definition twolevelmethodcpr.hh:44
CoarseOperatorType::range_type CoarseRangeType
The type of the range of the coarse level operator.
Definition twolevelmethodcpr.hh:67
CoarseDomainType & getCoarseLevelLhs()
Get the coarse level left hand side.
Definition twolevelmethodcpr.hh:93
virtual LevelTransferPolicyCpr * clone() const =0
Clone the current object.
FO FineOperatorType
The linear operator of the finel level system.
Definition twolevelmethodcpr.hh:50
virtual void createCoarseLevelSystem(const FineOperatorType &fineOperator)=0
Algebraically creates the coarse level system.
virtual void moveToCoarseLevel(const FineRangeType &fineRhs)=0
Transfers the data to the coarse level.
CoarseOperatorType::domain_type CoarseDomainType
The type of the domain of the coarse level operator.
Definition twolevelmethodcpr.hh:71
FineOperatorType::range_type FineRangeType
The type of the range of the fine level operator.
Definition twolevelmethodcpr.hh:54
CoarseRangeType & getCoarseLevelRhs()
Get the coarse level right hand side.
Definition twolevelmethodcpr.hh:84
virtual ~LevelTransferPolicyCpr()
Destructor.
Definition twolevelmethodcpr.hh:135
virtual void moveToFineLevel(FineDomainType &fineLhs)=0
Updates the fine level linear system after the correction of the coarse levels system.
virtual void calculateCoarseEntries(const FineOperatorType &fineOperator)=0
???.
CoarseDomainType lhs_
The coarse level lhs.
Definition twolevelmethodcpr.hh:141
CoarseRangeType rhs_
The coarse level rhs.
Definition twolevelmethodcpr.hh:139
FineOperatorType::domain_type FineDomainType
The type of the domain of the fine level operator.
Definition twolevelmethodcpr.hh:58
CO CoarseOperatorType
The linear operator of the finel level system.
Definition twolevelmethodcpr.hh:63
std::shared_ptr< CoarseOperatorType > & getCoarseLevelOperator()
Get the coarse level operator.
Definition twolevelmethodcpr.hh:76
std::shared_ptr< CoarseOperatorType > operator_
the coarse level linear operator.
Definition twolevelmethodcpr.hh:143
A policy class for solving the coarse level system using one step of AMG.
Definition twolevelmethodcpr.hh:245
AMG< Operator, X, Smoother > AMGType
The type of the AMG construct on the coarse level.
Definition twolevelmethodcpr.hh:258
OneStepAMGCoarseSolverPolicyCpr(const OneStepAMGCoarseSolverPolicyCpr &other)
Copy constructor.
Definition twolevelmethodcpr.hh:268
AMGInverseOperator CoarseLevelSolver
The type of solver constructed for the coarse level.
Definition twolevelmethodcpr.hh:325
S Smoother
The type of the smoother used in AMG.
Definition twolevelmethodcpr.hh:254
C Criterion
The type of the crition used for the aggregation within AMG.
Definition twolevelmethodcpr.hh:252
Dune::Amg::SmootherTraits< S >::Arguments SmootherArgs
The type of the arguments used for constructing the smoother.
Definition twolevelmethodcpr.hh:256
CoarseLevelSolver * createCoarseLevelSolver(P &transferPolicy)
Constructs a coarse level solver.
Definition twolevelmethodcpr.hh:335
O::range_type X
The type of the range and domain of the operator.
Definition twolevelmethodcpr.hh:250
OneStepAMGCoarseSolverPolicyCpr(const SmootherArgs &args, const Criterion &c)
Constructs the coarse solver policy.
Definition twolevelmethodcpr.hh:264
O Operator
The type of the linear operator used.
Definition twolevelmethodcpr.hh:248
Definition twolevelmethodcpr.hh:363
S SmootherType
The type of the fine level smoother.
Definition twolevelmethodcpr.hh:398
FineOperatorType::range_type FineRangeType
The type of the range of the fine level operator.
Definition twolevelmethodcpr.hh:377
TwoLevelMethodCpr(const FineOperatorType &op, std::shared_ptr< SmootherType > smoother, const LevelTransferPolicyCpr< FineOperatorType, CoarseOperatorType > &policy, CoarseLevelSolverPolicy &coarsePolicy, std::size_t preSteps=1, std::size_t postSteps=1)
Constructs a two level method.
Definition twolevelmethodcpr.hh:414
FineOperatorType::domain_type FineDomainType
The type of the domain of the fine level operator.
Definition twolevelmethodcpr.hh:381
CoarseOperatorType::domain_type CoarseDomainType
The type of the domain of the coarse level operator.
Definition twolevelmethodcpr.hh:394
CSP::Operator CoarseOperatorType
The linear operator of the finel level system.
Definition twolevelmethodcpr.hh:386
CSP CoarseLevelSolverPolicy
The type of the policy for constructing the coarse level solver.
Definition twolevelmethodcpr.hh:366
CoarseLevelSolverPolicy::CoarseLevelSolver CoarseLevelSolver
The type of the coarse level solver.
Definition twolevelmethodcpr.hh:368
CoarseOperatorType::range_type CoarseRangeType
The type of the range of the coarse level operator.
Definition twolevelmethodcpr.hh:390
FO FineOperatorType
The linear operator of the finel level system.
Definition twolevelmethodcpr.hh:373