5 #ifndef DUNE_AMGSMOOTHER_HH 6 #define DUNE_AMGSMOOTHER_HH 13 #include <dune/common/propertymap.hh> 14 #include <dune/common/ftraits.hh> 71 template<
class X,
class Y>
78 template<
class X,
class Y,
class C,
class T>
83 template<
class C,
class T>
94 typedef typename T::matrix_type Matrix;
150 template<
class T,
class C=SequentialInformation>
172 template<
class X,
class Y>
183 template <
class... Args>
207 const SmootherArgs* args_;
214 struct ConstructionTraits;
219 template<
class M,
class X,
class Y,
int l>
226 return std::make_shared<SeqSSOR<M,X,Y,l>>
235 template<
class M,
class X,
class Y,
int l>
242 return std::make_shared<SeqSOR<M,X,Y,l>>
251 template<
class M,
class X,
class Y,
int l>
258 return std::make_shared<SeqJac<M,X,Y,l>>
266 template<
class X,
class Y>
273 return std::make_shared<Richardson<X,Y>>
279 template<
class M,
class X,
class Y>
306 template<
class M,
class X,
class Y>
313 return std::make_shared<SeqILU<M,X,Y>>
321 template<
class M,
class X,
class Y,
class C>
328 return std::make_shared<ParSSOR<M,X,Y,C>>
334 template<
class X,
class Y,
class C,
class T>
341 auto seqPrec = SeqConstructionTraits::construct(args);
342 return std::make_shared<BlockPreconditioner<X,Y,C,T>> (seqPrec, args.
getComm());
346 template<
class C,
class T>
353 auto seqPrec = SeqConstructionTraits::construct(args);
354 return std::make_shared<NonoverlappingBlockPreconditioner<C,T>> (seqPrec, args.
getComm());
372 typedef typename Smoother::range_type
Range;
373 typedef typename Smoother::domain_type
Domain;
405 template<
typename LevelContext>
406 void presmooth(LevelContext& levelContext,
size_t steps)
408 for(std::size_t i=0; i < steps; ++i) {
411 ::preSmooth(*levelContext.smoother, *levelContext.lhs,
414 *levelContext.update += *levelContext.lhs;
417 levelContext.matrix->applyscaleadd(-1, *levelContext.lhs, *levelContext.rhs);
418 levelContext.pinfo->project(*levelContext.rhs);
427 template<
typename LevelContext>
430 for(std::size_t i=0; i < steps; ++i) {
432 levelContext.matrix->applyscaleadd(-1, *levelContext.lhs,
435 levelContext.pinfo->project(*levelContext.rhs);
437 ::postSmooth(*levelContext.smoother, *levelContext.lhs, *levelContext.rhs);
439 *levelContext.update += *levelContext.lhs;
443 template<
class M,
class X,
class Y,
int l>
452 smoother.template apply<true>(v,d);
458 smoother.template apply<false>(v,d);
462 template<
class M,
class X,
class Y,
class C,
int l>
471 smoother.template apply<true>(v,d);
477 smoother.template apply<false>(v,d);
481 template<
class M,
class X,
class Y,
class C,
int l>
490 smoother.template apply<true>(v,d);
496 smoother.template apply<false>(v,d);
503 template<
class M,
class X,
class MO,
class MS,
class A>
504 class SeqOverlappingSchwarz;
506 struct MultiplicativeSchwarzMode;
510 template<
class M,
class X,
class MS,
class TA>
520 smoother.template apply<true>(v,d);
526 smoother.template apply<false>(v,d);
544 bool onthefly_=
false)
549 template<
class M,
class X,
class TM,
class TS,
class TA>
555 template<
class M,
class X,
class TM,
class TS,
class TA>
570 Father::setMatrix(matrix);
572 std::vector<bool> visited(amap.
noVertices(),
false);
573 typedef IteratorPropertyMap<std::vector<bool>::iterator,IdentityMap> VisitedMapType;
574 VisitedMapType visitedMap(visited.begin());
580 switch(Father::getArgs().overlap) {
581 case SmootherArgs::vertex :
583 VertexAdder visitor(subdomains, amap);
584 createSubdomains(matrix, graph, amap, visitor, visitedMap);
587 case SmootherArgs::pairwise :
589 createPairDomains(graph);
592 case SmootherArgs::aggregate :
594 AggregateAdder<VisitedMapType> visitor(subdomains, amap, graph, visitedMap);
595 createSubdomains(matrix, graph, amap, visitor, visitedMap);
598 case SmootherArgs::none :
600 createSubdomains(matrix, graph, amap, visitor, visitedMap);
603 DUNE_THROW(NotImplemented,
"This overlapping scheme is not supported!");
608 Father::setMatrix(matrix);
614 iter!=amap.end(); ++iter)
617 std::vector<bool> visited(amap.noVertices(),
false);
618 typedef IteratorPropertyMap<std::vector<bool>::iterator,IdentityMap> VisitedMapType;
619 VisitedMapType visitedMap(visited.begin());
625 switch(Father::getArgs().overlap) {
626 case SmootherArgs::vertex :
628 VertexAdder visitor(subdomains, amap);
629 createSubdomains(matrix, graph, amap, visitor, visitedMap);
632 case SmootherArgs::aggregate :
634 DUNE_THROW(NotImplemented,
"Aggregate overlap is not supported yet");
641 case SmootherArgs::pairwise :
643 createPairDomains(graph);
646 case SmootherArgs::none :
648 createSubdomains(matrix, graph, amap, visitor, visitedMap);
662 : subdomains(subdomains_), max(-1), subdomain(-1), aggregates(aggregates_)
668 subdomains[subdomain].insert(edge.target());
672 subdomain=aggregate_;
673 max = std::max(subdomain, aggregate_);
702 struct AggregateAdder
706 : subdomains(subdomains_), subdomain(-1), aggregates(aggregates_),
707 adder(subdomains_, aggregates_), graph(graph_), visitedMap(visitedMap_)
712 subdomains[subdomain].insert(edge.target());
717 assert(aggregates[edge.target()]!=aggregate);
719 aggregates.template breadthFirstSearch<true,false>(edge.target(), aggregate,
720 graph, vlist, adder, adder,
727 adder.setAggregate(aggregate_);
728 aggregate=aggregate_;
750 typedef typename M::size_type size_type;
752 std::set<std::pair<size_type,size_type> > pairs;
754 for(VIter v=graph.
begin(), ve=graph.
end(); ve != v; ++v)
755 for(EIter e = v.begin(), ee=v.end(); ee!=e; ++e)
758 if(e.source()<e.target())
759 pairs.insert(std::make_pair(e.source(),e.target()));
761 pairs.insert(std::make_pair(e.target(),e.source()));
765 subdomains.resize(pairs.size());
766 Dune::dinfo <<std::endl<<
"Created "<<pairs.size()<<
" ("<<total<<
") pair domains"<<std::endl<<std::endl;
767 typedef typename std::set<std::pair<size_type,size_type> >::const_iterator SIter;
768 typename Vector::iterator subdomain=subdomains.begin();
770 for(SIter s=pairs.begin(), se =pairs.end(); se!=s; ++s)
772 subdomain->insert(s->first);
773 subdomain->insert(s->second);
776 std::size_t minsize=10000;
777 std::size_t maxsize=0;
779 for(
typename Vector::size_type i=0; i < subdomains.size(); ++i) {
780 sum+=subdomains[i].size();
781 minsize=std::min(minsize, subdomains[i].size());
782 maxsize=std::max(maxsize, subdomains[i].size());
784 Dune::dinfo<<
"Subdomain size: min="<<minsize<<
" max="<<maxsize<<
" avg="<<(sum/subdomains.size())
785 <<
" no="<<subdomains.size()<<std::endl;
788 template<
class Visitor>
789 void createSubdomains(
const M& ,
const MatrixGraph<const M>& graph,
790 const AggregatesMap& amap, Visitor& overlapVisitor,
791 IteratorPropertyMap<std::vector<bool>::iterator,IdentityMap>& visitedMap )
798 AggregateDescriptor maxAggregate=0;
800 for(std::size_t i=0; i < amap.noVertices(); ++i)
804 maxAggregate = std::max(maxAggregate, amap[i]);
806 subdomains.resize(maxAggregate+1+isolated);
809 for(
typename Vector::size_type i=0; i < subdomains.size(); ++i)
810 subdomains[i].clear();
815 VertexAdder aggregateVisitor(subdomains, amap);
817 for(VertexDescriptor i=0; i < amap.noVertices(); ++i)
818 if(!
get(visitedMap, i)) {
819 AggregateDescriptor aggregate=amap[i];
823 subdomains.push_back(Subdomain());
824 aggregate=subdomains.size()-1;
826 overlapVisitor.setAggregate(aggregate);
827 aggregateVisitor.setAggregate(aggregate);
828 subdomains[aggregate].insert(i);
830 amap.template breadthFirstSearch<false,false>(i, aggregate, graph, vlist, aggregateVisitor,
831 overlapVisitor, visitedMap);
834 std::size_t minsize=10000;
835 std::size_t maxsize=0;
837 for(
typename Vector::size_type i=0; i < subdomains.size(); ++i) {
838 sum+=subdomains[i].size();
839 minsize=std::min(minsize, subdomains[i].size());
840 maxsize=std::max(maxsize, subdomains[i].size());
842 Dune::dinfo<<
"Subdomain size: min="<<minsize<<
" max="<<maxsize<<
" avg="<<(sum/subdomains.size())
843 <<
" no="<<subdomains.size()<<
" isolated="<<isolated<<std::endl;
852 template<
class M,
class X,
class TM,
class TS,
class TA>
859 return std::make_shared<SeqOverlappingSchwarz<M,X,TM,TS,TA>>
static void preSmooth(Smoother &smoother, Domain &v, const Range &d)
Definition: smoother.hh:518
VertexIterator end()
Get an iterator over the vertices.
Sequential ILU preconditioner.
Definition: preconditioners.hh:697
int setAggregate(const AggregateDescriptor &aggregate_)
Definition: smoother.hh:725
Helper classes for the construction of classes without empty constructor.
DefaultConstructionArgs< SeqJac< M, X, Y, l > > Arguments
Definition: smoother.hh:254
Sequential SOR preconditioner.
Definition: preconditioners.hh:262
static void postSmooth(Smoother &smoother, Domain &v, Range &d)
Definition: smoother.hh:494
VertexIterator begin()
Get an iterator over the vertices.
Traits class for getting the attribute class of a smoother.
Definition: smoother.hh:65
int noSubdomains() const
Definition: smoother.hh:695
Definition: smoother.hh:535
DefaultParallelConstructionArgs< T, C > Arguments
Definition: smoother.hh:337
static void preSmooth(Smoother &smoother, Domain &v, Range &d)
Definition: smoother.hh:469
virtual void setMatrix(const Matrix &matrix, [[maybe_unused]] const AggregatesMap &amap)
Definition: smoother.hh:108
VertexAdder(Vector &subdomains_, const AggregatesMap &aggregates_)
Definition: smoother.hh:661
static void postSmooth(Smoother &smoother, Domain &v, const Range &d)
apply post smoothing in forward direction
Definition: smoother.hh:394
void setMatrix(const M &matrix)
Definition: smoother.hh:606
Y range_type
The range type of the preconditioner.
Definition: schwarz.hh:290
SeqOverlappingSchwarzSmootherArgs< typename M::field_type > Arguments
Definition: smoother.hh:552
X domain_type
The domain type of the preconditioner.
Definition: preconditioners.hh:267
ConstructionTraits< T > SeqConstructionTraits
Definition: smoother.hh:350
void operator()(const T &edge)
Definition: smoother.hh:665
Definition: smoother.hh:146
Tag that tells the Schwarz method to be multiplicative.
Definition: overlappingschwarz.hh:125
static std::shared_ptr< NonoverlappingBlockPreconditioner< C, T > > construct(Arguments &args)
Definition: smoother.hh:351
X domain_type
The domain type of the preconditioner.
Definition: overlappingschwarz.hh:765
const Matrix & getMatrix() const
Definition: smoother.hh:114
const SequentialInformation & getComm()
Definition: smoother.hh:196
Sequential overlapping Schwarz preconditioner.
Definition: ldl.hh:43
SeqSOR< M, X, Y, l > Smoother
Definition: smoother.hh:446
void setMatrix(const Args &...)
Definition: smoother.hh:184
void setMatrix(const Matrix &matrix)
Definition: smoother.hh:104
DefaultParallelConstructionArgs< T, C > Arguments
Definition: smoother.hh:349
int noSubdomains() const
Definition: smoother.hh:676
Definition: smoother.hh:173
M::size_type VertexDescriptor
The vertex descriptor.
Definition: graph.hh:73
AggregateDescriptor * iterator
Definition: aggregates.hh:741
virtual ~DefaultConstructionArgs()
Definition: smoother.hh:101
Definition: smoother.hh:538
static std::shared_ptr< SeqSOR< M, X, Y, l > > construct(Arguments &args)
Definition: smoother.hh:240
std::size_t noVertices() const
Get the number of vertices.
BlockPreconditioner< X, Y, C, SeqSOR< M, X, Y, l > > Smoother
Definition: smoother.hh:465
Smoother::domain_type Domain
Definition: smoother.hh:373
void setComm([[maybe_unused]] T1 &comm)
Definition: smoother.hh:193
int setAggregate(const AggregateDescriptor &)
Definition: smoother.hh:691
Definition: smoother.hh:538
const SequentialInformation & getComm()
Definition: smoother.hh:128
Smoother::domain_type Domain
Definition: smoother.hh:467
Definition: smoother.hh:538
Define general preconditioner interface.
static std::shared_ptr< SeqOverlappingSchwarz< M, X, TM, TS, TA > > construct(Arguments &args)
Definition: smoother.hh:857
Sequential SSOR preconditioner.
Definition: preconditioners.hh:142
int iterations
The number of iterations to perform.
Definition: smoother.hh:47
RelaxationFactor relaxationFactor
The relaxation factor to use.
Definition: smoother.hh:51
Block parallel preconditioner.
Definition: schwarz.hh:278
Definition: smoother.hh:280
static std::shared_ptr< SeqILU< M, X, Y > > construct(Arguments &args)
Definition: smoother.hh:311
ConstructionArgs< SeqILU< M, X, Y > > Arguments
Definition: smoother.hh:309
DefaultConstructionArgs< Richardson< X, Y > > Arguments
Definition: smoother.hh:269
bool onthefly
Definition: smoother.hh:541
int setAggregate(const AggregateDescriptor &aggregate_)
Definition: smoother.hh:670
Traits class for generically constructing non default constructable types.
Definition: novlpschwarz.hh:257
DefaultSmootherArgs()
Default constructor.
Definition: smoother.hh:56
Richardson preconditioner.
Definition: preconditioners.hh:878
SeqOverlappingSchwarzSmootherArgs(Overlap overlap_=vertex, bool onthefly_=false)
Definition: smoother.hh:543
Y range_type
The range type of the preconditioner.
Definition: preconditioners.hh:269
Dune::Amg::AggregatesMap< VertexDescriptor > AggregatesMap
Definition: smoother.hh:563
The sequential jacobian preconditioner.
Definition: preconditioners.hh:413
Helper class for applying the smoothers.
Definition: smoother.hh:369
const SmootherArgs getArgs() const
Definition: smoother.hh:201
static std::shared_ptr< ParSSOR< M, X, Y, C > > construct(Arguments &args)
Definition: smoother.hh:326
static void postSmooth(Smoother &smoother, Domain &v, Range &d)
Definition: smoother.hh:475
virtual ~DefaultConstructionArgs()
Definition: smoother.hh:180
void setArgs(const SmootherArgs &args)
Definition: smoother.hh:119
Smoother::domain_type Domain
Definition: smoother.hh:516
static void preSmooth(Smoother &smoother, Domain &v, const Range &d)
apply pre smoothing in forward direction
Definition: smoother.hh:382
int getN()
Definition: smoother.hh:293
Smoother::range_type Range
Definition: smoother.hh:466
void setN(int n)
Definition: smoother.hh:288
void setComm(const C &comm)
Definition: smoother.hh:158
Smoother::range_type Range
Definition: smoother.hh:447
int noSubdomains() const
Definition: smoother.hh:731
static void preSmooth(Smoother &smoother, Domain &v, Range &d)
Definition: smoother.hh:450
P::range_type range_type
The range type of the preconditioner.
Definition: novlpschwarz.hh:284
Smoother::range_type Range
Definition: smoother.hh:485
static std::shared_ptr< SeqJac< M, X, Y, l > > construct(Arguments &args)
Definition: smoother.hh:256
static std::shared_ptr< Richardson< X, Y > > construct(Arguments &args)
Definition: smoother.hh:271
Smoother::domain_type Domain
Definition: smoother.hh:448
Smoother::range_type Range
Definition: smoother.hh:515
ConstructionTraits< T > SeqConstructionTraits
Definition: smoother.hh:338
ConstructionArgs< SeqOverlappingSchwarz< M, X, TM, TS, TA > > Arguments
Definition: smoother.hh:855
AggregateAdder(Vector &subdomains_, const AggregatesMap &aggregates_, const MatrixGraph< const M > &graph_, VM &visitedMap_)
Definition: smoother.hh:704
DefaultSmootherArgs< typename X::field_type > Arguments
Definition: smoother.hh:74
void setArgs(const SmootherArgs &args)
Definition: smoother.hh:187
Definition: smoother.hh:556
The default class for the smoother arguments.
Definition: smoother.hh:37
Nonoverlapping parallel preconditioner.
Definition: novlpschwarz.hh:275
Smoother::domain_type Domain
Definition: smoother.hh:486
DefaultConstructionArgs< SeqSOR< M, X, Y, l > > Arguments
Definition: smoother.hh:238
DefaultConstructionArgs< SeqSSOR< M, X, Y, l > > Arguments
Definition: smoother.hh:222
Provides classes for the Coloring process of AMG.
FieldTraits< T >::real_type RelaxationFactor
The type of the relaxation factor.
Definition: smoother.hh:42
ConstructionArgs(int n=0)
Definition: smoother.hh:284
static void postSmooth(Smoother &smoother, Domain &v, Range &d)
Definition: smoother.hh:456
const C & getComm() const
Definition: smoother.hh:163
Smoother::range_type Range
Definition: smoother.hh:372
T Smoother
Definition: smoother.hh:371
Construction Arguments for the default smoothers.
Definition: smoother.hh:92
Vector::value_type Subdomain
Definition: smoother.hh:566
static std::shared_ptr< BlockPreconditioner< X, Y, C, T > > construct(Arguments &args)
Definition: smoother.hh:339
P::domain_type domain_type
The domain type of the preconditioner.
Definition: novlpschwarz.hh:282
void presmooth(LevelContext &levelContext, size_t steps)
Apply pre smoothing on the current level.
Definition: smoother.hh:406
SLList< VertexDescriptor, Allocator > VertexList
The type of a single linked list of vertex descriptors.
Definition: aggregates.hh:598
static const V ISOLATED
Identifier of isolated vertices.
Definition: aggregates.hh:577
void setComm([[maybe_unused]] T1 &comm)
Definition: smoother.hh:125
static std::shared_ptr< SeqSSOR< M, X, Y, l > > construct(Arguments &args)
Definition: smoother.hh:224
Overlap overlap
Definition: smoother.hh:540
Definition: smoother.hh:151
X domain_type
The domain type of the preconditioner.
Definition: schwarz.hh:285
void operator()(const T &edge)
Definition: smoother.hh:710
static void preSmooth(Smoother &smoother, Domain &v, Range &d)
Definition: smoother.hh:488
SeqOverlappingSchwarz< M, X, TM, TS, TA >::subdomain_vector Vector
Definition: smoother.hh:565
static void postSmooth(Smoother &smoother, Domain &v, const Range &d)
Definition: smoother.hh:524
Definition: allocator.hh:11
Class providing information about the mapping of the vertices onto aggregates.
Definition: aggregates.hh:565
virtual void setMatrix(const M &matrix, const AggregatesMap &amap)
Definition: smoother.hh:568
MatrixGraph< M >::VertexDescriptor VertexDescriptor
Definition: smoother.hh:562
const Matrix * matrix_
Definition: smoother.hh:139
NonoverlappingBlockPreconditioner< C, SeqSOR< M, X, Y, l > > Smoother
Definition: smoother.hh:484
virtual ~DefaultParallelConstructionArgs()
Definition: smoother.hh:155
X range_type
The range type of the preconditioner.
Definition: overlappingschwarz.hh:770
Definition: smoother.hh:538
AggregatesMap::AggregateDescriptor AggregateDescriptor
Definition: smoother.hh:564
A parallel SSOR preconditioner.
Definition: schwarz.hh:175
DefaultParallelConstructionArgs< M, C > Arguments
Definition: smoother.hh:324
SeqOverlappingSchwarz< M, X, MultiplicativeSchwarzMode, MS, TA > Smoother
Definition: smoother.hh:514
void operator()(const T &)
Definition: smoother.hh:689
const Vector & getSubDomains()
Definition: smoother.hh:653
Overlap
Definition: smoother.hh:538
const SmootherArgs getArgs() const
Definition: smoother.hh:133
DefaultSmootherArgs< typename T::matrix_type::field_type > Arguments
Definition: smoother.hh:67
void postsmooth(LevelContext &levelContext, size_t steps)
Apply post smoothing on the current level.
Definition: smoother.hh:428
V AggregateDescriptor
The aggregate descriptor type.
Definition: aggregates.hh:586