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_)
667 if(aggregates[edge.target()]!=AggregatesMap::ISOLATED)
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());
716 if(aggregates[edge.target()]!=AggregatesMap::ISOLATED) {
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& matrix,
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>>
Define general preconditioner interface.
Helper classes for the construction of classes without empty constructor.
Provides classes for the Coloring process of AMG.
DefaultSmootherArgs< typename X::field_type > Arguments
Definition smoother.hh:74
static void postSmooth(Smoother &smoother, Domain &v, Range &d)
Definition smoother.hh:494
void operator()(const T &edge)
Definition smoother.hh:689
static void preSmooth(Smoother &smoother, Domain &v, const Range &d)
Definition smoother.hh:518
static std::shared_ptr< SeqJac< M, X, Y, l > > construct(Arguments &args)
Definition smoother.hh:256
ConstructionArgs< SeqILU< M, X, Y > > Arguments
Definition smoother.hh:309
const Matrix & getMatrix() const
Definition smoother.hh:114
Smoother::range_type Range
Definition smoother.hh:515
int setAggregate(const AggregateDescriptor &aggregate_)
Definition smoother.hh:691
DefaultSmootherArgs< typename T::matrix_type::field_type > Arguments
Definition smoother.hh:67
int setAggregate(const AggregateDescriptor &aggregate_)
Definition smoother.hh:670
ConstructionTraits< T > SeqConstructionTraits
Definition smoother.hh:350
void setArgs(const SmootherArgs &args)
Definition smoother.hh:119
ConstructionArgs< SeqOverlappingSchwarz< M, X, TM, TS, TA > > Arguments
Definition smoother.hh:855
NonoverlappingBlockPreconditioner< C, SeqSOR< M, X, Y, l > > Smoother
Definition smoother.hh:484
static void postSmooth(Smoother &smoother, Domain &v, Range &d)
Definition smoother.hh:456
AggregateAdder(Vector &subdomains_, const AggregatesMap &aggregates_, const MatrixGraph< const M > &graph_, VM &visitedMap_)
Definition smoother.hh:704
Overlap
Definition smoother.hh:538
void setComm(const C &comm)
Definition smoother.hh:158
DefaultConstructionArgs< Richardson< X, Y > > Arguments
Definition smoother.hh:269
virtual ~DefaultConstructionArgs()
Definition smoother.hh:180
SeqOverlappingSchwarzSmootherArgs< typename M::field_type > Arguments
Definition smoother.hh:552
Vector::value_type Subdomain
Definition smoother.hh:566
static void preSmooth(Smoother &smoother, Domain &v, Range &d)
Definition smoother.hh:488
int getN()
Definition smoother.hh:293
Smoother::range_type Range
Definition smoother.hh:485
SeqSOR< M, X, Y, l > Smoother
Definition smoother.hh:446
void operator()(const T &edge)
Definition smoother.hh:710
static std::shared_ptr< SeqSSOR< M, X, Y, l > > construct(Arguments &args)
Definition smoother.hh:224
AggregatesMap::AggregateDescriptor AggregateDescriptor
Definition smoother.hh:564
bool onthefly
Definition smoother.hh:541
DefaultConstructionArgs< SeqSOR< M, X, Y, l > > Arguments
Definition smoother.hh:238
virtual void setMatrix(const M &matrix, const AggregatesMap &amap)
Definition smoother.hh:568
void setMatrix(const Args &...)
Definition smoother.hh:184
DefaultConstructionArgs< SeqJac< M, X, Y, l > > Arguments
Definition smoother.hh:254
DefaultConstructionArgs< SeqSSOR< M, X, Y, l > > Arguments
Definition smoother.hh:222
const SmootherArgs getArgs() const
Definition smoother.hh:133
VertexAdder(Vector &subdomains_, const AggregatesMap &aggregates_)
Definition smoother.hh:661
const Vector & getSubDomains()
Definition smoother.hh:653
SeqOverlappingSchwarz< M, X, TM, TS, TA >::subdomain_vector Vector
Definition smoother.hh:565
static std::shared_ptr< SeqOverlappingSchwarz< M, X, TM, TS, TA > > construct(Arguments &args)
Definition smoother.hh:857
static void preSmooth(Smoother &smoother, Domain &v, Range &d)
Definition smoother.hh:469
const_iterator begin() const
Definition aggregates.hh:725
void setMatrix(const Matrix &matrix)
Definition smoother.hh:104
T Smoother
Definition smoother.hh:371
static void preSmooth(Smoother &smoother, Domain &v, Range &d)
Definition smoother.hh:450
BlockPreconditioner< X, Y, C, SeqSOR< M, X, Y, l > > Smoother
Definition smoother.hh:465
void setComm(T1 &comm)
Definition smoother.hh:193
int noSubdomains() const
Definition smoother.hh:676
AggregateDescriptor * iterator
Definition aggregates.hh:735
void presmooth(LevelContext &levelContext, size_t steps)
Apply pre smoothing on the current level.
Definition smoother.hh:406
Smoother::domain_type Domain
Definition smoother.hh:516
SeqOverlappingSchwarzSmootherArgs(Overlap overlap_=vertex, bool onthefly_=false)
Definition smoother.hh:543
DefaultParallelConstructionArgs< T, C > Arguments
Definition smoother.hh:337
DefaultParallelConstructionArgs< T, C > Arguments
Definition smoother.hh:349
const Matrix * matrix_
Definition smoother.hh:139
const_iterator end() const
Definition aggregates.hh:730
const SequentialInformation & getComm()
Definition smoother.hh:128
V AggregateDescriptor
The aggregate descriptor type.
Definition aggregates.hh:580
static const V ISOLATED
Identifier of isolated vertices.
Definition aggregates.hh:571
DefaultSmootherArgs()
Default constructor.
Definition smoother.hh:56
void setMatrix(const M &matrix)
Definition smoother.hh:606
std::size_t noVertices() const
Get the number of vertices.
void operator()(const T &edge)
Definition smoother.hh:665
static void postSmooth(Smoother &smoother, Domain &v, const Range &d)
apply post smoothing in forward direction
Definition smoother.hh:394
FieldTraits< T >::real_type RelaxationFactor
The type of the relaxation factor.
Definition smoother.hh:42
Smoother::domain_type Domain
Definition smoother.hh:486
Smoother::domain_type Domain
Definition smoother.hh:373
void setN(int n)
Definition smoother.hh:288
static std::shared_ptr< BlockPreconditioner< X, Y, C, T > > construct(Arguments &args)
Definition smoother.hh:339
SLList< VertexDescriptor, Allocator > VertexList
The type of a single linked list of vertex descriptors.
Definition aggregates.hh:592
static std::shared_ptr< NonoverlappingBlockPreconditioner< C, T > > construct(Arguments &args)
Definition smoother.hh:351
SeqOverlappingSchwarz< M, X, MultiplicativeSchwarzMode, MS, TA > Smoother
Definition smoother.hh:514
static std::shared_ptr< ParSSOR< M, X, Y, C > > construct(Arguments &args)
Definition smoother.hh:326
MatrixGraph< M >::VertexDescriptor VertexDescriptor
Definition smoother.hh:562
static std::shared_ptr< SeqILU< M, X, Y > > construct(Arguments &args)
Definition smoother.hh:311
int noSubdomains() const
Definition smoother.hh:731
const SequentialInformation & getComm()
Definition smoother.hh:196
static std::shared_ptr< SeqSOR< M, X, Y, l > > construct(Arguments &args)
Definition smoother.hh:240
static std::shared_ptr< Richardson< X, Y > > construct(Arguments &args)
Definition smoother.hh:271
virtual void setMatrix(const Matrix &matrix, const AggregatesMap &amap)
Definition smoother.hh:108
int noSubdomains() const
Definition smoother.hh:695
void postsmooth(LevelContext &levelContext, size_t steps)
Apply post smoothing on the current level.
Definition smoother.hh:428
Dune::Amg::AggregatesMap< VertexDescriptor > AggregatesMap
Definition smoother.hh:563
const SmootherArgs getArgs() const
Definition smoother.hh:201
void setComm(T1 &comm)
Definition smoother.hh:125
static void postSmooth(Smoother &smoother, Domain &v, const Range &d)
Definition smoother.hh:524
DefaultParallelConstructionArgs< M, C > Arguments
Definition smoother.hh:324
RelaxationFactor relaxationFactor
The relaxation factor to use.
Definition smoother.hh:51
virtual ~DefaultParallelConstructionArgs()
Definition smoother.hh:155
Smoother::domain_type Domain
Definition smoother.hh:448
int setAggregate(const AggregateDescriptor &aggregate_)
Definition smoother.hh:725
Smoother::range_type Range
Definition smoother.hh:447
const C & getComm() const
Definition smoother.hh:163
virtual ~DefaultConstructionArgs()
Definition smoother.hh:101
static void preSmooth(Smoother &smoother, Domain &v, const Range &d)
apply pre smoothing in forward direction
Definition smoother.hh:382
static void postSmooth(Smoother &smoother, Domain &v, Range &d)
Definition smoother.hh:475
ConstructionTraits< T > SeqConstructionTraits
Definition smoother.hh:338
ConstructionArgs(int n=0)
Definition smoother.hh:284
Smoother::range_type Range
Definition smoother.hh:466
void setArgs(const SmootherArgs &args)
Definition smoother.hh:187
int iterations
The numbe of iterations to perform.
Definition smoother.hh:47
Smoother::range_type Range
Definition smoother.hh:372
Overlap overlap
Definition smoother.hh:540
Smoother::domain_type Domain
Definition smoother.hh:467
@ aggregate
Definition smoother.hh:538
@ none
Definition smoother.hh:538
@ pairwise
Definition smoother.hh:538
@ vertex
Definition smoother.hh:538
Definition allocator.hh:11
PropertyMapTypeSelector< Amg::VertexVisitedTag, Amg::PropertiesGraph< G, Amg::VertexProperties, EP, VM, EM > >::Type get(const Amg::VertexVisitedTag &tag, Amg::PropertiesGraph< G, Amg::VertexProperties, EP, VM, EM > &graph)
Definition dependency.hh:293
Sequential overlapping Schwarz preconditioner.
Definition overlappingschwarz.hh:755
X range_type
The range type of the preconditioner.
Definition overlappingschwarz.hh:770
X domain_type
The domain type of the preconditioner.
Definition overlappingschwarz.hh:765
std::vector< subdomain_type, typename std::allocator_traits< TA >::template rebind_alloc< subdomain_type > > subdomain_vector
The vector type containing the subdomain to row index mapping.
Definition overlappingschwarz.hh:797
Traits class for generically constructing non default constructable types.
Definition construction.hh:39
Nonoverlapping parallel preconditioner.
Definition novlpschwarz.hh:276
P::range_type range_type
The range type of the preconditioner.
Definition novlpschwarz.hh:284
P::domain_type domain_type
The domain type of the preconditioner.
Definition novlpschwarz.hh:282
Tag that tells the Schwarz method to be multiplicative.
Definition overlappingschwarz.hh:126
Class providing information about the mapping of the vertices onto aggregates.
Definition aggregates.hh:560
The (undirected) graph of a matrix.
Definition graph.hh:51
VertexIterator end()
Get an iterator over the vertices.
M::size_type VertexDescriptor
The vertex descriptor.
Definition graph.hh:73
VertexIterator begin()
Get an iterator over the vertices.
Iterator over all edges starting from a vertex.
Definition graph.hh:95
The vertex iterator type of the graph.
Definition graph.hh:209
The default class for the smoother arguments.
Definition smoother.hh:38
Traits class for getting the attribute class of a smoother.
Definition smoother.hh:66
Construction Arguments for the default smoothers.
Definition smoother.hh:93
Definition smoother.hh:148
Definition smoother.hh:153
Definition smoother.hh:174
Definition smoother.hh:282
Helper class for applying the smoothers.
Definition smoother.hh:370
Definition smoother.hh:537
Definition smoother.hh:558
Sequential SSOR preconditioner.
Definition preconditioners.hh:141
Sequential SOR preconditioner.
Definition preconditioners.hh:261
X domain_type
The domain type of the preconditioner.
Definition preconditioners.hh:266
Y range_type
The range type of the preconditioner.
Definition preconditioners.hh:268
The sequential jacobian preconditioner.
Definition preconditioners.hh:412
Sequential ILU preconditioner.
Definition preconditioners.hh:532
Richardson preconditioner.
Definition preconditioners.hh:713
A parallel SSOR preconditioner.
Definition schwarz.hh:175
Block parallel preconditioner.
Definition schwarz.hh:278
X domain_type
The domain type of the preconditioner.
Definition schwarz.hh:285
Y range_type
The range type of the preconditioner.
Definition schwarz.hh:290