3 #ifndef DUNE_AMGSMOOTHER_HH 4 #define DUNE_AMGSMOOTHER_HH 11 #include <dune/common/propertymap.hh> 12 #include <dune/common/unused.hh> 55 : iterations(1), relaxationFactor(1.0)
69 template<
class X,
class Y,
class C,
class T>
76 template<
class C,
class T>
89 typedef typename T::matrix_type Matrix;
103 virtual void setMatrix(
const Matrix& matrix,
const AggregatesMap& amap)
105 DUNE_UNUSED_PARAMETER(amap);
123 DUNE_UNUSED_PARAMETER(comm);
139 const SmootherArgs* args_;
148 template<
class T,
class C=SequentialInformation>
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;
430 static void preSmooth(Smoother& smoother, Domain& v,
const Range& d)
442 static void postSmooth(Smoother& smoother, Domain& v,
const Range& d)
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>
498 static void preSmooth(Smoother& smoother, Domain& v, Range& d)
500 smoother.template apply<true>(v,d);
504 static void postSmooth(Smoother& smoother, Domain& v, Range& d)
506 smoother.template apply<false>(v,d);
510 template<
class M,
class X,
class Y,
class C,
int l>
517 static void preSmooth(Smoother& smoother, Domain& v, Range& d)
519 smoother.template apply<true>(v,d);
523 static void postSmooth(Smoother& smoother, Domain& v, Range& d)
525 smoother.template apply<false>(v,d);
529 template<
class M,
class X,
class Y,
class C,
int l>
536 static void preSmooth(Smoother& smoother, Domain& v, Range& d)
538 smoother.template apply<true>(v,d);
542 static void postSmooth(Smoother& smoother, Domain& v, Range& d)
544 smoother.template apply<false>(v,d);
551 template<
class M,
class X,
class MO,
class MS,
class A>
558 template<
class M,
class X,
class MS,
class TA>
566 static void preSmooth(Smoother& smoother, Domain& v,
const Range& d)
568 smoother.template apply<true>(v,d);
572 static void postSmooth(Smoother& smoother, Domain& v,
const Range& d)
574 smoother.template apply<false>(v,d);
592 bool onthefly_=
false)
593 : overlap(overlap_), onthefly(onthefly_)
597 template<
class M,
class X,
class TM,
class TS,
class TA>
603 template<
class M,
class X,
class TM,
class TS,
class TA>
616 virtual void setMatrix(
const M& matrix,
const AggregatesMap& amap)
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);
659 AggregatesMap amap(matrix.N());
660 VertexDescriptor v=0;
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);
709 VertexAdder(Vector& subdomains_,
const AggregatesMap& aggregates_)
710 : subdomains(subdomains_), max(-1), subdomain(-1), aggregates(aggregates_)
716 subdomains[subdomain].insert(edge.target());
720 subdomain=aggregate_;
721 max = std::max(subdomain, aggregate_);
730 AggregateDescriptor max;
731 AggregateDescriptor subdomain;
732 const AggregatesMap& aggregates;
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_;
785 AggregateDescriptor aggregate;
788 const AggregatesMap& aggregates;
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>
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>
static void deconstruct(SeqSOR< M, X, Y, l > *sor)
Definition: smoother.hh:209
Sequential SSOR preconditioner.
Definition: preconditioners.hh:135
AggregateDescriptor * iterator
Definition: aggregates.hh:722
SLList< VertexDescriptor, Allocator > VertexList
The type of a single linked list of vertex descriptors.
Definition: aggregates.hh:575
const Vector & getSubDomains()
Definition: smoother.hh:701
void postsmooth(LevelContext &levelContext, size_t steps)
Apply post smoothing on the current level.
Definition: smoother.hh:476
BlockPreconditioner< X, Y, C, SeqSOR< M, X, Y, l > > Smoother
Definition: smoother.hh:513
Smoother::range_type Range
Definition: smoother.hh:533
static void deconstruct(SeqILU0< M, X, Y > *ilu)
Definition: smoother.hh:251
ConstructionArgs(int n=1)
Definition: smoother.hh:263
DefaultParallelConstructionArgs< T, C > Arguments
Definition: smoother.hh:390
int iterations
The numbe of iterations to perform.
Definition: smoother.hh:45
Definition: smoother.hh:586
Definition: allocator.hh:7
Helper class for applying the smoothers.
Definition: smoother.hh:417
AggregatesMap::AggregateDescriptor AggregateDescriptor
Definition: smoother.hh:612
DefaultParallelConstructionArgs< T, C > Arguments
Definition: smoother.hh:371
std::size_t noVertices() const
Get the number of vertices.
static void deconstruct(SeqJac< M, X, Y, l > *jac)
Definition: smoother.hh:229
Helper classes for the construction of classes without empty constructor.
Overlap
Definition: smoother.hh:586
Traits class for generically constructing non default constructable types.
Definition: novlpschwarz.hh:247
DefaultConstructionArgs< SeqILU0< M, X, Y > > Arguments
Definition: smoother.hh:243
SeqOverlappingSchwarzSmootherArgs< typename M::field_type > Arguments
Definition: smoother.hh:600
static void deconstruct(SeqSSOR< M, X, Y, l > *ssor)
Definition: smoother.hh:187
void setMatrix(const M &matrix)
Definition: smoother.hh:654
Definition: smoother.hh:583
T Smoother
Definition: smoother.hh:419
Sequential ILU preconditioner.
Definition: preconditioners.hh:504
static BlockPreconditioner< X, Y, C, T > * construct(Arguments &args)
Definition: smoother.hh:373
M::size_type VertexDescriptor
The vertex descriptor.
Definition: graph.hh:71
static SeqILUn< M, X, Y > * construct(Arguments &args)
Definition: smoother.hh:289
VertexAdder(Vector &subdomains_, const AggregatesMap &aggregates_)
Definition: smoother.hh:709
SeqOverlappingSchwarzSmootherArgs(Overlap overlap_=vertex, bool onthefly_=false)
Definition: smoother.hh:591
DefaultConstructionArgs< SeqJac< M, X, Y, l > > Arguments
Definition: smoother.hh:221
void operator()(const T &edge)
Definition: smoother.hh:737
The default class for the smoother arguments.
Definition: smoother.hh:35
X domain_type
The domain type of the preconditioner.
Definition: preconditioners.hh:230
VertexIterator end()
Get an iterator over the vertices.
const SequentialInformation & getComm()
Definition: smoother.hh:126
static void postSmooth(Smoother &smoother, Domain &v, Range &d)
Definition: smoother.hh:523
ConstructionTraits< T > SeqConstructionTraits
Definition: smoother.hh:372
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, const Range &d)
Definition: smoother.hh:566
static void deconstruct(SeqOverlappingSchwarz< M, X, TM, TS, TA > *schwarz)
Definition: smoother.hh:913
static NonoverlappingBlockPreconditioner< C, T > * construct(Arguments &args)
Definition: smoother.hh:392
Definition: smoother.hh:144
static SeqILU< M, X, Y > * construct(Arguments &args)
Definition: smoother.hh:335
ConstructionTraits< T > SeqConstructionTraits
Definition: smoother.hh:391
DefaultConstructionArgs< SeqSOR< M, X, Y, l > > Arguments
Definition: smoother.hh:201
void setMatrix(const Matrix &matrix)
Definition: smoother.hh:99
X domain_type
The domain type of the preconditioner.
Definition: schwarz.hh:276
static void preSmooth(Smoother &smoother, Domain &v, Range &d)
Definition: smoother.hh:498
void operator()(const T &edge)
Definition: smoother.hh:713
int getN()
Definition: smoother.hh:271
Define general preconditioner interface.
virtual ~DefaultConstructionArgs()
Definition: smoother.hh:96
const C & getComm() const
Definition: smoother.hh:161
const Matrix * matrix_
Definition: smoother.hh:137
X domain_type
The domain type of the preconditioner.
Definition: overlappingschwarz.hh:752
V AggregateDescriptor
The aggregate descriptor type.
Definition: aggregates.hh:563
void presmooth(LevelContext &levelContext, size_t steps)
Apply pre smoothing on the current level.
Definition: smoother.hh:454
Block parallel preconditioner.
Definition: schwarz.hh:269
static void deconstruct(NonoverlappingBlockPreconditioner< C, T > *bp)
Definition: smoother.hh:398
Sequential overlapping Schwarz preconditioner.
Definition: colcompmatrix.hh:157
Sequential ILU(n) preconditioner.
Definition: preconditioners.hh:739
int setAggregate(const AggregateDescriptor &aggregate_)
Definition: smoother.hh:773
The sequential jacobian preconditioner.
Definition: preconditioners.hh:416
int noSubdomains() const
Definition: smoother.hh:724
int noSubdomains() const
Definition: smoother.hh:779
void setN(int n)
Definition: smoother.hh:267
P::domain_type domain_type
The domain type of the preconditioner.
Definition: novlpschwarz.hh:270
static void deconstruct(SeqILU< M, X, Y > *ilu)
Definition: smoother.hh:341
ConstructionArgs(int n=0)
Definition: smoother.hh:308
Smoother::range_type Range
Definition: smoother.hh:495
VertexIterator begin()
Get an iterator over the vertices.
Smoother::range_type Range
Definition: smoother.hh:563
T RelaxationFactor
The type of the relaxation factor.
Definition: smoother.hh:40
Smoother::domain_type Domain
Definition: smoother.hh:496
Class providing information about the mapping of the vertices onto aggregates.
Definition: aggregates.hh:542
static SeqILU0< M, X, Y > * construct(Arguments &args)
Definition: smoother.hh:245
static void preSmooth(Smoother &smoother, Domain &v, Range &d)
Definition: smoother.hh:517
Nonoverlapping parallel preconditioner.
Definition: novlpschwarz.hh:265
void setN(int n)
Definition: smoother.hh:312
Vector::value_type Subdomain
Definition: smoother.hh:614
Overlap overlap
Definition: smoother.hh:588
SeqOverlappingSchwarz< M, X, TM, TS, TA >::subdomain_vector Vector
Definition: smoother.hh:613
int getN()
Definition: smoother.hh:317
void setComm(T1 &comm)
Definition: smoother.hh:121
Y range_type
The range type of the preconditioner.
Definition: schwarz.hh:281
static void deconstruct(SeqILUn< M, X, Y > *ilu)
Definition: smoother.hh:295
Sequential ILU0 preconditioner.
Definition: preconditioners.hh:652
virtual void setMatrix(const Matrix &matrix, const AggregatesMap &amap)
Definition: smoother.hh:103
static SeqJac< M, X, Y, l > * construct(Arguments &args)
Definition: smoother.hh:223
static void postSmooth(Smoother &smoother, Domain &v, Range &d)
Definition: smoother.hh:504
static const V ISOLATED
Identifier of isolated vertices.
Definition: aggregates.hh:554
AggregateAdder(Vector &subdomains_, const AggregatesMap &aggregates_, const MatrixGraph< const M > &graph_, VM &visitedMap_)
Definition: smoother.hh:752
P::range_type range_type
The range type of the preconditioner.
Definition: novlpschwarz.hh:272
SeqOverlappingSchwarz< M, X, MultiplicativeSchwarzMode, MS, TA > Smoother
Definition: smoother.hh:562
static void deconstruct(BlockPreconditioner< X, Y, C, T > *bp)
Definition: smoother.hh:379
virtual ~DefaultParallelConstructionArgs()
Definition: smoother.hh:153
Construction Arguments for the default smoothers.
Definition: smoother.hh:87
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
Smoother::domain_type Domain
Definition: smoother.hh:564
Traits class for getting the attribute class of a smoother.
Definition: smoother.hh:63
Smoother::domain_type Domain
Definition: smoother.hh:534
Dune::Amg::AggregatesMap< VertexDescriptor > AggregatesMap
Definition: smoother.hh:611
RelaxationFactor relaxationFactor
The relaxation factor to use.
Definition: smoother.hh:49
bool onthefly
Definition: smoother.hh:589
ConstructionArgs< SeqOverlappingSchwarz< M, X, TM, TS, TA > > Arguments
Definition: smoother.hh:903
static SeqSSOR< M, X, Y, l > * construct(Arguments &args)
Definition: smoother.hh:181
DefaultSmootherArgs< typename T::matrix_type::field_type > Arguments
Definition: smoother.hh:72
DefaultParallelConstructionArgs< M, C > Arguments
Definition: smoother.hh:354
A parallel SSOR preconditioner.
Definition: schwarz.hh:166
static void postSmooth(Smoother &smoother, Domain &v, Range &d)
Definition: smoother.hh:542
Tag that tells the Schwarz method to be multiplicative.
Definition: overlappingschwarz.hh:121
X range_type
The range type of the preconditioner.
Definition: overlappingschwarz.hh:757
Definition: smoother.hh:149
const SmootherArgs getArgs() const
Definition: smoother.hh:131
static void preSmooth(Smoother &smoother, Domain &v, const Range &d)
apply pre smoothing in forward direction
Definition: smoother.hh:430
void setComm(const C &comm)
Definition: smoother.hh:156
DefaultSmootherArgs< typename T::matrix_type::field_type > Arguments
Definition: smoother.hh:65
Smoother::range_type Range
Definition: smoother.hh:514
static SeqSOR< M, X, Y, l > * construct(Arguments &args)
Definition: smoother.hh:203
Smoother::domain_type Domain
Definition: smoother.hh:515
ConstructionArgs< SeqILU< M, X, Y > > Arguments
Definition: smoother.hh:333
Provides classes for the Coloring process of AMG.
MatrixGraph< M >::VertexDescriptor VertexDescriptor
Definition: smoother.hh:610
Sequential SOR preconditioner.
Definition: preconditioners.hh:225
DefaultSmootherArgs< typename T::matrix_type::field_type > Arguments
Definition: smoother.hh:79
int noSubdomains() const
Definition: smoother.hh:743
const Matrix & getMatrix() const
Definition: smoother.hh:110
Y range_type
The range type of the preconditioner.
Definition: preconditioners.hh:232
void operator()(const T &edge)
Definition: smoother.hh:758
int setAggregate(const AggregateDescriptor &aggregate_)
Definition: smoother.hh:718
ConstructionArgs< SeqILUn< M, X, Y > > Arguments
Definition: smoother.hh:287
static void deconstruct(ParSSOR< M, X, Y, C > *ssor)
Definition: smoother.hh:362
SeqSOR< M, X, Y, l > Smoother
Definition: smoother.hh:494
static ParSSOR< M, X, Y, C > * construct(Arguments &args)
Definition: smoother.hh:356
DefaultConstructionArgs< SeqSSOR< M, X, Y, l > > Arguments
Definition: smoother.hh:179
DefaultSmootherArgs()
Default constructor.
Definition: smoother.hh:54
static void postSmooth(Smoother &smoother, Domain &v, const Range &d)
apply post smoothing in forward direction
Definition: smoother.hh:442
virtual void setMatrix(const M &matrix, const AggregatesMap &amap)
Definition: smoother.hh:616
NonoverlappingBlockPreconditioner< C, SeqSOR< M, X, Y, l > > Smoother
Definition: smoother.hh:532
void setArgs(const SmootherArgs &args)
Definition: smoother.hh:115
int setAggregate(const AggregateDescriptor &aggregate_)
Definition: smoother.hh:739
Smoother::range_type Range
Definition: smoother.hh:420