Go to the documentation of this file.
3 #ifndef DUNE_AMGSMOOTHER_HH
4 #define DUNE_AMGSMOOTHER_HH
11 #include <dune/common/propertymap.hh>
12 #include <dune/common/unused.hh>
69 template<
class X,
class Y,
class C,
class T>
76 template<
class C,
class T>
89 typedef typename T::matrix_type Matrix;
105 DUNE_UNUSED_PARAMETER(amap);
123 DUNE_UNUSED_PARAMETER(comm);
148 template<
class T,
class C=SequentialInformation>
171 class ConstructionTraits;
176 template<
class M,
class X,
class Y,
int l>
198 template<
class M,
class X,
class Y,
int l>
218 template<
class M,
class X,
class Y,
int l>
240 template<
class M,
class X,
class Y>
258 template<
class M,
class X,
class Y>
284 template<
class M,
class X,
class Y>
303 template<
class M,
class X,
class Y>
330 template<
class M,
class X,
class Y>
351 template<
class M,
class X,
class Y,
class C>
368 template<
class X,
class Y,
class C,
class T>
381 SeqConstructionTraits::deconstruct(
static_cast<T*
>(&bp->preconditioner));
387 template<
class C,
class T>
400 SeqConstructionTraits::deconstruct(
static_cast<T*
>(&bp->preconditioner));
420 typedef typename Smoother::range_type
Range;
421 typedef typename Smoother::domain_type
Domain;
453 template<
typename LevelContext>
454 void presmooth(LevelContext& levelContext,
size_t steps)
456 for(std::size_t i=0; i < steps; ++i) {
459 ::preSmooth(*levelContext.smoother, *levelContext.lhs,
462 *levelContext.update += *levelContext.lhs;
465 levelContext.matrix->applyscaleadd(-1, *levelContext.lhs, *levelContext.rhs);
466 levelContext.pinfo->project(*levelContext.rhs);
475 template<
typename LevelContext>
478 for(std::size_t i=0; i < steps; ++i) {
480 levelContext.matrix->applyscaleadd(-1, *levelContext.lhs,
483 levelContext.pinfo->project(*levelContext.rhs);
485 ::postSmooth(*levelContext.smoother, *levelContext.lhs, *levelContext.rhs);
487 *levelContext.update += *levelContext.lhs;
491 template<
class M,
class X,
class Y,
int l>
500 smoother.template apply<true>(v,d);
506 smoother.template apply<false>(v,d);
510 template<
class M,
class X,
class Y,
class C,
int l>
519 smoother.template apply<true>(v,d);
525 smoother.template apply<false>(v,d);
529 template<
class M,
class X,
class Y,
class C,
int l>
538 smoother.template apply<true>(v,d);
544 smoother.template apply<false>(v,d);
551 template<
class M,
class X,
class MO,
class MS,
class A>
552 class SeqOverlappingSchwarz;
554 struct MultiplicativeSchwarzMode;
558 template<
class M,
class X,
class MS,
class TA>
568 smoother.template apply<true>(v,d);
574 smoother.template apply<false>(v,d);
592 bool onthefly_=
false)
597 template<
class M,
class X,
class TM,
class TS,
class TA>
603 template<
class M,
class X,
class TM,
class TS,
class TA>
618 Father::setMatrix(matrix);
620 std::vector<bool> visited(amap.
noVertices(),
false);
621 typedef IteratorPropertyMap<std::vector<bool>::iterator,IdentityMap> VisitedMapType;
622 VisitedMapType visitedMap(visited.begin());
628 switch(Father::getArgs().overlap) {
629 case SmootherArgs::vertex :
631 VertexAdder visitor(subdomains, amap);
632 createSubdomains(matrix, graph, amap, visitor, visitedMap);
635 case SmootherArgs::pairwise :
637 createPairDomains(graph);
640 case SmootherArgs::aggregate :
642 AggregateAdder<VisitedMapType> visitor(subdomains, amap, graph, visitedMap);
643 createSubdomains(matrix, graph, amap, visitor, visitedMap);
646 case SmootherArgs::none :
648 createSubdomains(matrix, graph, amap, visitor, visitedMap);
651 DUNE_THROW(NotImplemented,
"This overlapping scheme is not supported!");
656 Father::setMatrix(matrix);
662 iter!=amap.
end(); ++iter)
665 std::vector<bool> visited(amap.
noVertices(),
false);
666 typedef IteratorPropertyMap<std::vector<bool>::iterator,IdentityMap> VisitedMapType;
667 VisitedMapType visitedMap(visited.begin());
673 switch(Father::getArgs().overlap) {
674 case SmootherArgs::vertex :
676 VertexAdder visitor(subdomains, amap);
677 createSubdomains(matrix, graph, amap, visitor, visitedMap);
680 case SmootherArgs::aggregate :
682 DUNE_THROW(NotImplemented,
"Aggregate overlap is not supported yet");
689 case SmootherArgs::pairwise :
691 createPairDomains(graph);
694 case SmootherArgs::none :
696 createSubdomains(matrix, graph, amap, visitor, visitedMap);
710 : subdomains(subdomains_), max(-1), subdomain(-1), aggregates(aggregates_)
716 subdomains[subdomain].insert(edge.target());
720 subdomain=aggregate_;
721 max = std::max(subdomain, aggregate_);
750 struct AggregateAdder
754 : subdomains(subdomains_), subdomain(-1), aggregates(aggregates_),
755 adder(subdomains_, aggregates_), graph(graph_), visitedMap(visitedMap_)
760 subdomains[subdomain].insert(edge.target());
765 assert(aggregates[edge.target()]!=aggregate);
767 aggregates.template breadthFirstSearch<true,false>(edge.target(), aggregate,
768 graph, vlist, adder, adder,
775 adder.setAggregate(aggregate_);
776 aggregate=aggregate_;
798 typedef typename M::size_type size_type;
800 std::set<std::pair<size_type,size_type> > pairs;
802 for(VIter v=graph.
begin(), ve=graph.
end(); ve != v; ++v)
803 for(EIter e = v.begin(), ee=v.end(); ee!=e; ++e)
806 if(e.source()<e.target())
807 pairs.insert(std::make_pair(e.source(),e.target()));
809 pairs.insert(std::make_pair(e.target(),e.source()));
813 subdomains.resize(pairs.size());
814 Dune::dinfo <<std::endl<<
"Created "<<pairs.size()<<
" ("<<total<<
") pair domains"<<std::endl<<std::endl;
815 typedef typename std::set<std::pair<size_type,size_type> >::const_iterator SIter;
816 typename Vector::iterator subdomain=subdomains.begin();
818 for(SIter s=pairs.begin(), se =pairs.end(); se!=s; ++s)
820 subdomain->insert(s->first);
821 subdomain->insert(s->second);
824 std::size_t minsize=10000;
825 std::size_t maxsize=0;
827 for(
typename Vector::size_type i=0; i < subdomains.size(); ++i) {
828 sum+=subdomains[i].size();
829 minsize=std::min(minsize, subdomains[i].size());
830 maxsize=std::max(maxsize, subdomains[i].size());
832 Dune::dinfo<<
"Subdomain size: min="<<minsize<<
" max="<<maxsize<<
" avg="<<(sum/subdomains.size())
833 <<
" no="<<subdomains.size()<<std::endl;
836 template<
class Visitor>
837 void createSubdomains(
const M& matrix,
const MatrixGraph<const M>& graph,
838 const AggregatesMap& amap, Visitor& overlapVisitor,
839 IteratorPropertyMap<std::vector<bool>::iterator,IdentityMap>& visitedMap )
846 AggregateDescriptor maxAggregate=0;
848 for(std::size_t i=0; i < amap.noVertices(); ++i)
852 maxAggregate = std::max(maxAggregate, amap[i]);
854 subdomains.resize(maxAggregate+1+isolated);
857 for(
typename Vector::size_type i=0; i < subdomains.size(); ++i)
858 subdomains[i].clear();
863 VertexAdder aggregateVisitor(subdomains, amap);
865 for(VertexDescriptor i=0; i < amap.noVertices(); ++i)
866 if(!
get(visitedMap, i)) {
867 AggregateDescriptor aggregate=amap[i];
871 subdomains.push_back(Subdomain());
872 aggregate=subdomains.size()-1;
874 overlapVisitor.setAggregate(aggregate);
875 aggregateVisitor.setAggregate(aggregate);
876 subdomains[aggregate].insert(i);
878 amap.template breadthFirstSearch<false,false>(i, aggregate, graph, vlist, aggregateVisitor,
879 overlapVisitor, visitedMap);
882 std::size_t minsize=10000;
883 std::size_t maxsize=0;
885 for(
typename Vector::size_type i=0; i < subdomains.size(); ++i) {
886 sum+=subdomains[i].size();
887 minsize=std::min(minsize, subdomains[i].size());
888 maxsize=std::max(maxsize, subdomains[i].size());
890 Dune::dinfo<<
"Subdomain size: min="<<minsize<<
" max="<<maxsize<<
" avg="<<(sum/subdomains.size())
891 <<
" no="<<subdomains.size()<<
" isolated="<<isolated<<std::endl;
900 template<
class M,
class X,
class TM,
class TS,
class TA>
const Vector & getSubDomains()
Definition: smoother.hh:701
DefaultParallelConstructionArgs< T, C > Arguments
Definition: smoother.hh:371
Helper classes for the construction of classes without empty constructor.
void operator()(const T &edge)
Definition: smoother.hh:758
DefaultConstructionArgs< SeqILU0< M, X, Y > > Arguments
Definition: smoother.hh:243
static ParSSOR< M, X, Y, C > * construct(Arguments &args)
Definition: smoother.hh:356
DefaultConstructionArgs< SeqSSOR< M, X, Y, l > > Arguments
Definition: smoother.hh:179
DefaultParallelConstructionArgs< T, C > Arguments
Definition: smoother.hh:390
int setAggregate(const AggregateDescriptor &aggregate_)
Definition: smoother.hh:739
void operator()(const T &edge)
Definition: smoother.hh:737
Class providing information about the mapping of the vertices onto aggregates.
Definition: aggregates.hh:542
Nonoverlapping parallel preconditioner.
Definition: novlpschwarz.hh:265
@ pairwise
Definition: smoother.hh:586
SeqOverlappingSchwarzSmootherArgs< typename M::field_type > Arguments
Definition: smoother.hh:600
Traits class for getting the attribute class of a smoother.
Definition: smoother.hh:63
ConstructionArgs(int n=1)
Definition: smoother.hh:263
Smoother::range_type Range
Definition: smoother.hh:420
const SequentialInformation & getComm()
Definition: smoother.hh:126
T Smoother
Definition: smoother.hh:419
X domain_type
The domain type of the preconditioner.
Definition: schwarz.hh:276
int setAggregate(const AggregateDescriptor &aggregate_)
Definition: smoother.hh:718
VertexAdder(Vector &subdomains_, const AggregatesMap &aggregates_)
Definition: smoother.hh:709
void setMatrix(const M &matrix)
Definition: smoother.hh:654
DefaultSmootherArgs()
Default constructor.
Definition: smoother.hh:54
int iterations
The numbe of iterations to perform.
Definition: smoother.hh:45
static SeqILU< M, X, Y > * construct(Arguments &args)
Definition: smoother.hh:335
ConstructionTraits< T > SeqConstructionTraits
Definition: smoother.hh:391
Sequential ILU(n) preconditioner.
Definition: preconditioners.hh:739
const_iterator begin() const
Definition: aggregates.hh:712
P::domain_type domain_type
The domain type of the preconditioner.
Definition: novlpschwarz.hh:270
DefaultConstructionArgs< SeqJac< M, X, Y, l > > Arguments
Definition: smoother.hh:221
AggregateDescriptor * iterator
Definition: aggregates.hh:722
std::size_t noVertices() const
Get the number of vertices.
BlockPreconditioner< X, Y, C, SeqSOR< M, X, Y, l > > Smoother
Definition: smoother.hh:513
V AggregateDescriptor
The aggregate descriptor type.
Definition: aggregates.hh:563
Traits class for generically constructing non default constructable types.
Definition: novlpschwarz.hh:247
static void preSmooth(Smoother &smoother, Domain &v, const Range &d)
Definition: smoother.hh:566
SeqOverlappingSchwarzSmootherArgs(Overlap overlap_=vertex, bool onthefly_=false)
Definition: smoother.hh:591
static NonoverlappingBlockPreconditioner< C, T > * construct(Arguments &args)
Definition: smoother.hh:392
int setAggregate(const AggregateDescriptor &aggregate_)
Definition: smoother.hh:773
A parallel SSOR preconditioner.
Definition: schwarz.hh:166
Definition: smoother.hh:144
static BlockPreconditioner< X, Y, C, T > * construct(Arguments &args)
Definition: smoother.hh:373
ConstructionArgs(int n=0)
Definition: smoother.hh:308
static void postSmooth(Smoother &smoother, Domain &v, Range &d)
Definition: smoother.hh:523
VertexIterator begin()
Get an iterator over the vertices.
Smoother::domain_type Domain
Definition: smoother.hh:421
static SeqOverlappingSchwarz< M, X, TM, TS, TA > * construct(Arguments &args)
Definition: smoother.hh:905
static void preSmooth(Smoother &smoother, Domain &v, Range &d)
Definition: smoother.hh:517
P::range_type range_type
The range type of the preconditioner.
Definition: novlpschwarz.hh:272
static void deconstruct(SeqJac< M, X, Y, l > *jac)
Definition: smoother.hh:229
VertexIterator end()
Get an iterator over the vertices.
Overlap
Definition: smoother.hh:586
@ none
Definition: smoother.hh:586
Definition: smoother.hh:604
The default class for the smoother arguments.
Definition: smoother.hh:35
void setComm(T1 &comm)
Definition: smoother.hh:121
void setN(int n)
Definition: smoother.hh:267
static void preSmooth(Smoother &smoother, Domain &v, Range &d)
Definition: smoother.hh:498
static void deconstruct(SeqOverlappingSchwarz< M, X, TM, TS, TA > *schwarz)
Definition: smoother.hh:913
DefaultConstructionArgs< SeqSOR< M, X, Y, l > > Arguments
Definition: smoother.hh:201
void setMatrix(const Matrix &matrix)
Definition: smoother.hh:99
Smoother::range_type Range
Definition: smoother.hh:563
ConstructionTraits< T > SeqConstructionTraits
Definition: smoother.hh:372
Construction Arguments for the default smoothers.
Definition: smoother.hh:87
int noSubdomains() const
Definition: smoother.hh:724
static SeqILU0< M, X, Y > * construct(Arguments &args)
Definition: smoother.hh:245
Definition: smoother.hh:583
static SeqILUn< M, X, Y > * construct(Arguments &args)
Definition: smoother.hh:289
X range_type
The range type of the preconditioner.
Definition: overlappingschwarz.hh:757
T RelaxationFactor
The type of the relaxation factor.
Definition: smoother.hh:40
static void preSmooth(Smoother &smoother, Domain &v, Range &d)
Definition: smoother.hh:536
static void postSmooth(Smoother &smoother, Domain &v, const Range &d)
Definition: smoother.hh:572
void presmooth(LevelContext &levelContext, size_t steps)
Apply pre smoothing on the current level.
Definition: smoother.hh:454
void setN(int n)
Definition: smoother.hh:312
Define general preconditioner interface.
virtual ~DefaultConstructionArgs()
Definition: smoother.hh:96
int noSubdomains() const
Definition: smoother.hh:779
Y range_type
The range type of the preconditioner.
Definition: schwarz.hh:281
static void postSmooth(Smoother &smoother, Domain &v, Range &d)
Definition: smoother.hh:504
M::size_type VertexDescriptor
The vertex descriptor.
Definition: graph.hh:71
void operator()(const T &edge)
Definition: smoother.hh:713
int getN()
Definition: smoother.hh:271
Sequential overlapping Schwarz preconditioner.
Definition: colcompmatrix.hh:157
static SeqSSOR< M, X, Y, l > * construct(Arguments &args)
Definition: smoother.hh:181
Tag that tells the Schwarz method to be multiplicative.
Definition: overlappingschwarz.hh:121
DefaultParallelConstructionArgs< M, C > Arguments
Definition: smoother.hh:354
SeqOverlappingSchwarz< M, X, MultiplicativeSchwarzMode, MS, TA > Smoother
Definition: smoother.hh:562
Sequential SOR preconditioner.
Definition: preconditioners.hh:225
void setComm(const C &comm)
Definition: smoother.hh:156
static SeqSOR< M, X, Y, l > * construct(Arguments &args)
Definition: smoother.hh:203
X domain_type
The domain type of the preconditioner.
Definition: preconditioners.hh:230
RelaxationFactor relaxationFactor
The relaxation factor to use.
Definition: smoother.hh:49
SeqOverlappingSchwarz< M, X, TM, TS, TA >::subdomain_vector Vector
Definition: smoother.hh:613
ConstructionArgs< SeqILU< M, X, Y > > Arguments
Definition: smoother.hh:333
Smoother::domain_type Domain
Definition: smoother.hh:496
bool onthefly
Definition: smoother.hh:589
ConstructionArgs< SeqOverlappingSchwarz< M, X, TM, TS, TA > > Arguments
Definition: smoother.hh:903
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:292
AggregateAdder(Vector &subdomains_, const AggregatesMap &aggregates_, const MatrixGraph< const M > &graph_, VM &visitedMap_)
Definition: smoother.hh:752
DefaultSmootherArgs< typename T::matrix_type::field_type > Arguments
Definition: smoother.hh:72
static void postSmooth(Smoother &smoother, Domain &v, Range &d)
Definition: smoother.hh:542
Overlap overlap
Definition: smoother.hh:588
const_iterator end() const
Definition: aggregates.hh:717
Definition: smoother.hh:259
const C & getComm() const
Definition: smoother.hh:161
const Matrix * matrix_
Definition: smoother.hh:137
static void deconstruct(NonoverlappingBlockPreconditioner< C, T > *bp)
Definition: smoother.hh:398
static void deconstruct(SeqILUn< M, X, Y > *ilu)
Definition: smoother.hh:295
Dune::Amg::AggregatesMap< VertexDescriptor > AggregatesMap
Definition: smoother.hh:611
Vector::value_type Subdomain
Definition: smoother.hh:614
int getN()
Definition: smoother.hh:317
const SmootherArgs getArgs() const
Definition: smoother.hh:131
DefaultSmootherArgs< typename T::matrix_type::field_type > Arguments
Definition: smoother.hh:65
static SeqJac< M, X, Y, l > * construct(Arguments &args)
Definition: smoother.hh:223
static void deconstruct(SeqILU< M, X, Y > *ilu)
Definition: smoother.hh:341
virtual void setMatrix(const M &matrix, const AggregatesMap &amap)
Definition: smoother.hh:616
Smoother::range_type Range
Definition: smoother.hh:495
static void deconstruct(BlockPreconditioner< X, Y, C, T > *bp)
Definition: smoother.hh:379
NonoverlappingBlockPreconditioner< C, SeqSOR< M, X, Y, l > > Smoother
Definition: smoother.hh:532
DefaultSmootherArgs< typename T::matrix_type::field_type > Arguments
Definition: smoother.hh:79
Sequential ILU0 preconditioner.
Definition: preconditioners.hh:652
static const V ISOLATED
Identifier of isolated vertices.
Definition: aggregates.hh:554
Definition: allocator.hh:7
static void preSmooth(Smoother &smoother, Domain &v, const Range &d)
apply pre smoothing in forward direction
Definition: smoother.hh:430
X domain_type
The domain type of the preconditioner.
Definition: overlappingschwarz.hh:752
int noSubdomains() const
Definition: smoother.hh:743
void postsmooth(LevelContext &levelContext, size_t steps)
Apply post smoothing on the current level.
Definition: smoother.hh:476
Smoother::domain_type Domain
Definition: smoother.hh:534
Smoother::range_type Range
Definition: smoother.hh:533
@ aggregate
Definition: smoother.hh:586
The sequential jacobian preconditioner.
Definition: preconditioners.hh:416
Helper class for applying the smoothers.
Definition: smoother.hh:417
static void deconstruct(SeqILU0< M, X, Y > *ilu)
Definition: smoother.hh:251
virtual void setMatrix(const Matrix &matrix, const AggregatesMap &amap)
Definition: smoother.hh:103
ConstructionArgs< SeqILUn< M, X, Y > > Arguments
Definition: smoother.hh:287
Sequential SSOR preconditioner.
Definition: preconditioners.hh:135
static void deconstruct(ParSSOR< M, X, Y, C > *ssor)
Definition: smoother.hh:362
MatrixGraph< M >::VertexDescriptor VertexDescriptor
Definition: smoother.hh:610
Y range_type
The range type of the preconditioner.
Definition: preconditioners.hh:232
virtual ~DefaultParallelConstructionArgs()
Definition: smoother.hh:153
Sequential ILU preconditioner.
Definition: preconditioners.hh:504
void setArgs(const SmootherArgs &args)
Definition: smoother.hh:115
Smoother::domain_type Domain
Definition: smoother.hh:564
const Matrix & getMatrix() const
Definition: smoother.hh:110
Smoother::domain_type Domain
Definition: smoother.hh:515
@ vertex
Definition: smoother.hh:586
Smoother::range_type Range
Definition: smoother.hh:514
static void postSmooth(Smoother &smoother, Domain &v, const Range &d)
apply post smoothing in forward direction
Definition: smoother.hh:442
SLList< VertexDescriptor, Allocator > VertexList
The type of a single linked list of vertex descriptors.
Definition: aggregates.hh:575
Definition: smoother.hh:304
static void deconstruct(SeqSSOR< M, X, Y, l > *ssor)
Definition: smoother.hh:187
SeqSOR< M, X, Y, l > Smoother
Definition: smoother.hh:494
Provides classes for the Coloring process of AMG.
AggregatesMap::AggregateDescriptor AggregateDescriptor
Definition: smoother.hh:612
static void deconstruct(SeqSOR< M, X, Y, l > *sor)
Definition: smoother.hh:209
Block parallel preconditioner.
Definition: schwarz.hh:269
Definition: smoother.hh:149