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>
305 template<
class M,
class X,
class Y,
class C>
322 template<
class X,
class Y,
class C,
class T>
335 SeqConstructionTraits::deconstruct(static_cast<T*>(&bp->preconditioner));
341 template<
class C,
class T>
354 SeqConstructionTraits::deconstruct(static_cast<T*>(&bp->preconditioner));
374 typedef typename Smoother::range_type
Range;
375 typedef typename Smoother::domain_type
Domain;
407 template<
typename LevelContext>
408 void presmooth(LevelContext& levelContext,
size_t steps)
410 for(std::size_t i=0; i < steps; ++i) {
413 ::preSmooth(*levelContext.smoother, *levelContext.lhs,
416 *levelContext.update += *levelContext.lhs;
419 levelContext.matrix->applyscaleadd(-1, *levelContext.lhs, *levelContext.rhs);
420 levelContext.pinfo->project(*levelContext.rhs);
429 template<
typename LevelContext>
432 for(std::size_t i=0; i < steps; ++i) {
434 levelContext.matrix->applyscaleadd(-1, *levelContext.lhs,
437 levelContext.pinfo->project(*levelContext.rhs);
439 ::postSmooth(*levelContext.smoother, *levelContext.lhs, *levelContext.rhs);
441 *levelContext.update += *levelContext.lhs;
445 template<
class M,
class X,
class Y,
int l>
454 smoother.template apply<true>(v,d);
460 smoother.template apply<false>(v,d);
464 template<
class M,
class X,
class Y,
class C,
int l>
473 smoother.template apply<true>(v,d);
479 smoother.template apply<false>(v,d);
483 template<
class M,
class X,
class Y,
class C,
int l>
492 smoother.template apply<true>(v,d);
498 smoother.template apply<false>(v,d);
505 template<
class M,
class X,
class MO,
class MS,
class A>
506 class SeqOverlappingSchwarz;
508 struct MultiplicativeSchwarzMode;
512 template<
class M,
class X,
class MS,
class TA>
522 smoother.template apply<true>(v,d);
528 smoother.template apply<false>(v,d);
546 bool onthefly_=
false)
551 template<
class M,
class X,
class TM,
class TS,
class TA>
557 template<
class M,
class X,
class TM,
class TS,
class TA>
572 Father::setMatrix(matrix);
574 std::vector<bool> visited(amap.
noVertices(),
false);
575 typedef IteratorPropertyMap<std::vector<bool>::iterator,IdentityMap> VisitedMapType;
576 VisitedMapType visitedMap(visited.begin());
582 switch(Father::getArgs().overlap) {
583 case SmootherArgs::vertex :
585 VertexAdder visitor(subdomains, amap);
586 createSubdomains(matrix, graph, amap, visitor, visitedMap);
589 case SmootherArgs::pairwise :
591 createPairDomains(graph);
594 case SmootherArgs::aggregate :
596 AggregateAdder<VisitedMapType> visitor(subdomains, amap, graph, visitedMap);
597 createSubdomains(matrix, graph, amap, visitor, visitedMap);
600 case SmootherArgs::none :
602 createSubdomains(matrix, graph, amap, visitor, visitedMap);
605 DUNE_THROW(NotImplemented,
"This overlapping scheme is not supported!");
610 Father::setMatrix(matrix);
616 iter!=amap.end(); ++iter)
619 std::vector<bool> visited(amap.noVertices(),
false);
620 typedef IteratorPropertyMap<std::vector<bool>::iterator,IdentityMap> VisitedMapType;
621 VisitedMapType visitedMap(visited.begin());
627 switch(Father::getArgs().overlap) {
628 case SmootherArgs::vertex :
630 VertexAdder visitor(subdomains, amap);
631 createSubdomains(matrix, graph, amap, visitor, visitedMap);
634 case SmootherArgs::aggregate :
636 DUNE_THROW(NotImplemented,
"Aggregate overlap is not supported yet");
643 case SmootherArgs::pairwise :
645 createPairDomains(graph);
648 case SmootherArgs::none :
650 createSubdomains(matrix, graph, amap, visitor, visitedMap);
664 : subdomains(subdomains_), max(-1), subdomain(-1), aggregates(aggregates_)
670 subdomains[subdomain].insert(edge.target());
674 subdomain=aggregate_;
675 max = std::max(subdomain, aggregate_);
704 struct AggregateAdder
708 : subdomains(subdomains_), subdomain(-1), aggregates(aggregates_),
709 adder(subdomains_, aggregates_), graph(graph_), visitedMap(visitedMap_)
714 subdomains[subdomain].insert(edge.target());
719 assert(aggregates[edge.target()]!=aggregate);
721 aggregates.template breadthFirstSearch<true,false>(edge.target(), aggregate,
722 graph, vlist, adder, adder,
729 adder.setAggregate(aggregate_);
730 aggregate=aggregate_;
752 typedef typename M::size_type size_type;
754 std::set<std::pair<size_type,size_type> > pairs;
756 for(VIter v=graph.
begin(), ve=graph.
end(); ve != v; ++v)
757 for(EIter e = v.begin(), ee=v.end(); ee!=e; ++e)
760 if(e.source()<e.target())
761 pairs.insert(std::make_pair(e.source(),e.target()));
763 pairs.insert(std::make_pair(e.target(),e.source()));
767 subdomains.resize(pairs.size());
768 Dune::dinfo <<std::endl<<
"Created "<<pairs.size()<<
" ("<<total<<
") pair domains"<<std::endl<<std::endl;
769 typedef typename std::set<std::pair<size_type,size_type> >::const_iterator SIter;
770 typename Vector::iterator subdomain=subdomains.begin();
772 for(SIter s=pairs.begin(), se =pairs.end(); se!=s; ++s)
774 subdomain->insert(s->first);
775 subdomain->insert(s->second);
778 std::size_t minsize=10000;
779 std::size_t maxsize=0;
781 for(
typename Vector::size_type i=0; i < subdomains.size(); ++i) {
782 sum+=subdomains[i].size();
783 minsize=std::min(minsize, subdomains[i].size());
784 maxsize=std::max(maxsize, subdomains[i].size());
786 Dune::dinfo<<
"Subdomain size: min="<<minsize<<
" max="<<maxsize<<
" avg="<<(sum/subdomains.size())
787 <<
" no="<<subdomains.size()<<std::endl;
790 template<
class Visitor>
791 void createSubdomains(
const M& matrix,
const MatrixGraph<const M>& graph,
792 const AggregatesMap& amap, Visitor& overlapVisitor,
793 IteratorPropertyMap<std::vector<bool>::iterator,IdentityMap>& visitedMap )
800 AggregateDescriptor maxAggregate=0;
802 for(std::size_t i=0; i < amap.noVertices(); ++i)
806 maxAggregate = std::max(maxAggregate, amap[i]);
808 subdomains.resize(maxAggregate+1+isolated);
811 for(
typename Vector::size_type i=0; i < subdomains.size(); ++i)
812 subdomains[i].clear();
817 VertexAdder aggregateVisitor(subdomains, amap);
819 for(VertexDescriptor i=0; i < amap.noVertices(); ++i)
820 if(!
get(visitedMap, i)) {
821 AggregateDescriptor aggregate=amap[i];
825 subdomains.push_back(Subdomain());
826 aggregate=subdomains.size()-1;
828 overlapVisitor.setAggregate(aggregate);
829 aggregateVisitor.setAggregate(aggregate);
830 subdomains[aggregate].insert(i);
832 amap.template breadthFirstSearch<false,false>(i, aggregate, graph, vlist, aggregateVisitor,
833 overlapVisitor, visitedMap);
836 std::size_t minsize=10000;
837 std::size_t maxsize=0;
839 for(
typename Vector::size_type i=0; i < subdomains.size(); ++i) {
840 sum+=subdomains[i].size();
841 minsize=std::min(minsize, subdomains[i].size());
842 maxsize=std::max(maxsize, subdomains[i].size());
844 Dune::dinfo<<
"Subdomain size: min="<<minsize<<
" max="<<maxsize<<
" avg="<<(sum/subdomains.size())
845 <<
" no="<<subdomains.size()<<
" isolated="<<isolated<<std::endl;
854 template<
class M,
class X,
class TM,
class TS,
class TA>
void setMatrix(const Matrix &matrix)
Definition: smoother.hh:99
Definition: smoother.hh:540
void operator()(const T &edge)
Definition: smoother.hh:712
void postsmooth(LevelContext &levelContext, size_t steps)
Apply post smoothing on the current level.
Definition: smoother.hh:430
SeqOverlappingSchwarz< M, X, TM, TS, TA >::subdomain_vector Vector
Definition: smoother.hh:567
AggregateDescriptor * iterator
Definition: aggregates.hh:722
static void postSmooth(Smoother &smoother, Domain &v, Range &d)
Definition: smoother.hh:496
DefaultConstructionArgs< SeqILU0< M, X, Y > > Arguments
Definition: smoother.hh:243
Overlap overlap
Definition: smoother.hh:542
ConstructionArgs(int n=1)
Definition: smoother.hh:263
const Matrix & getMatrix() const
Definition: smoother.hh:110
const Matrix * matrix_
Definition: smoother.hh:137
Definition: smoother.hh:537
Dune::Amg::AggregatesMap< VertexDescriptor > AggregatesMap
Definition: smoother.hh:565
Definition: smoother.hh:540
X domain_type
The domain type of the preconditioner.
Definition: preconditioners.hh:220
A parallel SSOR preconditioner.
Definition: schwarz.hh:252
Vector::value_type Subdomain
Definition: smoother.hh:568
SLList< VertexDescriptor, Allocator > VertexList
The type of a single linked list of vertex descriptors.
Definition: aggregates.hh:575
void operator()(const T &edge)
Definition: smoother.hh:667
Traits class for getting the attribute class of a smoother.
Definition: smoother.hh:63
VertexIterator end()
Get an iterator over the vertices.
Construction Arguments for the default smoothers.
Definition: smoother.hh:87
static void postSmooth(Smoother &smoother, Domain &v, Range &d)
Definition: smoother.hh:477
Smoother::domain_type Domain
Definition: smoother.hh:469
virtual void setMatrix(const M &matrix, const AggregatesMap &amap)
Definition: smoother.hh:570
ConstructionTraits< T > SeqConstructionTraits
Definition: smoother.hh:345
SeqOverlappingSchwarz< M, X, MultiplicativeSchwarzMode, MS, TA > Smoother
Definition: smoother.hh:516
static void deconstruct(BlockPreconditioner< X, Y, C, T > *bp)
Definition: smoother.hh:333
const C & getComm() const
Definition: smoother.hh:161
void setN(int n)
Definition: smoother.hh:267
static void preSmooth(Smoother &smoother, Domain &v, const Range &d)
apply pre smoothing in forward direction
Definition: smoother.hh:384
DefaultSmootherArgs()
Default constructor.
Definition: smoother.hh:54
Sequential ILU0 preconditioner.
Definition: preconditioners.hh:488
static const V ISOLATED
Identifier of isolated vertices.
Definition: aggregates.hh:554
Definition: smoother.hh:540
static SeqSOR< M, X, Y, l > * construct(Arguments &args)
Definition: smoother.hh:203
Smoother::domain_type Domain
Definition: smoother.hh:488
ConstructionArgs< SeqOverlappingSchwarz< M, X, TM, TS, TA > > Arguments
Definition: smoother.hh:857
AggregateAdder(Vector &subdomains_, const AggregatesMap &aggregates_, const MatrixGraph< const M > &graph_, VM &visitedMap_)
Definition: smoother.hh:706
Sequential overlapping Schwarz preconditioner.
Definition: colcompmatrix.hh:157
BlockPreconditioner< X, Y, C, SeqSOR< M, X, Y, l > > Smoother
Definition: smoother.hh:467
static BlockPreconditioner< X, Y, C, T > * construct(Arguments &args)
Definition: smoother.hh:327
static void deconstruct(SeqILUn< M, X, Y > *ilu)
Definition: smoother.hh:295
SeqOverlappingSchwarzSmootherArgs< typename M::field_type > Arguments
Definition: smoother.hh:554
Smoother::domain_type Domain
Definition: smoother.hh:375
Definition: smoother.hh:558
virtual ~DefaultConstructionArgs()
Definition: smoother.hh:96
VertexAdder(Vector &subdomains_, const AggregatesMap &aggregates_)
Definition: smoother.hh:663
Tag that tells the Schwarz method to be multiplicative.
Definition: overlappingschwarz.hh:121
static void preSmooth(Smoother &smoother, Domain &v, Range &d)
Definition: smoother.hh:471
Smoother::range_type Range
Definition: smoother.hh:468
const SequentialInformation & getComm()
Definition: smoother.hh:126
Y range_type
The range type of the preconditioner.
Definition: schwarz.hh:367
DefaultSmootherArgs< typename T::matrix_type::field_type > Arguments
Definition: smoother.hh:79
void setComm(const C &comm)
Definition: smoother.hh:156
int iterations
The numbe of iterations to perform.
Definition: smoother.hh:45
void setComm(T1 &comm)
Definition: smoother.hh:121
Helper classes for the construction of classes without empty constructor.
V AggregateDescriptor
The aggregate descriptor type.
Definition: aggregates.hh:563
static SeqILU0< M, X, Y > * construct(Arguments &args)
Definition: smoother.hh:245
static void preSmooth(Smoother &smoother, Domain &v, const Range &d)
Definition: smoother.hh:520
static NonoverlappingBlockPreconditioner< C, T > * construct(Arguments &args)
Definition: smoother.hh:346
DefaultParallelConstructionArgs< T, C > Arguments
Definition: smoother.hh:325
ConstructionArgs< SeqILUn< M, X, Y > > Arguments
Definition: smoother.hh:287
Class providing information about the mapping of the vertices onto aggregates.
Definition: aggregates.hh:542
int setAggregate(const AggregateDescriptor &aggregate_)
Definition: smoother.hh:727
static ParSSOR< M, X, Y, C > * construct(Arguments &args)
Definition: smoother.hh:310
static void deconstruct(SeqILU0< M, X, Y > *ilu)
Definition: smoother.hh:251
static void deconstruct(ParSSOR< M, X, Y, C > *ssor)
Definition: smoother.hh:316
int noSubdomains() const
Definition: smoother.hh:697
static void deconstruct(NonoverlappingBlockPreconditioner< C, T > *bp)
Definition: smoother.hh:352
DefaultParallelConstructionArgs< T, C > Arguments
Definition: smoother.hh:344
SeqOverlappingSchwarzSmootherArgs(Overlap overlap_=vertex, bool onthefly_=false)
Definition: smoother.hh:545
Sequential SSOR preconditioner.
Definition: preconditioners.hh:127
Smoother::domain_type Domain
Definition: smoother.hh:518
Traits class for generically constructing non default constructable types.
Definition: novlpschwarz.hh:326
Smoother::range_type Range
Definition: smoother.hh:374
Definition: smoother.hh:259
P::domain_type domain_type
The domain type of the preconditioner.
Definition: novlpschwarz.hh:344
void setMatrix(const M &matrix)
Definition: smoother.hh:608
static void postSmooth(Smoother &smoother, Domain &v, Range &d)
Definition: smoother.hh:458
The default class for the smoother arguments.
Definition: smoother.hh:35
DefaultParallelConstructionArgs< M, C > Arguments
Definition: smoother.hh:308
X domain_type
The domain type of the preconditioner.
Definition: schwarz.hh:362
static void deconstruct(SeqJac< M, X, Y, l > *jac)
Definition: smoother.hh:229
const Vector & getSubDomains()
Definition: smoother.hh:655
RelaxationFactor relaxationFactor
The relaxation factor to use.
Definition: smoother.hh:49
Nonoverlapping parallel preconditioner.
Definition: novlpschwarz.hh:339
Block parallel preconditioner.
Definition: schwarz.hh:355
const SmootherArgs getArgs() const
Definition: smoother.hh:131
Smoother::domain_type Domain
Definition: smoother.hh:450
static void deconstruct(SeqOverlappingSchwarz< M, X, TM, TS, TA > *schwarz)
Definition: smoother.hh:867
The sequential jacobian preconditioner.
Definition: preconditioners.hh:402
VertexIterator begin()
Get an iterator over the vertices.
Smoother::range_type Range
Definition: smoother.hh:487
X range_type
The range type of the preconditioner.
Definition: overlappingschwarz.hh:768
bool onthefly
Definition: smoother.hh:543
Smoother::range_type Range
Definition: smoother.hh:517
virtual void setMatrix(const Matrix &matrix, const AggregatesMap &amap)
Definition: smoother.hh:103
ConstructionTraits< T > SeqConstructionTraits
Definition: smoother.hh:326
T RelaxationFactor
The type of the relaxation factor.
Definition: smoother.hh:40
Provides classes for the Coloring process of AMG.
int setAggregate(const AggregateDescriptor &aggregate_)
Definition: smoother.hh:693
DefaultSmootherArgs< typename T::matrix_type::field_type > Arguments
Definition: smoother.hh:72
void operator()(const T &edge)
Definition: smoother.hh:691
Define general preconditioner interface.
Helper class for applying the smoothers.
Definition: smoother.hh:371
Smoother::range_type Range
Definition: smoother.hh:449
static void deconstruct(SeqSSOR< M, X, Y, l > *ssor)
Definition: smoother.hh:187
static SeqJac< M, X, Y, l > * construct(Arguments &args)
Definition: smoother.hh:223
DefaultSmootherArgs< typename T::matrix_type::field_type > Arguments
Definition: smoother.hh:65
static void postSmooth(Smoother &smoother, Domain &v, const Range &d)
apply post smoothing in forward direction
Definition: smoother.hh:396
static SeqSSOR< M, X, Y, l > * construct(Arguments &args)
Definition: smoother.hh:181
Overlap
Definition: smoother.hh:540
static void deconstruct(SeqSOR< M, X, Y, l > *sor)
Definition: smoother.hh:209
NonoverlappingBlockPreconditioner< C, SeqSOR< M, X, Y, l > > Smoother
Definition: smoother.hh:486
P::range_type range_type
The range type of the preconditioner.
Definition: novlpschwarz.hh:346
static void preSmooth(Smoother &smoother, Domain &v, Range &d)
Definition: smoother.hh:452
DefaultConstructionArgs< SeqSOR< M, X, Y, l > > Arguments
Definition: smoother.hh:201
Sequential ILU(n) preconditioner.
Definition: preconditioners.hh:572
Sequential SOR preconditioner.
Definition: preconditioners.hh:215
DefaultConstructionArgs< SeqSSOR< M, X, Y, l > > Arguments
Definition: smoother.hh:179
static SeqILUn< M, X, Y > * construct(Arguments &args)
Definition: smoother.hh:289
Definition: smoother.hh:144
static void preSmooth(Smoother &smoother, Domain &v, Range &d)
Definition: smoother.hh:490
void setArgs(const SmootherArgs &args)
Definition: smoother.hh:115
static void postSmooth(Smoother &smoother, Domain &v, const Range &d)
Definition: smoother.hh:526
T Smoother
Definition: smoother.hh:373
MatrixGraph< M >::VertexDescriptor VertexDescriptor
Definition: smoother.hh:564
void presmooth(LevelContext &levelContext, size_t steps)
Apply pre smoothing on the current level.
Definition: smoother.hh:408
virtual ~DefaultParallelConstructionArgs()
Definition: smoother.hh:153
Definition: smoother.hh:149
static SeqOverlappingSchwarz< M, X, TM, TS, TA > * construct(Arguments &args)
Definition: smoother.hh:859
int noSubdomains() const
Definition: smoother.hh:733
int noSubdomains() const
Definition: smoother.hh:678
std::size_t noVertices() const
Get the number of vertices.
Definition: smoother.hh:540
X domain_type
The domain type of the preconditioner.
Definition: overlappingschwarz.hh:763
int getN()
Definition: smoother.hh:271
M::size_type VertexDescriptor
The vertex descriptor.
Definition: graph.hh:71
AggregatesMap::AggregateDescriptor AggregateDescriptor
Definition: smoother.hh:566
int setAggregate(const AggregateDescriptor &aggregate_)
Definition: smoother.hh:672
Y range_type
The range type of the preconditioner.
Definition: preconditioners.hh:222
SeqSOR< M, X, Y, l > Smoother
Definition: smoother.hh:448
DefaultConstructionArgs< SeqJac< M, X, Y, l > > Arguments
Definition: smoother.hh:221