5#ifndef DUNE_AMGSMOOTHER_HH
6#define DUNE_AMGSMOOTHER_HH
11#include <dune/istl/schwarz.hh>
12#include <dune/istl/novlpschwarz.hh>
13#include <dune/common/propertymap.hh>
72 template<
class X,
class Y>
79 template<
class X,
class Y,
class C,
class T>
81 :
public SmootherTraits<T>
84 template<
class C,
class T>
85 struct SmootherTraits<NonoverlappingBlockPreconditioner<C,T> >
86 :
public SmootherTraits<T>
95 typedef typename T::matrix_type Matrix;
105 void setMatrix(
const Matrix& matrix)
109 virtual void setMatrix(
const Matrix& matrix, [[maybe_unused]]
const AggregatesMap& amap)
115 const Matrix& getMatrix()
const
126 void setComm([[maybe_unused]] T1& comm)
129 const SequentialInformation& getComm()
140 const Matrix* matrix_;
143 SequentialInformation comm_;
147 struct ConstructionArgs
151 template<
class T,
class C=SequentialInformation>
152 class DefaultParallelConstructionArgs
153 :
public ConstructionArgs<T>
156 virtual ~DefaultParallelConstructionArgs()
159 void setComm(
const C& comm)
164 const C& getComm()
const
173 template<
class X,
class Y>
174 class DefaultConstructionArgs<Richardson<X,Y>>
176 typedef Richardson<X,Y> T;
178 typedef typename SmootherTraits<T>::Arguments SmootherArgs;
181 virtual ~DefaultConstructionArgs()
184 template <
class... Args>
185 void setMatrix(
const Args&...)
188 void setArgs(
const SmootherArgs& args)
194 void setComm([[maybe_unused]] T1& comm)
197 const SequentialInformation& getComm()
202 const SmootherArgs getArgs()
const
208 const SmootherArgs* args_;
209 SequentialInformation comm_;
215 struct ConstructionTraits;
220 template<
class M,
class X,
class Y,
int l>
227 return std::make_shared<SeqSSOR<M,X,Y,l>>
236 template<
class M,
class X,
class Y,
int l>
243 return std::make_shared<SeqSOR<M,X,Y,l>>
252 template<
class M,
class X,
class Y,
int l>
259 return std::make_shared<SeqJac<M,X,Y,l>>
267 template<
class X,
class Y>
272 static inline std::shared_ptr<Richardson<X,Y>>
construct(Arguments& args)
274 return std::make_shared<Richardson<X,Y>>
275 (args.getArgs().relaxationFactor);
280 template<
class M,
class X,
class Y>
281 class ConstructionArgs<
SeqILU<M,X,Y> >
285 ConstructionArgs(
int n=0)
307 template<
class M,
class X,
class Y>
310 typedef ConstructionArgs<SeqILU<M,X,Y> >
Arguments;
312 static inline std::shared_ptr<SeqILU<M,X,Y>>
construct(Arguments& args)
314 return std::make_shared<SeqILU<M,X,Y>>
315 (args.getMatrix(), args.getN(), args.getArgs().relaxationFactor);
322 template<
class M,
class X,
class Y,
class C>
325 typedef DefaultParallelConstructionArgs<M,C>
Arguments;
327 static inline std::shared_ptr<ParSSOR<M,X,Y,C>>
construct(Arguments& args)
329 return std::make_shared<ParSSOR<M,X,Y,C>>
330 (args.getMatrix(), args.getArgs().iterations,
331 args.getArgs().relaxationFactor, args.getComm());
335 template<
class X,
class Y,
class C,
class T>
338 typedef DefaultParallelConstructionArgs<T,C>
Arguments;
340 static inline std::shared_ptr<BlockPreconditioner<X,Y,C,T>>
construct(
Arguments& args)
342 auto seqPrec = SeqConstructionTraits::construct(args);
343 return std::make_shared<BlockPreconditioner<X,Y,C,T>> (seqPrec, args.getComm());
347 template<
class C,
class T>
348 struct ConstructionTraits<NonoverlappingBlockPreconditioner<C,T> >
350 typedef DefaultParallelConstructionArgs<T,C>
Arguments;
351 typedef ConstructionTraits<T> SeqConstructionTraits;
352 static inline std::shared_ptr<NonoverlappingBlockPreconditioner<C,T>>
construct(
Arguments& args)
354 auto seqPrec = SeqConstructionTraits::construct(args);
355 return std::make_shared<NonoverlappingBlockPreconditioner<C,T>> (seqPrec, args.getComm());
373 typedef typename Smoother::range_type Range;
374 typedef typename Smoother::domain_type Domain;
383 static void preSmooth(Smoother& smoother, Domain& v,
const Range& d)
395 static void postSmooth(Smoother& smoother, Domain& v,
const Range& d)
406 template<
typename LevelContext>
407 void presmooth(LevelContext& levelContext,
size_t steps)
409 for(std::size_t i=0; i < steps; ++i) {
412 ::preSmooth(*levelContext.smoother, *levelContext.lhs,
415 *levelContext.update += *levelContext.lhs;
418 levelContext.matrix->applyscaleadd(-1, *levelContext.lhs, *levelContext.rhs);
419 levelContext.pinfo->project(*levelContext.rhs);
428 template<
typename LevelContext>
431 for(std::size_t i=0; i < steps; ++i) {
433 levelContext.matrix->applyscaleadd(-1, *levelContext.lhs,
436 levelContext.pinfo->project(*levelContext.rhs);
438 ::postSmooth(*levelContext.smoother, *levelContext.lhs, *levelContext.rhs);
440 *levelContext.update += *levelContext.lhs;
444 template<
class M,
class X,
class Y,
int l>
445 struct SmootherApplier<
SeqSOR<M,X,Y,l> >
448 typedef typename Smoother::range_type Range;
449 typedef typename Smoother::domain_type Domain;
451 static void preSmooth(Smoother& smoother, Domain& v, Range& d)
453 smoother.template apply<true>(v,d);
457 static void postSmooth(Smoother& smoother, Domain& v, Range& d)
459 smoother.template apply<false>(v,d);
463 template<
class M,
class X,
class Y,
class C,
int l>
464 struct SmootherApplier<BlockPreconditioner<X,Y,C,SeqSOR<M,X,Y,l> > >
466 typedef BlockPreconditioner<X,Y,C,SeqSOR<M,X,Y,l> > Smoother;
467 typedef typename Smoother::range_type Range;
468 typedef typename Smoother::domain_type Domain;
470 static void preSmooth(Smoother& smoother, Domain& v, Range& d)
472 smoother.template apply<true>(v,d);
476 static void postSmooth(Smoother& smoother, Domain& v, Range& d)
478 smoother.template apply<false>(v,d);
482 template<
class M,
class X,
class Y,
class C,
int l>
483 struct SmootherApplier<NonoverlappingBlockPreconditioner<C,SeqSOR<M,X,Y,l> > >
485 typedef NonoverlappingBlockPreconditioner<C,SeqSOR<M,X,Y,l> > Smoother;
486 typedef typename Smoother::range_type Range;
487 typedef typename Smoother::domain_type Domain;
489 static void preSmooth(Smoother& smoother, Domain& v, Range& d)
491 smoother.template apply<true>(v,d);
495 static void postSmooth(Smoother& smoother, Domain& v, Range& d)
497 smoother.template apply<false>(v,d);
504 template<
class M,
class X,
class MO,
class MS,
class A>
505 class SeqOverlappingSchwarz;
507 struct MultiplicativeSchwarzMode;
511 template<
class M,
class X,
class MS,
class TA>
512 struct SmootherApplier<SeqOverlappingSchwarz<M,X,MultiplicativeSchwarzMode,
515 typedef SeqOverlappingSchwarz<M,X,MultiplicativeSchwarzMode,MS,TA> Smoother;
516 typedef typename Smoother::range_type Range;
517 typedef typename Smoother::domain_type Domain;
519 static void preSmooth(Smoother& smoother, Domain& v,
const Range& d)
521 smoother.template apply<true>(v,d);
525 static void postSmooth(Smoother& smoother, Domain& v,
const Range& d)
527 smoother.template apply<false>(v,d);
536 struct SeqOverlappingSchwarzSmootherArgs
537 :
public DefaultSmootherArgs<T>
544 SeqOverlappingSchwarzSmootherArgs(Overlap overlap_=
vertex,
545 bool onthefly_=
false)
546 : overlap(overlap_), onthefly(onthefly_)
550 template<
class M,
class X,
class TM,
class TS,
class TA>
551 struct SmootherTraits<SeqOverlappingSchwarz<M,X,TM,TS,TA> >
553 typedef SeqOverlappingSchwarzSmootherArgs<typename M::field_type> Arguments;
556 template<
class M,
class X,
class TM,
class TS,
class TA>
557 class ConstructionArgs<SeqOverlappingSchwarz<M,X,TM,TS,TA> >
558 :
public DefaultConstructionArgs<SeqOverlappingSchwarz<M,X,TM,TS,TA> >
560 typedef DefaultConstructionArgs<SeqOverlappingSchwarz<M,X,TM,TS,TA> > Father;
567 typedef typename Vector::value_type Subdomain;
569 virtual void setMatrix(
const M& matrix,
const AggregatesMap& amap)
571 Father::setMatrix(matrix);
573 std::vector<bool> visited(amap.noVertices(),
false);
574 typedef IteratorPropertyMap<std::vector<bool>::iterator,IdentityMap> VisitedMapType;
575 VisitedMapType visitedMap(visited.begin());
577 MatrixGraph<const M> graph(matrix);
579 typedef SeqOverlappingSchwarzSmootherArgs<typename M::field_type> SmootherArgs;
581 switch(Father::getArgs().overlap) {
584 VertexAdder visitor(subdomains, amap);
585 createSubdomains(matrix, graph, amap, visitor, visitedMap);
588 case SmootherArgs::pairwise :
590 createPairDomains(graph);
593 case SmootherArgs::aggregate :
595 AggregateAdder<VisitedMapType> visitor(subdomains, amap, graph, visitedMap);
596 createSubdomains(matrix, graph, amap, visitor, visitedMap);
601 createSubdomains(matrix, graph, amap, visitor, visitedMap);
604 DUNE_THROW(NotImplemented,
"This overlapping scheme is not supported!");
607 void setMatrix(
const M& matrix)
609 Father::setMatrix(matrix);
612 AggregatesMap amap(matrix.N());
613 VertexDescriptor v=0;
614 for(
typename AggregatesMap::iterator iter=amap.begin();
615 iter!=amap.end(); ++iter)
618 std::vector<bool> visited(amap.noVertices(),
false);
619 typedef IteratorPropertyMap<std::vector<bool>::iterator,IdentityMap> VisitedMapType;
620 VisitedMapType visitedMap(visited.begin());
622 MatrixGraph<const M> graph(matrix);
624 typedef SeqOverlappingSchwarzSmootherArgs<typename M::field_type> SmootherArgs;
626 switch(Father::getArgs().overlap) {
629 VertexAdder visitor(subdomains, amap);
630 createSubdomains(matrix, graph, amap, visitor, visitedMap);
633 case SmootherArgs::aggregate :
635 DUNE_THROW(NotImplemented,
"Aggregate overlap is not supported yet");
642 case SmootherArgs::pairwise :
644 createPairDomains(graph);
649 createSubdomains(matrix, graph, amap, visitor, visitedMap);
654 const Vector& getSubDomains()
662 VertexAdder(Vector& subdomains_,
const AggregatesMap& aggregates_)
663 : subdomains(subdomains_),
max(-1), subdomain(-1), aggregates(aggregates_)
666 void operator()(
const T& edge)
669 subdomains[subdomain].insert(edge.target());
671 int setAggregate(
const AggregateDescriptor& aggregate_)
673 subdomain=aggregate_;
677 int noSubdomains()
const
683 AggregateDescriptor
max;
684 AggregateDescriptor subdomain;
685 const AggregatesMap& aggregates;
690 void operator()(
const T& )
692 int setAggregate(
const AggregateDescriptor& )
696 int noSubdomains()
const
703 struct AggregateAdder
705 AggregateAdder(Vector& subdomains_,
const AggregatesMap& aggregates_,
706 const MatrixGraph<const M>& graph_, VM& visitedMap_)
707 : subdomains(subdomains_), subdomain(-1), aggregates(aggregates_),
708 adder(subdomains_, aggregates_), graph(graph_), visitedMap(visitedMap_)
711 void operator()(
const T& edge)
713 subdomains[subdomain].insert(edge.target());
718 assert(aggregates[edge.target()]!=aggregate);
720 aggregates.template breadthFirstSearch<true,false>(edge.target(), aggregate,
721 graph, vlist, adder, adder,
726 int setAggregate(
const AggregateDescriptor& aggregate_)
728 adder.setAggregate(aggregate_);
729 aggregate=aggregate_;
732 int noSubdomains()
const
738 AggregateDescriptor aggregate;
741 const AggregatesMap& aggregates;
743 const MatrixGraph<const M>& graph;
747 void createPairDomains(
const MatrixGraph<const M>& graph)
751 typedef typename M::size_type size_type;
753 std::set<std::pair<size_type,size_type> > pairs;
755 for(VIter v=graph.begin(), ve=graph.end(); ve != v; ++v)
756 for(EIter e = v.begin(), ee=v.end(); ee!=e; ++e)
759 if(e.source()<e.target())
760 pairs.insert(std::make_pair(e.source(),e.target()));
762 pairs.insert(std::make_pair(e.target(),e.source()));
766 subdomains.resize(pairs.size());
767 Dune::dinfo <<std::endl<<
"Created "<<pairs.size()<<
" ("<<total<<
") pair domains"<<std::endl<<std::endl;
768 typedef typename std::set<std::pair<size_type,size_type> >::const_iterator SIter;
769 typename Vector::iterator subdomain=subdomains.begin();
771 for(SIter s=pairs.begin(), se =pairs.end(); se!=s; ++s)
773 subdomain->insert(s->first);
774 subdomain->insert(s->second);
777 std::size_t minsize=10000;
778 std::size_t maxsize=0;
780 for(
typename Vector::size_type i=0; i < subdomains.size(); ++i) {
781 sum+=subdomains[i].size();
785 Dune::dinfo<<
"Subdomain size: min="<<minsize<<
" max="<<maxsize<<
" avg="<<(sum/subdomains.size())
786 <<
" no="<<subdomains.size()<<std::endl;
789 template<
class Visitor>
790 void createSubdomains(
const M& ,
const MatrixGraph<const M>& graph,
791 const AggregatesMap& amap, Visitor& overlapVisitor,
792 IteratorPropertyMap<std::vector<bool>::iterator,IdentityMap>& visitedMap )
799 AggregateDescriptor maxAggregate=0;
801 for(std::size_t i=0; i < amap.noVertices(); ++i)
805 maxAggregate =
std::max(maxAggregate, amap[i]);
807 subdomains.resize(maxAggregate+1+isolated);
810 for(
typename Vector::size_type i=0; i < subdomains.size(); ++i)
811 subdomains[i].clear();
816 VertexAdder aggregateVisitor(subdomains, amap);
818 for(VertexDescriptor i=0; i < amap.noVertices(); ++i)
819 if(!
get(visitedMap, i)) {
820 AggregateDescriptor aggregate=amap[i];
824 subdomains.push_back(Subdomain());
825 aggregate=subdomains.size()-1;
827 overlapVisitor.setAggregate(aggregate);
828 aggregateVisitor.setAggregate(aggregate);
829 subdomains[aggregate].insert(i);
831 amap.template breadthFirstSearch<false,false>(i, aggregate, graph, vlist, aggregateVisitor,
832 overlapVisitor, visitedMap);
835 std::size_t minsize=10000;
836 std::size_t maxsize=0;
838 for(
typename Vector::size_type i=0; i < subdomains.size(); ++i) {
839 sum+=subdomains[i].size();
843 Dune::dinfo<<
"Subdomain size: min="<<minsize<<
" max="<<maxsize<<
" avg="<<(sum/subdomains.size())
844 <<
" no="<<subdomains.size()<<
" isolated="<<isolated<<std::endl;
853 template<
class M,
class X,
class TM,
class TS,
class TA>
854 struct ConstructionTraits<SeqOverlappingSchwarz<M,X,TM,TS,TA> >
856 typedef ConstructionArgs<SeqOverlappingSchwarz<M,X,TM,TS,TA> >
Arguments;
858 static inline std::shared_ptr<SeqOverlappingSchwarz<M,X,TM,TS,TA>>
construct(
Arguments& args)
860 return std::make_shared<SeqOverlappingSchwarz<M,X,TM,TS,TA>>
862 args.getSubDomains(),
863 args.getArgs().relaxationFactor,
864 args.getArgs().onthefly);
Provides classes for the Coloring process of AMG.
Class providing information about the mapping of the vertices onto aggregates.
Definition: aggregates.hh:570
Construction Arguments for the default smoothers.
Definition: smoother.hh:94
VertexIteratorT< const MatrixGraph< Matrix > > ConstVertexIterator
The constant vertex iterator type.
Definition: graph.hh:308
M::size_type VertexDescriptor
The vertex descriptor.
Definition: graph.hh:73
EdgeIteratorT< const MatrixGraph< Matrix > > ConstEdgeIterator
The constant edge iterator type.
Definition: graph.hh:298
Block parallel preconditioner.
Definition: schwarz.hh:278
Richardson preconditioner.
Definition: preconditioners.hh:878
Sequential ILU preconditioner.
Definition: preconditioners.hh:697
The sequential jacobian preconditioner.
Definition: preconditioners.hh:413
std::vector< subdomain_type, typename std::allocator_traits< TA >::template rebind_alloc< subdomain_type > > subdomain_vector
The vector type containing the subdomain to row index mapping.
Definition: overlappingschwarz.hh:797
Sequential SOR preconditioner.
Definition: preconditioners.hh:262
Sequential SSOR preconditioner.
Definition: preconditioners.hh:142
Helper classes for the construction of classes without empty constructor.
Type traits to determine the type of reals (when working with complex numbers)
#define DUNE_THROW(E,...)
Definition: exceptions.hh:314
constexpr GeometryType none(unsigned int dim)
Returns a GeometryType representing a singular of dimension dim.
Definition: type.hh:471
constexpr GeometryType vertex
GeometryType representing a vertex.
Definition: type.hh:492
constexpr auto max
Function object that returns the greater of the given values.
Definition: hybridutilities.hh:489
constexpr auto min
Function object that returns the smaller of the given values.
Definition: hybridutilities.hh:511
Simd::Scalar< typename FieldTraits< T >::real_type > RelaxationFactor
The type of the relaxation factor.
Definition: smoother.hh:43
static std::shared_ptr< T > construct(Arguments &)
Construct an object with the specified arguments.
Definition: construction.hh:52
void presmooth(LevelContext &levelContext, size_t steps)
Apply pre smoothing on the current level.
Definition: smoother.hh:407
V AggregateDescriptor
The aggregate descriptor type.
Definition: aggregates.hh:590
static const V ISOLATED
Identifier of isolated vertices.
Definition: aggregates.hh:581
DefaultSmootherArgs()
Default constructor.
Definition: smoother.hh:57
const void * Arguments
A type holding all the arguments needed to call the constructor.
Definition: construction.hh:44
static void postSmooth(Smoother &smoother, Domain &v, const Range &d)
apply post smoothing in forward direction
Definition: smoother.hh:395
SLList< VertexDescriptor, Allocator > VertexList
The type of a single linked list of vertex descriptors.
Definition: aggregates.hh:602
void postsmooth(LevelContext &levelContext, size_t steps)
Apply post smoothing on the current level.
Definition: smoother.hh:429
RelaxationFactor relaxationFactor
The relaxation factor to use.
Definition: smoother.hh:52
static void preSmooth(Smoother &smoother, Domain &v, const Range &d)
apply pre smoothing in forward direction
Definition: smoother.hh:383
int iterations
The number of iterations to perform.
Definition: smoother.hh:48
typename Overloads::ScalarType< std::decay_t< V > >::type Scalar
Element type of some SIMD type.
Definition: interface.hh:235
DInfoType dinfo(std::cout)
Stream for informative output.
Definition: stdstreams.hh:141
PartitionSet<... > Overlap
Type of PartitionSet for the overlap partition.
Definition: partitionset.hh:249
Dune namespace
Definition: alignedallocator.hh:13
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75
constexpr auto get(std::integer_sequence< T, II... >, std::integral_constant< std::size_t, pos >={})
Return the entry at position pos of the given sequence.
Definition: integersequence.hh:22
Define general preconditioner interface.
Include file for users of the SIMD abstraction layer.
Traits class for generically constructing non default constructable types.
Definition: construction.hh:39
The default class for the smoother arguments.
Definition: smoother.hh:39
Helper class for applying the smoothers.
Definition: smoother.hh:371
Traits class for getting the attribute class of a smoother.
Definition: smoother.hh:67