3 #ifndef DUNE_AMGSMOOTHER_HH
4 #define DUNE_AMGSMOOTHER_HH
11 #include <dune/common/deprecated.hh>
12 #include <dune/common/propertymap.hh>
13 #include <dune/common/unused.hh>
70 template<
class X,
class Y>
77 template<
class X,
class Y,
class C,
class T>
82 template<
class C,
class T>
93 typedef typename T::matrix_type Matrix;
109 DUNE_UNUSED_PARAMETER(amap);
127 DUNE_UNUSED_PARAMETER(comm);
152 template<
class T,
class C=SequentialInformation>
174 template<
class X,
class Y>
185 template <
class... Args>
197 DUNE_UNUSED_PARAMETER(comm);
211 const SmootherArgs* args_;
218 class ConstructionTraits;
223 template<
class M,
class X,
class Y,
int l>
230 return std::make_shared<SeqSSOR<M,X,Y,l>>
239 template<
class M,
class X,
class Y,
int l>
246 return std::make_shared<SeqSOR<M,X,Y,l>>
255 template<
class M,
class X,
class Y,
int l>
262 return std::make_shared<SeqJac<M,X,Y,l>>
270 template<
class X,
class Y>
277 return std::make_shared<Richardson<X,Y>>
283 DUNE_NO_DEPRECATED_BEGIN
287 template<
class M,
class X,
class Y>
294 return std::make_shared<SeqILU0<M,X,Y>>
298 DUNE_NO_DEPRECATED_END
300 DUNE_NO_DEPRECATED_BEGIN
301 template<
class M,
class X,
class Y>
327 template<
class M,
class X,
class Y>
334 return std::make_shared<SeqILUn<M,X,Y>>
338 DUNE_NO_DEPRECATED_END
341 template<
class M,
class X,
class Y>
368 template<
class M,
class X,
class Y>
375 return std::make_shared<SeqILU<M,X,Y>>
383 template<
class M,
class X,
class Y,
class C>
390 return std::make_shared<ParSSOR<M,X,Y,C>>
396 template<
class X,
class Y,
class C,
class T>
403 auto seqPrec = SeqConstructionTraits::construct(args);
404 return std::make_shared<BlockPreconditioner<X,Y,C,T>> (seqPrec, args.
getComm());
408 template<
class C,
class T>
415 auto seqPrec = SeqConstructionTraits::construct(args);
416 return std::make_shared<NonoverlappingBlockPreconditioner<C,T>> (seqPrec, args.
getComm());
434 typedef typename Smoother::range_type
Range;
435 typedef typename Smoother::domain_type
Domain;
467 template<
typename LevelContext>
468 void presmooth(LevelContext& levelContext,
size_t steps)
470 for(std::size_t i=0; i < steps; ++i) {
473 ::preSmooth(*levelContext.smoother, *levelContext.lhs,
476 *levelContext.update += *levelContext.lhs;
479 levelContext.matrix->applyscaleadd(-1, *levelContext.lhs, *levelContext.rhs);
480 levelContext.pinfo->project(*levelContext.rhs);
489 template<
typename LevelContext>
492 for(std::size_t i=0; i < steps; ++i) {
494 levelContext.matrix->applyscaleadd(-1, *levelContext.lhs,
497 levelContext.pinfo->project(*levelContext.rhs);
499 ::postSmooth(*levelContext.smoother, *levelContext.lhs, *levelContext.rhs);
501 *levelContext.update += *levelContext.lhs;
505 template<
class M,
class X,
class Y,
int l>
514 smoother.template apply<true>(v,d);
520 smoother.template apply<false>(v,d);
524 template<
class M,
class X,
class Y,
class C,
int l>
533 smoother.template apply<true>(v,d);
539 smoother.template apply<false>(v,d);
543 template<
class M,
class X,
class Y,
class C,
int l>
552 smoother.template apply<true>(v,d);
558 smoother.template apply<false>(v,d);
565 template<
class M,
class X,
class MO,
class MS,
class A>
566 class SeqOverlappingSchwarz;
568 struct MultiplicativeSchwarzMode;
572 template<
class M,
class X,
class MS,
class TA>
582 smoother.template apply<true>(v,d);
588 smoother.template apply<false>(v,d);
606 bool onthefly_=
false)
611 template<
class M,
class X,
class TM,
class TS,
class TA>
617 template<
class M,
class X,
class TM,
class TS,
class TA>
632 Father::setMatrix(matrix);
634 std::vector<bool> visited(amap.
noVertices(),
false);
635 typedef IteratorPropertyMap<std::vector<bool>::iterator,IdentityMap> VisitedMapType;
636 VisitedMapType visitedMap(visited.begin());
642 switch(Father::getArgs().overlap) {
643 case SmootherArgs::vertex :
645 VertexAdder visitor(subdomains, amap);
646 createSubdomains(matrix, graph, amap, visitor, visitedMap);
649 case SmootherArgs::pairwise :
651 createPairDomains(graph);
654 case SmootherArgs::aggregate :
656 AggregateAdder<VisitedMapType> visitor(subdomains, amap, graph, visitedMap);
657 createSubdomains(matrix, graph, amap, visitor, visitedMap);
660 case SmootherArgs::none :
662 createSubdomains(matrix, graph, amap, visitor, visitedMap);
665 DUNE_THROW(NotImplemented,
"This overlapping scheme is not supported!");
670 Father::setMatrix(matrix);
676 iter!=amap.
end(); ++iter)
679 std::vector<bool> visited(amap.
noVertices(),
false);
680 typedef IteratorPropertyMap<std::vector<bool>::iterator,IdentityMap> VisitedMapType;
681 VisitedMapType visitedMap(visited.begin());
687 switch(Father::getArgs().overlap) {
688 case SmootherArgs::vertex :
690 VertexAdder visitor(subdomains, amap);
691 createSubdomains(matrix, graph, amap, visitor, visitedMap);
694 case SmootherArgs::aggregate :
696 DUNE_THROW(NotImplemented,
"Aggregate overlap is not supported yet");
703 case SmootherArgs::pairwise :
705 createPairDomains(graph);
708 case SmootherArgs::none :
710 createSubdomains(matrix, graph, amap, visitor, visitedMap);
724 : subdomains(subdomains_), max(-1), subdomain(-1), aggregates(aggregates_)
730 subdomains[subdomain].insert(edge.target());
734 subdomain=aggregate_;
735 max = std::max(subdomain, aggregate_);
764 struct AggregateAdder
768 : subdomains(subdomains_), subdomain(-1), aggregates(aggregates_),
769 adder(subdomains_, aggregates_), graph(graph_), visitedMap(visitedMap_)
774 subdomains[subdomain].insert(edge.target());
779 assert(aggregates[edge.target()]!=aggregate);
781 aggregates.template breadthFirstSearch<true,false>(edge.target(), aggregate,
782 graph, vlist, adder, adder,
789 adder.setAggregate(aggregate_);
790 aggregate=aggregate_;
812 typedef typename M::size_type size_type;
814 std::set<std::pair<size_type,size_type> > pairs;
816 for(VIter v=graph.
begin(), ve=graph.
end(); ve != v; ++v)
817 for(EIter e = v.begin(), ee=v.end(); ee!=e; ++e)
820 if(e.source()<e.target())
821 pairs.insert(std::make_pair(e.source(),e.target()));
823 pairs.insert(std::make_pair(e.target(),e.source()));
827 subdomains.resize(pairs.size());
828 Dune::dinfo <<std::endl<<
"Created "<<pairs.size()<<
" ("<<total<<
") pair domains"<<std::endl<<std::endl;
829 typedef typename std::set<std::pair<size_type,size_type> >::const_iterator SIter;
830 typename Vector::iterator subdomain=subdomains.
begin();
832 for(SIter s=pairs.begin(), se =pairs.end(); se!=s; ++s)
834 subdomain->insert(s->first);
835 subdomain->insert(s->second);
838 std::size_t minsize=10000;
839 std::size_t maxsize=0;
841 for(
typename Vector::size_type i=0; i < subdomains.size(); ++i) {
842 sum+=subdomains[i].size();
843 minsize=std::min(minsize, subdomains[i].size());
844 maxsize=std::max(maxsize, subdomains[i].size());
846 Dune::dinfo<<
"Subdomain size: min="<<minsize<<
" max="<<maxsize<<
" avg="<<(sum/subdomains.size())
847 <<
" no="<<subdomains.size()<<std::endl;
850 template<
class Visitor>
851 void createSubdomains(
const M& matrix,
const MatrixGraph<const M>& graph,
852 const AggregatesMap& amap, Visitor& overlapVisitor,
853 IteratorPropertyMap<std::vector<bool>::iterator,IdentityMap>& visitedMap )
860 AggregateDescriptor maxAggregate=0;
862 for(std::size_t i=0; i < amap.noVertices(); ++i)
866 maxAggregate = std::max(maxAggregate, amap[i]);
868 subdomains.resize(maxAggregate+1+isolated);
871 for(
typename Vector::size_type i=0; i < subdomains.size(); ++i)
872 subdomains[i].clear();
877 VertexAdder aggregateVisitor(subdomains, amap);
879 for(VertexDescriptor i=0; i < amap.noVertices(); ++i)
880 if(!
get(visitedMap, i)) {
881 AggregateDescriptor aggregate=amap[i];
885 subdomains.push_back(Subdomain());
886 aggregate=subdomains.size()-1;
888 overlapVisitor.setAggregate(aggregate);
889 aggregateVisitor.setAggregate(aggregate);
890 subdomains[aggregate].insert(i);
892 amap.template breadthFirstSearch<false,false>(i, aggregate, graph, vlist, aggregateVisitor,
893 overlapVisitor, visitedMap);
896 std::size_t minsize=10000;
897 std::size_t maxsize=0;
899 for(
typename Vector::size_type i=0; i < subdomains.size(); ++i) {
900 sum+=subdomains[i].size();
901 minsize=std::min(minsize, subdomains[i].size());
902 maxsize=std::max(maxsize, subdomains[i].size());
904 Dune::dinfo<<
"Subdomain size: min="<<minsize<<
" max="<<maxsize<<
" avg="<<(sum/subdomains.size())
905 <<
" no="<<subdomains.size()<<
" isolated="<<isolated<<std::endl;
914 template<
class M,
class X,
class TM,
class TS,
class TA>
921 return std::make_shared<SeqOverlappingSchwarz<M,X,TM,TS,TA>>
Provides classes for the Coloring process of AMG.
Helper classes for the construction of classes without empty constructor.
Define general preconditioner interface.
const Matrix & getMatrix() const
Definition: smoother.hh:114
DefaultSmootherArgs< typename X::field_type > Arguments
Definition: smoother.hh:73
static std::shared_ptr< SeqILU< M, X, Y > > construct(Arguments &args)
Definition: smoother.hh:373
static void postSmooth(Smoother &smoother, Domain &v, Range &d)
Definition: smoother.hh:556
void operator()(const T &edge)
Definition: smoother.hh:751
const SequentialInformation & getComm()
Definition: smoother.hh:200
static void preSmooth(Smoother &smoother, Domain &v, const Range &d)
Definition: smoother.hh:580
ConstructionArgs< SeqILU< M, X, Y > > Arguments
Definition: smoother.hh:371
Smoother::range_type Range
Definition: smoother.hh:577
int setAggregate(const AggregateDescriptor &aggregate_)
Definition: smoother.hh:753
DefaultSmootherArgs< typename T::matrix_type::field_type > Arguments
Definition: smoother.hh:66
int setAggregate(const AggregateDescriptor &aggregate_)
Definition: smoother.hh:732
ConstructionTraits< T > SeqConstructionTraits
Definition: smoother.hh:412
void setArgs(const SmootherArgs &args)
Definition: smoother.hh:119
ConstructionArgs< SeqOverlappingSchwarz< M, X, TM, TS, TA > > Arguments
Definition: smoother.hh:917
NonoverlappingBlockPreconditioner< C, SeqSOR< M, X, Y, l > > Smoother
Definition: smoother.hh:546
static void postSmooth(Smoother &smoother, Domain &v, Range &d)
Definition: smoother.hh:518
ConstructionArgs< SeqILUn< M, X, Y > > Arguments
Definition: smoother.hh:330
DefaultConstructionArgs< SeqILU0< M, X, Y > > Arguments
Definition: smoother.hh:290
AggregateAdder(Vector &subdomains_, const AggregatesMap &aggregates_, const MatrixGraph< const M > &graph_, VM &visitedMap_)
Definition: smoother.hh:766
Overlap
Definition: smoother.hh:600
void setComm(const C &comm)
Definition: smoother.hh:160
DefaultConstructionArgs< Richardson< X, Y > > Arguments
Definition: smoother.hh:273
virtual ~DefaultConstructionArgs()
Definition: smoother.hh:182
SeqOverlappingSchwarzSmootherArgs< typename M::field_type > Arguments
Definition: smoother.hh:614
Vector::value_type Subdomain
Definition: smoother.hh:628
static void preSmooth(Smoother &smoother, Domain &v, Range &d)
Definition: smoother.hh:550
int getN()
Definition: smoother.hh:355
Smoother::range_type Range
Definition: smoother.hh:547
SeqSOR< M, X, Y, l > Smoother
Definition: smoother.hh:508
void operator()(const T &edge)
Definition: smoother.hh:772
static std::shared_ptr< SeqSSOR< M, X, Y, l > > construct(Arguments &args)
Definition: smoother.hh:228
AggregatesMap::AggregateDescriptor AggregateDescriptor
Definition: smoother.hh:626
static std::shared_ptr< Richardson< X, Y > > construct(Arguments &args)
Definition: smoother.hh:275
bool onthefly
Definition: smoother.hh:603
DefaultConstructionArgs< SeqSOR< M, X, Y, l > > Arguments
Definition: smoother.hh:242
virtual void setMatrix(const M &matrix, const AggregatesMap &amap)
Definition: smoother.hh:630
void setMatrix(const Args &...)
Definition: smoother.hh:186
static std::shared_ptr< SeqJac< M, X, Y, l > > construct(Arguments &args)
Definition: smoother.hh:260
DefaultConstructionArgs< SeqJac< M, X, Y, l > > Arguments
Definition: smoother.hh:258
DefaultConstructionArgs< SeqSSOR< M, X, Y, l > > Arguments
Definition: smoother.hh:226
static std::shared_ptr< NonoverlappingBlockPreconditioner< C, T > > construct(Arguments &args)
Definition: smoother.hh:413
const SmootherArgs getArgs() const
Definition: smoother.hh:135
VertexAdder(Vector &subdomains_, const AggregatesMap &aggregates_)
Definition: smoother.hh:723
static std::shared_ptr< SeqSOR< M, X, Y, l > > construct(Arguments &args)
Definition: smoother.hh:244
SeqOverlappingSchwarz< M, X, TM, TS, TA >::subdomain_vector Vector
Definition: smoother.hh:627
static void preSmooth(Smoother &smoother, Domain &v, Range &d)
Definition: smoother.hh:531
const_iterator begin() const
Definition: aggregates.hh:723
void setMatrix(const Matrix &matrix)
Definition: smoother.hh:103
T Smoother
Definition: smoother.hh:433
static void preSmooth(Smoother &smoother, Domain &v, Range &d)
Definition: smoother.hh:512
BlockPreconditioner< X, Y, C, SeqSOR< M, X, Y, l > > Smoother
Definition: smoother.hh:527
static std::shared_ptr< BlockPreconditioner< X, Y, C, T > > construct(Arguments &args)
Definition: smoother.hh:401
void setComm(T1 &comm)
Definition: smoother.hh:195
int noSubdomains() const
Definition: smoother.hh:738
AggregateDescriptor * iterator
Definition: aggregates.hh:733
void presmooth(LevelContext &levelContext, size_t steps)
Apply pre smoothing on the current level.
Definition: smoother.hh:468
Smoother::domain_type Domain
Definition: smoother.hh:578
SeqOverlappingSchwarzSmootherArgs(Overlap overlap_=vertex, bool onthefly_=false)
Definition: smoother.hh:605
DefaultParallelConstructionArgs< T, C > Arguments
Definition: smoother.hh:399
DefaultParallelConstructionArgs< T, C > Arguments
Definition: smoother.hh:411
const Matrix * matrix_
Definition: smoother.hh:141
const_iterator end() const
Definition: aggregates.hh:728
V AggregateDescriptor
The aggregate descriptor type.
Definition: aggregates.hh:576
static const V ISOLATED
Identifier of isolated vertices.
Definition: aggregates.hh:567
const SequentialInformation & getComm()
Definition: smoother.hh:130
DefaultSmootherArgs()
Default constructor.
Definition: smoother.hh:55
int getN()
Definition: smoother.hh:314
void setMatrix(const M &matrix)
Definition: smoother.hh:668
std::size_t noVertices() const
Get the number of vertices.
void operator()(const T &edge)
Definition: smoother.hh:727
static void postSmooth(Smoother &smoother, Domain &v, const Range &d)
apply post smoothing in forward direction
Definition: smoother.hh:456
void setN(int n)
Definition: smoother.hh:310
Smoother::domain_type Domain
Definition: smoother.hh:548
static std::shared_ptr< ParSSOR< M, X, Y, C > > construct(Arguments &args)
Definition: smoother.hh:388
Smoother::domain_type Domain
Definition: smoother.hh:435
void setN(int n)
Definition: smoother.hh:350
ConstructionArgs(int n=1)
Definition: smoother.hh:306
SLList< VertexDescriptor, Allocator > VertexList
The type of a single linked list of vertex descriptors.
Definition: aggregates.hh:588
static std::shared_ptr< SeqILUn< M, X, Y > > construct(Arguments &args)
Definition: smoother.hh:332
SeqOverlappingSchwarz< M, X, MultiplicativeSchwarzMode, MS, TA > Smoother
Definition: smoother.hh:576
MatrixGraph< M >::VertexDescriptor VertexDescriptor
Definition: smoother.hh:624
int noSubdomains() const
Definition: smoother.hh:793
const Vector & getSubDomains()
Definition: smoother.hh:715
const C & getComm() const
Definition: smoother.hh:165
virtual void setMatrix(const Matrix &matrix, const AggregatesMap &amap)
Definition: smoother.hh:107
int noSubdomains() const
Definition: smoother.hh:757
void postsmooth(LevelContext &levelContext, size_t steps)
Apply post smoothing on the current level.
Definition: smoother.hh:490
Dune::Amg::AggregatesMap< VertexDescriptor > AggregatesMap
Definition: smoother.hh:625
const SmootherArgs getArgs() const
Definition: smoother.hh:205
void setComm(T1 &comm)
Definition: smoother.hh:125
static void postSmooth(Smoother &smoother, Domain &v, const Range &d)
Definition: smoother.hh:586
DefaultParallelConstructionArgs< M, C > Arguments
Definition: smoother.hh:386
RelaxationFactor relaxationFactor
The relaxation factor to use.
Definition: smoother.hh:50
virtual ~DefaultParallelConstructionArgs()
Definition: smoother.hh:157
static std::shared_ptr< SeqILU0< M, X, Y > > construct(Arguments &args)
Definition: smoother.hh:292
static std::shared_ptr< SeqOverlappingSchwarz< M, X, TM, TS, TA > > construct(Arguments &args)
Definition: smoother.hh:919
Smoother::domain_type Domain
Definition: smoother.hh:510
int setAggregate(const AggregateDescriptor &aggregate_)
Definition: smoother.hh:787
Smoother::range_type Range
Definition: smoother.hh:509
virtual ~DefaultConstructionArgs()
Definition: smoother.hh:100
static void preSmooth(Smoother &smoother, Domain &v, const Range &d)
apply pre smoothing in forward direction
Definition: smoother.hh:444
static void postSmooth(Smoother &smoother, Domain &v, Range &d)
Definition: smoother.hh:537
ConstructionTraits< T > SeqConstructionTraits
Definition: smoother.hh:400
ConstructionArgs(int n=0)
Definition: smoother.hh:346
Smoother::range_type Range
Definition: smoother.hh:528
void setArgs(const SmootherArgs &args)
Definition: smoother.hh:189
int iterations
The numbe of iterations to perform.
Definition: smoother.hh:46
T RelaxationFactor
The type of the relaxation factor.
Definition: smoother.hh:41
Smoother::range_type Range
Definition: smoother.hh:434
Overlap overlap
Definition: smoother.hh:602
Smoother::domain_type Domain
Definition: smoother.hh:529
@ aggregate
Definition: smoother.hh:600
@ none
Definition: smoother.hh:600
@ pairwise
Definition: smoother.hh:600
@ vertex
Definition: smoother.hh:600
Definition: allocator.hh:7
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
Sequential overlapping Schwarz preconditioner.
Definition: overlappingschwarz.hh:752
X range_type
The range type of the preconditioner.
Definition: overlappingschwarz.hh:767
X domain_type
The domain type of the preconditioner.
Definition: overlappingschwarz.hh:762
Traits class for generically constructing non default constructable types.
Definition: construction.hh:38
Nonoverlapping parallel preconditioner.
Definition: novlpschwarz.hh:272
P::range_type range_type
The range type of the preconditioner.
Definition: novlpschwarz.hh:280
P::domain_type domain_type
The domain type of the preconditioner.
Definition: novlpschwarz.hh:278
Tag that tells the Schwarz method to be multiplicative.
Definition: overlappingschwarz.hh:123
Class providing information about the mapping of the vertices onto aggregates.
Definition: aggregates.hh:556
VertexIterator end()
Get an iterator over the vertices.
M::size_type VertexDescriptor
The vertex descriptor.
Definition: graph.hh:71
VertexIterator begin()
Get an iterator over the vertices.
The default class for the smoother arguments.
Definition: smoother.hh:37
Traits class for getting the attribute class of a smoother.
Definition: smoother.hh:65
Construction Arguments for the default smoothers.
Definition: smoother.hh:92
Definition: smoother.hh:150
Definition: smoother.hh:155
Definition: smoother.hh:176
Definition: smoother.hh:304
Definition: smoother.hh:344
Helper class for applying the smoothers.
Definition: smoother.hh:432
Definition: smoother.hh:599
Definition: smoother.hh:620
Sequential SSOR preconditioner.
Definition: preconditioners.hh:138
Sequential SOR preconditioner.
Definition: preconditioners.hh:249
X domain_type
The domain type of the preconditioner.
Definition: preconditioners.hh:254
Y range_type
The range type of the preconditioner.
Definition: preconditioners.hh:256
The sequential jacobian preconditioner.
Definition: preconditioners.hh:390
Sequential ILU preconditioner.
Definition: preconditioners.hh:500
Sequential ILU0 preconditioner.
Definition: preconditioners.hh:670
Sequential ILU(n) preconditioner.
Definition: preconditioners.hh:778
Richardson preconditioner.
Definition: preconditioners.hh:875
A parallel SSOR preconditioner.
Definition: schwarz.hh:170
Block parallel preconditioner.
Definition: schwarz.hh:273
X domain_type
The domain type of the preconditioner.
Definition: schwarz.hh:280
Y range_type
The range type of the preconditioner.
Definition: schwarz.hh:285