3 #ifndef DUNE_AMGSMOOTHER_HH
4 #define DUNE_AMGSMOOTHER_HH
11 #include <dune/common/propertymap.hh>
68 template<
class X,
class Y>
75 template<
class X,
class Y,
class C,
class T>
80 template<
class C,
class T>
91 typedef typename T::matrix_type Matrix;
147 template<
class T,
class C=SequentialInformation>
169 template<
class X,
class Y>
180 template <
class... Args>
204 const SmootherArgs* args_;
211 struct ConstructionTraits;
216 template<
class M,
class X,
class Y,
int l>
223 return std::make_shared<SeqSSOR<M,X,Y,l>>
232 template<
class M,
class X,
class Y,
int l>
239 return std::make_shared<SeqSOR<M,X,Y,l>>
248 template<
class M,
class X,
class Y,
int l>
255 return std::make_shared<SeqJac<M,X,Y,l>>
263 template<
class X,
class Y>
270 return std::make_shared<Richardson<X,Y>>
276 template<
class M,
class X,
class Y>
303 template<
class M,
class X,
class Y>
310 return std::make_shared<SeqILU<M,X,Y>>
318 template<
class M,
class X,
class Y,
class C>
325 return std::make_shared<ParSSOR<M,X,Y,C>>
331 template<
class X,
class Y,
class C,
class T>
338 auto seqPrec = SeqConstructionTraits::construct(args);
339 return std::make_shared<BlockPreconditioner<X,Y,C,T>> (seqPrec, args.
getComm());
343 template<
class C,
class T>
350 auto seqPrec = SeqConstructionTraits::construct(args);
351 return std::make_shared<NonoverlappingBlockPreconditioner<C,T>> (seqPrec, args.
getComm());
369 typedef typename Smoother::range_type
Range;
370 typedef typename Smoother::domain_type
Domain;
402 template<
typename LevelContext>
403 void presmooth(LevelContext& levelContext,
size_t steps)
405 for(std::size_t i=0; i < steps; ++i) {
408 ::preSmooth(*levelContext.smoother, *levelContext.lhs,
411 *levelContext.update += *levelContext.lhs;
414 levelContext.matrix->applyscaleadd(-1, *levelContext.lhs, *levelContext.rhs);
415 levelContext.pinfo->project(*levelContext.rhs);
424 template<
typename LevelContext>
427 for(std::size_t i=0; i < steps; ++i) {
429 levelContext.matrix->applyscaleadd(-1, *levelContext.lhs,
432 levelContext.pinfo->project(*levelContext.rhs);
434 ::postSmooth(*levelContext.smoother, *levelContext.lhs, *levelContext.rhs);
436 *levelContext.update += *levelContext.lhs;
440 template<
class M,
class X,
class Y,
int l>
449 smoother.template apply<true>(v,d);
455 smoother.template apply<false>(v,d);
459 template<
class M,
class X,
class Y,
class C,
int l>
468 smoother.template apply<true>(v,d);
474 smoother.template apply<false>(v,d);
478 template<
class M,
class X,
class Y,
class C,
int l>
487 smoother.template apply<true>(v,d);
493 smoother.template apply<false>(v,d);
500 template<
class M,
class X,
class MO,
class MS,
class A>
501 class SeqOverlappingSchwarz;
503 struct MultiplicativeSchwarzMode;
507 template<
class M,
class X,
class MS,
class TA>
517 smoother.template apply<true>(v,d);
523 smoother.template apply<false>(v,d);
541 bool onthefly_=
false)
546 template<
class M,
class X,
class TM,
class TS,
class TA>
552 template<
class M,
class X,
class TM,
class TS,
class TA>
567 Father::setMatrix(matrix);
569 std::vector<bool> visited(amap.
noVertices(),
false);
570 typedef IteratorPropertyMap<std::vector<bool>::iterator,IdentityMap> VisitedMapType;
571 VisitedMapType visitedMap(visited.begin());
577 switch(Father::getArgs().overlap) {
578 case SmootherArgs::vertex :
580 VertexAdder visitor(subdomains, amap);
581 createSubdomains(matrix, graph, amap, visitor, visitedMap);
584 case SmootherArgs::pairwise :
586 createPairDomains(graph);
589 case SmootherArgs::aggregate :
591 AggregateAdder<VisitedMapType> visitor(subdomains, amap, graph, visitedMap);
592 createSubdomains(matrix, graph, amap, visitor, visitedMap);
595 case SmootherArgs::none :
597 createSubdomains(matrix, graph, amap, visitor, visitedMap);
600 DUNE_THROW(NotImplemented,
"This overlapping scheme is not supported!");
605 Father::setMatrix(matrix);
611 iter!=amap.
end(); ++iter)
614 std::vector<bool> visited(amap.
noVertices(),
false);
615 typedef IteratorPropertyMap<std::vector<bool>::iterator,IdentityMap> VisitedMapType;
616 VisitedMapType visitedMap(visited.begin());
622 switch(Father::getArgs().overlap) {
623 case SmootherArgs::vertex :
625 VertexAdder visitor(subdomains, amap);
626 createSubdomains(matrix, graph, amap, visitor, visitedMap);
629 case SmootherArgs::aggregate :
631 DUNE_THROW(NotImplemented,
"Aggregate overlap is not supported yet");
638 case SmootherArgs::pairwise :
640 createPairDomains(graph);
643 case SmootherArgs::none :
645 createSubdomains(matrix, graph, amap, visitor, visitedMap);
659 : subdomains(subdomains_), max(-1), subdomain(-1), aggregates(aggregates_)
665 subdomains[subdomain].insert(edge.target());
669 subdomain=aggregate_;
670 max = std::max(subdomain, aggregate_);
699 struct AggregateAdder
703 : subdomains(subdomains_), subdomain(-1), aggregates(aggregates_),
704 adder(subdomains_, aggregates_), graph(graph_), visitedMap(visitedMap_)
709 subdomains[subdomain].insert(edge.target());
714 assert(aggregates[edge.target()]!=aggregate);
716 aggregates.template breadthFirstSearch<true,false>(edge.target(), aggregate,
717 graph, vlist, adder, adder,
724 adder.setAggregate(aggregate_);
725 aggregate=aggregate_;
747 typedef typename M::size_type size_type;
749 std::set<std::pair<size_type,size_type> > pairs;
751 for(VIter v=graph.
begin(), ve=graph.
end(); ve != v; ++v)
752 for(EIter e = v.begin(), ee=v.end(); ee!=e; ++e)
755 if(e.source()<e.target())
756 pairs.insert(std::make_pair(e.source(),e.target()));
758 pairs.insert(std::make_pair(e.target(),e.source()));
762 subdomains.resize(pairs.size());
763 Dune::dinfo <<std::endl<<
"Created "<<pairs.size()<<
" ("<<total<<
") pair domains"<<std::endl<<std::endl;
764 typedef typename std::set<std::pair<size_type,size_type> >::const_iterator SIter;
765 typename Vector::iterator subdomain=subdomains.
begin();
767 for(SIter s=pairs.begin(), se =pairs.end(); se!=s; ++s)
769 subdomain->insert(s->first);
770 subdomain->insert(s->second);
773 std::size_t minsize=10000;
774 std::size_t maxsize=0;
776 for(
typename Vector::size_type i=0; i < subdomains.size(); ++i) {
777 sum+=subdomains[i].size();
778 minsize=std::min(minsize, subdomains[i].size());
779 maxsize=std::max(maxsize, subdomains[i].size());
781 Dune::dinfo<<
"Subdomain size: min="<<minsize<<
" max="<<maxsize<<
" avg="<<(sum/subdomains.size())
782 <<
" no="<<subdomains.size()<<std::endl;
785 template<
class Visitor>
786 void createSubdomains(
const M& matrix,
const MatrixGraph<const M>& graph,
787 const AggregatesMap& amap, Visitor& overlapVisitor,
788 IteratorPropertyMap<std::vector<bool>::iterator,IdentityMap>& visitedMap )
795 AggregateDescriptor maxAggregate=0;
797 for(std::size_t i=0; i < amap.noVertices(); ++i)
801 maxAggregate = std::max(maxAggregate, amap[i]);
803 subdomains.resize(maxAggregate+1+isolated);
806 for(
typename Vector::size_type i=0; i < subdomains.size(); ++i)
807 subdomains[i].clear();
812 VertexAdder aggregateVisitor(subdomains, amap);
814 for(VertexDescriptor i=0; i < amap.noVertices(); ++i)
815 if(!
get(visitedMap, i)) {
816 AggregateDescriptor aggregate=amap[i];
820 subdomains.push_back(Subdomain());
821 aggregate=subdomains.size()-1;
823 overlapVisitor.setAggregate(aggregate);
824 aggregateVisitor.setAggregate(aggregate);
825 subdomains[aggregate].insert(i);
827 amap.template breadthFirstSearch<false,false>(i, aggregate, graph, vlist, aggregateVisitor,
828 overlapVisitor, visitedMap);
831 std::size_t minsize=10000;
832 std::size_t maxsize=0;
834 for(
typename Vector::size_type i=0; i < subdomains.size(); ++i) {
835 sum+=subdomains[i].size();
836 minsize=std::min(minsize, subdomains[i].size());
837 maxsize=std::max(maxsize, subdomains[i].size());
839 Dune::dinfo<<
"Subdomain size: min="<<minsize<<
" max="<<maxsize<<
" avg="<<(sum/subdomains.size())
840 <<
" no="<<subdomains.size()<<
" isolated="<<isolated<<std::endl;
849 template<
class M,
class X,
class TM,
class TS,
class TA>
856 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:111
DefaultSmootherArgs< typename X::field_type > Arguments
Definition: smoother.hh:71
static std::shared_ptr< SeqILU< M, X, Y > > construct(Arguments &args)
Definition: smoother.hh:308
static void postSmooth(Smoother &smoother, Domain &v, Range &d)
Definition: smoother.hh:491
void operator()(const T &edge)
Definition: smoother.hh:686
const SequentialInformation & getComm()
Definition: smoother.hh:193
static void preSmooth(Smoother &smoother, Domain &v, const Range &d)
Definition: smoother.hh:515
ConstructionArgs< SeqILU< M, X, Y > > Arguments
Definition: smoother.hh:306
Smoother::range_type Range
Definition: smoother.hh:512
int setAggregate(const AggregateDescriptor &aggregate_)
Definition: smoother.hh:688
DefaultSmootherArgs< typename T::matrix_type::field_type > Arguments
Definition: smoother.hh:64
int setAggregate(const AggregateDescriptor &aggregate_)
Definition: smoother.hh:667
ConstructionTraits< T > SeqConstructionTraits
Definition: smoother.hh:347
void setArgs(const SmootherArgs &args)
Definition: smoother.hh:116
ConstructionArgs< SeqOverlappingSchwarz< M, X, TM, TS, TA > > Arguments
Definition: smoother.hh:852
NonoverlappingBlockPreconditioner< C, SeqSOR< M, X, Y, l > > Smoother
Definition: smoother.hh:481
static void postSmooth(Smoother &smoother, Domain &v, Range &d)
Definition: smoother.hh:453
AggregateAdder(Vector &subdomains_, const AggregatesMap &aggregates_, const MatrixGraph< const M > &graph_, VM &visitedMap_)
Definition: smoother.hh:701
Overlap
Definition: smoother.hh:535
void setComm(const C &comm)
Definition: smoother.hh:155
DefaultConstructionArgs< Richardson< X, Y > > Arguments
Definition: smoother.hh:266
virtual ~DefaultConstructionArgs()
Definition: smoother.hh:177
SeqOverlappingSchwarzSmootherArgs< typename M::field_type > Arguments
Definition: smoother.hh:549
Vector::value_type Subdomain
Definition: smoother.hh:563
static void preSmooth(Smoother &smoother, Domain &v, Range &d)
Definition: smoother.hh:485
int getN()
Definition: smoother.hh:290
Smoother::range_type Range
Definition: smoother.hh:482
SeqSOR< M, X, Y, l > Smoother
Definition: smoother.hh:443
void operator()(const T &edge)
Definition: smoother.hh:707
static std::shared_ptr< SeqSSOR< M, X, Y, l > > construct(Arguments &args)
Definition: smoother.hh:221
AggregatesMap::AggregateDescriptor AggregateDescriptor
Definition: smoother.hh:561
static std::shared_ptr< Richardson< X, Y > > construct(Arguments &args)
Definition: smoother.hh:268
bool onthefly
Definition: smoother.hh:538
DefaultConstructionArgs< SeqSOR< M, X, Y, l > > Arguments
Definition: smoother.hh:235
virtual void setMatrix(const M &matrix, const AggregatesMap &amap)
Definition: smoother.hh:565
void setMatrix(const Args &...)
Definition: smoother.hh:181
static std::shared_ptr< SeqJac< M, X, Y, l > > construct(Arguments &args)
Definition: smoother.hh:253
DefaultConstructionArgs< SeqJac< M, X, Y, l > > Arguments
Definition: smoother.hh:251
DefaultConstructionArgs< SeqSSOR< M, X, Y, l > > Arguments
Definition: smoother.hh:219
static std::shared_ptr< NonoverlappingBlockPreconditioner< C, T > > construct(Arguments &args)
Definition: smoother.hh:348
const SmootherArgs getArgs() const
Definition: smoother.hh:130
VertexAdder(Vector &subdomains_, const AggregatesMap &aggregates_)
Definition: smoother.hh:658
static std::shared_ptr< SeqSOR< M, X, Y, l > > construct(Arguments &args)
Definition: smoother.hh:237
SeqOverlappingSchwarz< M, X, TM, TS, TA >::subdomain_vector Vector
Definition: smoother.hh:562
static void preSmooth(Smoother &smoother, Domain &v, Range &d)
Definition: smoother.hh:466
const_iterator begin() const
Definition: aggregates.hh:723
void setMatrix(const Matrix &matrix)
Definition: smoother.hh:101
T Smoother
Definition: smoother.hh:368
static void preSmooth(Smoother &smoother, Domain &v, Range &d)
Definition: smoother.hh:447
BlockPreconditioner< X, Y, C, SeqSOR< M, X, Y, l > > Smoother
Definition: smoother.hh:462
static std::shared_ptr< BlockPreconditioner< X, Y, C, T > > construct(Arguments &args)
Definition: smoother.hh:336
int noSubdomains() const
Definition: smoother.hh:673
AggregateDescriptor * iterator
Definition: aggregates.hh:733
void presmooth(LevelContext &levelContext, size_t steps)
Apply pre smoothing on the current level.
Definition: smoother.hh:403
Smoother::domain_type Domain
Definition: smoother.hh:513
SeqOverlappingSchwarzSmootherArgs(Overlap overlap_=vertex, bool onthefly_=false)
Definition: smoother.hh:540
DefaultParallelConstructionArgs< T, C > Arguments
Definition: smoother.hh:334
DefaultParallelConstructionArgs< T, C > Arguments
Definition: smoother.hh:346
const Matrix * matrix_
Definition: smoother.hh:136
const_iterator end() const
Definition: aggregates.hh:728
V AggregateDescriptor
The aggregate descriptor type.
Definition: aggregates.hh:578
static const V ISOLATED
Identifier of isolated vertices.
Definition: aggregates.hh:569
const SequentialInformation & getComm()
Definition: smoother.hh:125
DefaultSmootherArgs()
Default constructor.
Definition: smoother.hh:53
void setMatrix(const M &matrix)
Definition: smoother.hh:603
void setComm([[maybe_unused]] T1 &comm)
Definition: smoother.hh:190
std::size_t noVertices() const
Get the number of vertices.
void operator()(const T &edge)
Definition: smoother.hh:662
static void postSmooth(Smoother &smoother, Domain &v, const Range &d)
apply post smoothing in forward direction
Definition: smoother.hh:391
Smoother::domain_type Domain
Definition: smoother.hh:483
static std::shared_ptr< ParSSOR< M, X, Y, C > > construct(Arguments &args)
Definition: smoother.hh:323
virtual void setMatrix(const Matrix &matrix, [[maybe_unused]] const AggregatesMap &amap)
Definition: smoother.hh:105
Smoother::domain_type Domain
Definition: smoother.hh:370
void setN(int n)
Definition: smoother.hh:285
SLList< VertexDescriptor, Allocator > VertexList
The type of a single linked list of vertex descriptors.
Definition: aggregates.hh:590
SeqOverlappingSchwarz< M, X, MultiplicativeSchwarzMode, MS, TA > Smoother
Definition: smoother.hh:511
MatrixGraph< M >::VertexDescriptor VertexDescriptor
Definition: smoother.hh:559
int noSubdomains() const
Definition: smoother.hh:728
const Vector & getSubDomains()
Definition: smoother.hh:650
const C & getComm() const
Definition: smoother.hh:160
int noSubdomains() const
Definition: smoother.hh:692
void postsmooth(LevelContext &levelContext, size_t steps)
Apply post smoothing on the current level.
Definition: smoother.hh:425
Dune::Amg::AggregatesMap< VertexDescriptor > AggregatesMap
Definition: smoother.hh:560
const SmootherArgs getArgs() const
Definition: smoother.hh:198
static void postSmooth(Smoother &smoother, Domain &v, const Range &d)
Definition: smoother.hh:521
DefaultParallelConstructionArgs< M, C > Arguments
Definition: smoother.hh:321
RelaxationFactor relaxationFactor
The relaxation factor to use.
Definition: smoother.hh:48
virtual ~DefaultParallelConstructionArgs()
Definition: smoother.hh:152
static std::shared_ptr< SeqOverlappingSchwarz< M, X, TM, TS, TA > > construct(Arguments &args)
Definition: smoother.hh:854
Smoother::domain_type Domain
Definition: smoother.hh:445
int setAggregate(const AggregateDescriptor &aggregate_)
Definition: smoother.hh:722
Smoother::range_type Range
Definition: smoother.hh:444
virtual ~DefaultConstructionArgs()
Definition: smoother.hh:98
static void preSmooth(Smoother &smoother, Domain &v, const Range &d)
apply pre smoothing in forward direction
Definition: smoother.hh:379
static void postSmooth(Smoother &smoother, Domain &v, Range &d)
Definition: smoother.hh:472
ConstructionTraits< T > SeqConstructionTraits
Definition: smoother.hh:335
ConstructionArgs(int n=0)
Definition: smoother.hh:281
Smoother::range_type Range
Definition: smoother.hh:463
void setComm([[maybe_unused]] T1 &comm)
Definition: smoother.hh:122
void setArgs(const SmootherArgs &args)
Definition: smoother.hh:184
int iterations
The numbe of iterations to perform.
Definition: smoother.hh:44
T RelaxationFactor
The type of the relaxation factor.
Definition: smoother.hh:39
Smoother::range_type Range
Definition: smoother.hh:369
Overlap overlap
Definition: smoother.hh:537
Smoother::domain_type Domain
Definition: smoother.hh:464
@ aggregate
Definition: smoother.hh:535
@ none
Definition: smoother.hh:535
@ pairwise
Definition: smoother.hh:535
@ vertex
Definition: smoother.hh:535
Definition: allocator.hh:9
PropertyMapTypeSelector< Amg::VertexVisitedTag, Amg::PropertiesGraph< G, Amg::VertexProperties, EP, VM, EM > >::Type get([[maybe_unused]] const Amg::VertexVisitedTag &tag, Amg::PropertiesGraph< G, Amg::VertexProperties, EP, VM, EM > &graph)
Definition: dependency.hh:291
Sequential overlapping Schwarz preconditioner.
Definition: overlappingschwarz.hh:753
X range_type
The range type of the preconditioner.
Definition: overlappingschwarz.hh:768
X domain_type
The domain type of the preconditioner.
Definition: overlappingschwarz.hh:763
Traits class for generically constructing non default constructable types.
Definition: construction.hh:37
Nonoverlapping parallel preconditioner.
Definition: novlpschwarz.hh:277
P::range_type range_type
The range type of the preconditioner.
Definition: novlpschwarz.hh:285
P::domain_type domain_type
The domain type of the preconditioner.
Definition: novlpschwarz.hh:283
Tag that tells the Schwarz method to be multiplicative.
Definition: overlappingschwarz.hh:124
Class providing information about the mapping of the vertices onto aggregates.
Definition: aggregates.hh:558
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:35
Traits class for getting the attribute class of a smoother.
Definition: smoother.hh:63
Construction Arguments for the default smoothers.
Definition: smoother.hh:90
Definition: smoother.hh:145
Definition: smoother.hh:150
Definition: smoother.hh:171
Definition: smoother.hh:279
Helper class for applying the smoothers.
Definition: smoother.hh:367
Definition: smoother.hh:534
Definition: smoother.hh:555
Sequential SSOR preconditioner.
Definition: preconditioners.hh:137
Sequential SOR preconditioner.
Definition: preconditioners.hh:255
X domain_type
The domain type of the preconditioner.
Definition: preconditioners.hh:260
Y range_type
The range type of the preconditioner.
Definition: preconditioners.hh:262
The sequential jacobian preconditioner.
Definition: preconditioners.hh:404
Sequential ILU preconditioner.
Definition: preconditioners.hh:522
Richardson preconditioner.
Definition: preconditioners.hh:701
A parallel SSOR preconditioner.
Definition: schwarz.hh:176
Block parallel preconditioner.
Definition: schwarz.hh:279
X domain_type
The domain type of the preconditioner.
Definition: schwarz.hh:286
Y range_type
The range type of the preconditioner.
Definition: schwarz.hh:291