Debian Codegraph @

dune/istl/paamg/smoother.hh

raw
1 // SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root
2 // SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
3 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4 // vi: set et ts=4 sw=2 sts=2:
5 #ifndef DUNE_AMGSMOOTHER_HH
6 #define DUNE_AMGSMOOTHER_HH
7
8 #include <dune/istl/paamg/construction.hh>
9 #include <dune/istl/paamg/aggregates.hh>
10 #include <dune/istl/preconditioners.hh>
11 #include <dune/istl/schwarz.hh>
12 #include <dune/istl/novlpschwarz.hh>
13 #include <dune/common/propertymap.hh>
14 #include <dune/common/ftraits.hh>
15
16 namespace Dune
17 {
18 namespace Amg
19 {
20
21 /**
22 * @addtogroup ISTL_PAAMG
23 *
24 * @{
25 */
26
27 /** @file
28 * @author Markus Blatt
29 * @brief Classes for the generic construction and application
30 * of the smoothers.
31 */
32
33 /**
34 * @brief The default class for the smoother arguments.
35 */
36 template<class T>
37 struct DefaultSmootherArgs
38 {
39 /**
40 * @brief The type of the relaxation factor.
41 */
42 typedef typename FieldTraits<T>::real_type RelaxationFactor;
43
44 /**
45 * @brief The number of iterations to perform.
46 */
47 int iterations;
48 /**
49 * @brief The relaxation factor to use.
50 */
51 RelaxationFactor relaxationFactor;
52
53 /**
54 * @brief Default constructor.
55 */
56 DefaultSmootherArgs()
57 : iterations(1), relaxationFactor(1.0)
58 {}
59 };
60
61 /**
62 * @brief Traits class for getting the attribute class of a smoother.
63 */
64 template<class T>
65 struct SmootherTraits
66 {
67 typedef DefaultSmootherArgs<typename T::matrix_type::field_type> Arguments;
68
69 };
70
71 template<class X, class Y>
72 struct SmootherTraits<Richardson<X,Y>>
73 {
74 typedef DefaultSmootherArgs<typename X::field_type> Arguments;
75
76 };
77
78 template<class X, class Y, class C, class T>
79 struct SmootherTraits<BlockPreconditioner<X,Y,C,T> >
80 : public SmootherTraits<T>
81 {};
82
83 template<class C, class T>
84 struct SmootherTraits<NonoverlappingBlockPreconditioner<C,T> >
85 : public SmootherTraits<T>
86 {};
87
88 /**
89 * @brief Construction Arguments for the default smoothers
90 */
91 template<class T>
92 class DefaultConstructionArgs
93 {
94 typedef typename T::matrix_type Matrix;
95
96 typedef typename SmootherTraits<T>::Arguments SmootherArgs;
97
98 typedef Dune::Amg::AggregatesMap<typename MatrixGraph<Matrix>::VertexDescriptor> AggregatesMap;
99
100 public:
101 virtual ~DefaultConstructionArgs()
102 {}
103
104 void setMatrix(const Matrix& matrix)
105 {
106 matrix_=&matrix;
107 }
108 virtual void setMatrix(const Matrix& matrix, [[maybe_unused]] const AggregatesMap& amap)
109 {
110 setMatrix(matrix);
111 }
112
113
114 const Matrix& getMatrix() const
115 {
116 return *matrix_;
117 }
118
119 void setArgs(const SmootherArgs& args)
120 {
121 args_=&args;
122 }
123
124 template<class T1>
125 void setComm([[maybe_unused]] T1& comm)
126 {}
127
128 const SequentialInformation& getComm()
129 {
130 return comm_;
131 }
132
133 const SmootherArgs getArgs() const
134 {
135 return *args_;
136 }
137
138 protected:
139 const Matrix* matrix_;
140 private:
141 const SmootherArgs* args_;
142 SequentialInformation comm_;
143 };
144
145 template<class T>
146 struct ConstructionArgs
147 : public DefaultConstructionArgs<T>
148 {};
149
150 template<class T, class C=SequentialInformation>
151 class DefaultParallelConstructionArgs
152 : public ConstructionArgs<T>
153 {
154 public:
155 virtual ~DefaultParallelConstructionArgs()
156 {}
157
158 void setComm(const C& comm)
159 {
160 comm_ = &comm;
161 }
162
163 const C& getComm() const
164 {
165 return *comm_;
166 }
167 private:
168 const C* comm_;
169 };
170
171
172 template<class X, class Y>
173 class DefaultConstructionArgs<Richardson<X,Y>>
174 {
175 typedef Richardson<X,Y> T;
176
177 typedef typename SmootherTraits<T>::Arguments SmootherArgs;
178
179 public:
180 virtual ~DefaultConstructionArgs()
181 {}
182
183 template <class... Args>
184 void setMatrix(const Args&...)
185 {}
186
187 void setArgs(const SmootherArgs& args)
188 {
189 args_=&args;
190 }
191
192 template<class T1>
193 void setComm([[maybe_unused]] T1& comm)
194 {}
195
196 const SequentialInformation& getComm()
197 {
198 return comm_;
199 }
200
201 const SmootherArgs getArgs() const
202 {
203 return *args_;
204 }
205
206 private:
207 const SmootherArgs* args_;
208 SequentialInformation comm_;
209 };
210
211
212
213 template<class T>
214 struct ConstructionTraits;
215
216 /**
217 * @brief Policy for the construction of the SeqSSOR smoother
218 */
219 template<class M, class X, class Y, int l>
220 struct ConstructionTraits<SeqSSOR<M,X,Y,l> >
221 {
222 typedef DefaultConstructionArgs<SeqSSOR<M,X,Y,l> > Arguments;
223
224 static inline std::shared_ptr<SeqSSOR<M,X,Y,l>> construct(Arguments& args)
225 {
226 return std::make_shared<SeqSSOR<M,X,Y,l>>
227 (args.getMatrix(), args.getArgs().iterations, args.getArgs().relaxationFactor);
228 }
229 };
230
231
232 /**
233 * @brief Policy for the construction of the SeqSOR smoother
234 */
235 template<class M, class X, class Y, int l>
236 struct ConstructionTraits<SeqSOR<M,X,Y,l> >
237 {
238 typedef DefaultConstructionArgs<SeqSOR<M,X,Y,l> > Arguments;
239
240 static inline std::shared_ptr<SeqSOR<M,X,Y,l>> construct(Arguments& args)
241 {
242 return std::make_shared<SeqSOR<M,X,Y,l>>
243 (args.getMatrix(), args.getArgs().iterations, args.getArgs().relaxationFactor);
244 }
245 };
246
247
248 /**
249 * @brief Policy for the construction of the SeqJac smoother
250 */
251 template<class M, class X, class Y, int l>
252 struct ConstructionTraits<SeqJac<M,X,Y,l> >
253 {
254 typedef DefaultConstructionArgs<SeqJac<M,X,Y,l> > Arguments;
255
256 static inline std::shared_ptr<SeqJac<M,X,Y,l>> construct(Arguments& args)
257 {
258 return std::make_shared<SeqJac<M,X,Y,l>>
259 (args.getMatrix(), args.getArgs().iterations, args.getArgs().relaxationFactor);
260 }
261 };
262
263 /**
264 * @brief Policy for the construction of the Richardson smoother
265 */
266 template<class X, class Y>
267 struct ConstructionTraits<Richardson<X,Y> >
268 {
269 typedef DefaultConstructionArgs<Richardson<X,Y> > Arguments;
270
271 static inline std::shared_ptr<Richardson<X,Y>> construct(Arguments& args)
272 {
273 return std::make_shared<Richardson<X,Y>>
274 (args.getArgs().relaxationFactor);
275 }
276 };
277
278
279 template<class M, class X, class Y>
280 class ConstructionArgs<SeqILU<M,X,Y> >
281 : public DefaultConstructionArgs<SeqILU<M,X,Y> >
282 {
283 public:
284 ConstructionArgs(int n=0)
285 : n_(n)
286 {}
287
288 void setN(int n)
289 {
290 n_ = n;
291 }
292
293 int getN()
294 {
295 return n_;
296 }
297
298 private:
299 int n_;
300 };
301
302
303 /**
304 * @brief Policy for the construction of the SeqILU smoother
305 */
306 template<class M, class X, class Y>
307 struct ConstructionTraits<SeqILU<M,X,Y> >
308 {
309 typedef ConstructionArgs<SeqILU<M,X,Y> > Arguments;
310
311 static inline std::shared_ptr<SeqILU<M,X,Y>> construct(Arguments& args)
312 {
313 return std::make_shared<SeqILU<M,X,Y>>
314 (args.getMatrix(), args.getN(), args.getArgs().relaxationFactor);
315 }
316 };
317
318 /**
319 * @brief Policy for the construction of the ParSSOR smoother
320 */
321 template<class M, class X, class Y, class C>
322 struct ConstructionTraits<ParSSOR<M,X,Y,C> >
323 {
324 typedef DefaultParallelConstructionArgs<M,C> Arguments;
325
326 static inline std::shared_ptr<ParSSOR<M,X,Y,C>> construct(Arguments& args)
327 {
328 return std::make_shared<ParSSOR<M,X,Y,C>>
329 (args.getMatrix(), args.getArgs().iterations,
330 args.getArgs().relaxationFactor, args.getComm());
331 }
332 };
333
334 template<class X, class Y, class C, class T>
335 struct ConstructionTraits<BlockPreconditioner<X,Y,C,T> >
336 {
337 typedef DefaultParallelConstructionArgs<T,C> Arguments;
338 typedef ConstructionTraits<T> SeqConstructionTraits;
339 static inline std::shared_ptr<BlockPreconditioner<X,Y,C,T>> construct(Arguments& args)
340 {
341 auto seqPrec = SeqConstructionTraits::construct(args);
342 return std::make_shared<BlockPreconditioner<X,Y,C,T>> (seqPrec, args.getComm());
343 }
344 };
345
346 template<class C, class T>
347 struct ConstructionTraits<NonoverlappingBlockPreconditioner<C,T> >
348 {
349 typedef DefaultParallelConstructionArgs<T,C> Arguments;
350 typedef ConstructionTraits<T> SeqConstructionTraits;
351 static inline std::shared_ptr<NonoverlappingBlockPreconditioner<C,T>> construct(Arguments& args)
352 {
353 auto seqPrec = SeqConstructionTraits::construct(args);
354 return std::make_shared<NonoverlappingBlockPreconditioner<C,T>> (seqPrec, args.getComm());
355 }
356 };
357
358 /**
359 * @brief Helper class for applying the smoothers.
360 *
361 * The goal of this class is to get a symmetric AMG method
362 * whenever possible.
363 *
364 * The specializations for SOR and SeqOverlappingSchwarz in
365 * MultiplicativeSchwarzMode will apply
366 * the smoother forward when pre and backward when post smoothing.
367 */
368 template<class T>
369 struct SmootherApplier
370 {
371 typedef T Smoother;
372 typedef typename Smoother::range_type Range;
373 typedef typename Smoother::domain_type Domain;
374
375 /**
376 * @brief apply pre smoothing in forward direction
377 *
378 * @param smoother The smoother to use.
379 * @param d The current defect.
380 * @param v handle to store the update in.
381 */
382 static void preSmooth(Smoother& smoother, Domain& v, const Range& d)
383 {
384 smoother.apply(v,d);
385 }
386
387 /**
388 * @brief apply post smoothing in forward direction
389 *
390 * @param smoother The smoother to use.
391 * @param d The current defect.
392 * @param v handle to store the update in.
393 */
394 static void postSmooth(Smoother& smoother, Domain& v, const Range& d)
395 {
396 smoother.apply(v,d);
397 }
398 };
399
400 /**
401 * @brief Apply pre smoothing on the current level.
402 * @param levelContext the iterators of the current level.
403 * @param steps The number of smoothing steps to apply.
404 */
405 template<typename LevelContext>
406 void presmooth(LevelContext& levelContext, size_t steps)
407 {
408 for(std::size_t i=0; i < steps; ++i) {
409 *levelContext.lhs=0;
410 SmootherApplier<typename LevelContext::SmootherType>
411 ::preSmooth(*levelContext.smoother, *levelContext.lhs,
412 *levelContext.rhs);
413 // Accumulate update
414 *levelContext.update += *levelContext.lhs;
415
416 // update defect
417 levelContext.matrix->applyscaleadd(-1, *levelContext.lhs, *levelContext.rhs);
418 levelContext.pinfo->project(*levelContext.rhs);
419 }
420 }
421
422 /**
423 * @brief Apply post smoothing on the current level.
424 * @param levelContext the iterators of the current level.
425 * @param steps The number of smoothing steps to apply.
426 */
427 template<typename LevelContext>
428 void postsmooth(LevelContext& levelContext, size_t steps)
429 {
430 for(std::size_t i=0; i < steps; ++i) {
431 // update defect
432 levelContext.matrix->applyscaleadd(-1, *levelContext.lhs,
433 *levelContext.rhs);
434 *levelContext.lhs=0;
435 levelContext.pinfo->project(*levelContext.rhs);
436 SmootherApplier<typename LevelContext::SmootherType>
437 ::postSmooth(*levelContext.smoother, *levelContext.lhs, *levelContext.rhs);
438 // Accumulate update
439 *levelContext.update += *levelContext.lhs;
440 }
441 }
442
443 template<class M, class X, class Y, int l>
444 struct SmootherApplier<SeqSOR<M,X,Y,l> >
445 {
446 typedef SeqSOR<M,X,Y,l> Smoother;
447 typedef typename Smoother::range_type Range;
448 typedef typename Smoother::domain_type Domain;
449
450 static void preSmooth(Smoother& smoother, Domain& v, Range& d)
451 {
452 smoother.template apply<true>(v,d);
453 }
454
455
456 static void postSmooth(Smoother& smoother, Domain& v, Range& d)
457 {
458 smoother.template apply<false>(v,d);
459 }
460 };
461
462 template<class M, class X, class Y, class C, int l>
463 struct SmootherApplier<BlockPreconditioner<X,Y,C,SeqSOR<M,X,Y,l> > >
464 {
465 typedef BlockPreconditioner<X,Y,C,SeqSOR<M,X,Y,l> > Smoother;
466 typedef typename Smoother::range_type Range;
467 typedef typename Smoother::domain_type Domain;
468
469 static void preSmooth(Smoother& smoother, Domain& v, Range& d)
470 {
471 smoother.template apply<true>(v,d);
472 }
473
474
475 static void postSmooth(Smoother& smoother, Domain& v, Range& d)
476 {
477 smoother.template apply<false>(v,d);
478 }
479 };
480
481 template<class M, class X, class Y, class C, int l>
482 struct SmootherApplier<NonoverlappingBlockPreconditioner<C,SeqSOR<M,X,Y,l> > >
483 {
484 typedef NonoverlappingBlockPreconditioner<C,SeqSOR<M,X,Y,l> > Smoother;
485 typedef typename Smoother::range_type Range;
486 typedef typename Smoother::domain_type Domain;
487
488 static void preSmooth(Smoother& smoother, Domain& v, Range& d)
489 {
490 smoother.template apply<true>(v,d);
491 }
492
493
494 static void postSmooth(Smoother& smoother, Domain& v, Range& d)
495 {
496 smoother.template apply<false>(v,d);
497 }
498 };
499
500 } // end namespace Amg
501
502 // forward declarations
503 template<class M, class X, class MO, class MS, class A>
504 class SeqOverlappingSchwarz;
505
506 struct MultiplicativeSchwarzMode;
507
508 namespace Amg
509 {
510 template<class M, class X, class MS, class TA>
511 struct SmootherApplier<SeqOverlappingSchwarz<M,X,MultiplicativeSchwarzMode,
512 MS,TA> >
513 {
514 typedef SeqOverlappingSchwarz<M,X,MultiplicativeSchwarzMode,MS,TA> Smoother;
515 typedef typename Smoother::range_type Range;
516 typedef typename Smoother::domain_type Domain;
517
518 static void preSmooth(Smoother& smoother, Domain& v, const Range& d)
519 {
520 smoother.template apply<true>(v,d);
521 }
522
523
524 static void postSmooth(Smoother& smoother, Domain& v, const Range& d)
525 {
526 smoother.template apply<false>(v,d);
527
528 }
529 };
530
531 // template<class M, class X, class TM, class TA>
532 // class SeqOverlappingSchwarz;
533
534 template<class T>
535 struct SeqOverlappingSchwarzSmootherArgs
536 : public DefaultSmootherArgs<T>
537 {
538 enum Overlap {vertex, aggregate, pairwise, none};
539
540 Overlap overlap;
541 bool onthefly;
542
543 SeqOverlappingSchwarzSmootherArgs(Overlap overlap_=vertex,
544 bool onthefly_=false)
545 : overlap(overlap_), onthefly(onthefly_)
546 {}
547 };
548
549 template<class M, class X, class TM, class TS, class TA>
550 struct SmootherTraits<SeqOverlappingSchwarz<M,X,TM,TS,TA> >
551 {
552 typedef SeqOverlappingSchwarzSmootherArgs<typename M::field_type> Arguments;
553 };
554
555 template<class M, class X, class TM, class TS, class TA>
556 class ConstructionArgs<SeqOverlappingSchwarz<M,X,TM,TS,TA> >
557 : public DefaultConstructionArgs<SeqOverlappingSchwarz<M,X,TM,TS,TA> >
558 {
559 typedef DefaultConstructionArgs<SeqOverlappingSchwarz<M,X,TM,TS,TA> > Father;
560
561 public:
562 typedef typename MatrixGraph<M>::VertexDescriptor VertexDescriptor;
563 typedef Dune::Amg::AggregatesMap<VertexDescriptor> AggregatesMap;
564 typedef typename AggregatesMap::AggregateDescriptor AggregateDescriptor;
565 typedef typename SeqOverlappingSchwarz<M,X,TM,TS,TA>::subdomain_vector Vector;
566 typedef typename Vector::value_type Subdomain;
567
568 virtual void setMatrix(const M& matrix, const AggregatesMap& amap)
569 {
570 Father::setMatrix(matrix);
571
572 std::vector<bool> visited(amap.noVertices(), false);
573 typedef IteratorPropertyMap<std::vector<bool>::iterator,IdentityMap> VisitedMapType;
574 VisitedMapType visitedMap(visited.begin());
575
576 MatrixGraph<const M> graph(matrix);
577
578 typedef SeqOverlappingSchwarzSmootherArgs<typename M::field_type> SmootherArgs;
579
580 switch(Father::getArgs().overlap) {
581 case SmootherArgs::vertex :
582 {
583 VertexAdder visitor(subdomains, amap);
584 createSubdomains(matrix, graph, amap, visitor, visitedMap);
585 }
586 break;
587 case SmootherArgs::pairwise :
588 {
589 createPairDomains(graph);
590 }
591 break;
592 case SmootherArgs::aggregate :
593 {
594 AggregateAdder<VisitedMapType> visitor(subdomains, amap, graph, visitedMap);
595 createSubdomains(matrix, graph, amap, visitor, visitedMap);
596 }
597 break;
598 case SmootherArgs::none :
599 NoneAdder visitor;
600 createSubdomains(matrix, graph, amap, visitor, visitedMap);
601 break;
602 default :
603 DUNE_THROW(NotImplemented, "This overlapping scheme is not supported!");
604 }
605 }
606 void setMatrix(const M& matrix)
607 {
608 Father::setMatrix(matrix);
609
610 /* Create aggregates map where each aggregate is just one vertex. */
611 AggregatesMap amap(matrix.N());
612 VertexDescriptor v=0;
613 for(typename AggregatesMap::iterator iter=amap.begin();
614 iter!=amap.end(); ++iter)
615 *iter=v++;
616
617 std::vector<bool> visited(amap.noVertices(), false);
618 typedef IteratorPropertyMap<std::vector<bool>::iterator,IdentityMap> VisitedMapType;
619 VisitedMapType visitedMap(visited.begin());
620
621 MatrixGraph<const M> graph(matrix);
622
623 typedef SeqOverlappingSchwarzSmootherArgs<typename M::field_type> SmootherArgs;
624
625 switch(Father::getArgs().overlap) {
626 case SmootherArgs::vertex :
627 {
628 VertexAdder visitor(subdomains, amap);
629 createSubdomains(matrix, graph, amap, visitor, visitedMap);
630 }
631 break;
632 case SmootherArgs::aggregate :
633 {
634 DUNE_THROW(NotImplemented, "Aggregate overlap is not supported yet");
635 /*
636 AggregateAdder<VisitedMapType> visitor(subdomains, amap, graph, visitedMap);
637 createSubdomains(matrix, graph, amap, visitor, visitedMap);
638 */
639 }
640 break;
641 case SmootherArgs::pairwise :
642 {
643 createPairDomains(graph);
644 }
645 break;
646 case SmootherArgs::none :
647 NoneAdder visitor;
648 createSubdomains(matrix, graph, amap, visitor, visitedMap);
649
650 }
651 }
652
653 const Vector& getSubDomains()
654 {
655 return subdomains;
656 }
657
658 private:
659 struct VertexAdder
660 {
661 VertexAdder(Vector& subdomains_, const AggregatesMap& aggregates_)
662 : subdomains(subdomains_), max(-1), subdomain(-1), aggregates(aggregates_)
663 {}
664 template<class T>
665 void operator()(const T& edge)
666 {
667 if(aggregates[edge.target()]!=AggregatesMap::ISOLATED)
668 subdomains[subdomain].insert(edge.target());
669 }
670 int setAggregate(const AggregateDescriptor& aggregate_)
671 {
672 subdomain=aggregate_;
673 max = std::max(subdomain, aggregate_);
674 return subdomain;
675 }
676 int noSubdomains() const
677 {
678 return max+1;
679 }
680 private:
681 Vector& subdomains;
682 AggregateDescriptor max;
683 AggregateDescriptor subdomain;
684 const AggregatesMap& aggregates;
685 };
686 struct NoneAdder
687 {
688 template<class T>
689 void operator()(const T& /*edge*/)
690 {}
691 int setAggregate(const AggregateDescriptor& /*aggregate_*/)
692 {
693 return -1;
694 }
695 int noSubdomains() const
696 {
697 return -1;
698 }
699 };
700
701 template<class VM>
702 struct AggregateAdder
703 {
704 AggregateAdder(Vector& subdomains_, const AggregatesMap& aggregates_,
705 const MatrixGraph<const M>& graph_, VM& visitedMap_)
706 : subdomains(subdomains_), subdomain(-1), aggregates(aggregates_),
707 adder(subdomains_, aggregates_), graph(graph_), visitedMap(visitedMap_)
708 {}
709 template<class T>
710 void operator()(const T& edge)
711 {
712 subdomains[subdomain].insert(edge.target());
713 // If we (the neighbouring vertex of the aggregate)
714 // are not isolated, add the aggregate we belong to
715 // to the same subdomain using the OneOverlapAdder
716 if(aggregates[edge.target()]!=AggregatesMap::ISOLATED) {
717 assert(aggregates[edge.target()]!=aggregate);
718 typename AggregatesMap::VertexList vlist;
719 aggregates.template breadthFirstSearch<true,false>(edge.target(), aggregate,
720 graph, vlist, adder, adder,
721 visitedMap);
722 }
723 }
724
725 int setAggregate(const AggregateDescriptor& aggregate_)
726 {
727 adder.setAggregate(aggregate_);
728 aggregate=aggregate_;
729 return ++subdomain;
730 }
731 int noSubdomains() const
732 {
733 return subdomain+1;
734 }
735
736 private:
737 AggregateDescriptor aggregate;
738 Vector& subdomains;
739 int subdomain;
740 const AggregatesMap& aggregates;
741 VertexAdder adder;
742 const MatrixGraph<const M>& graph;
743 VM& visitedMap;
744 };
745
746 void createPairDomains(const MatrixGraph<const M>& graph)
747 {
748 typedef typename MatrixGraph<const M>::ConstVertexIterator VIter;
749 typedef typename MatrixGraph<const M>::ConstEdgeIterator EIter;
750 typedef typename M::size_type size_type;
751
752 std::set<std::pair<size_type,size_type> > pairs;
753 int total=0;
754 for(VIter v=graph.begin(), ve=graph.end(); ve != v; ++v)
755 for(EIter e = v.begin(), ee=v.end(); ee!=e; ++e)
756 {
757 ++total;
758 if(e.source()<e.target())
759 pairs.insert(std::make_pair(e.source(),e.target()));
760 else
761 pairs.insert(std::make_pair(e.target(),e.source()));
762 }
763
764
765 subdomains.resize(pairs.size());
766 Dune::dinfo <<std::endl<< "Created "<<pairs.size()<<" ("<<total<<") pair domains"<<std::endl<<std::endl;
767 typedef typename std::set<std::pair<size_type,size_type> >::const_iterator SIter;
768 typename Vector::iterator subdomain=subdomains.begin();
769
770 for(SIter s=pairs.begin(), se =pairs.end(); se!=s; ++s)
771 {
772 subdomain->insert(s->first);
773 subdomain->insert(s->second);
774 ++subdomain;
775 }
776 std::size_t minsize=10000;
777 std::size_t maxsize=0;
778 int sum=0;
779 for(typename Vector::size_type i=0; i < subdomains.size(); ++i) {
780 sum+=subdomains[i].size();
781 minsize=std::min(minsize, subdomains[i].size());
782 maxsize=std::max(maxsize, subdomains[i].size());
783 }
784 Dune::dinfo<<"Subdomain size: min="<<minsize<<" max="<<maxsize<<" avg="<<(sum/subdomains.size())
785 <<" no="<<subdomains.size()<<std::endl;
786 }
787
788 template<class Visitor>
789 void createSubdomains(const M& /*matrix*/, const MatrixGraph<const M>& graph,
790 const AggregatesMap& amap, Visitor& overlapVisitor,
791 IteratorPropertyMap<std::vector<bool>::iterator,IdentityMap>& visitedMap )
792 {
793 // count number ag aggregates. We assume that the
794 // aggregates are numbered consecutively from 0 except
795 // for the isolated ones. All isolated vertices form
796 // one aggregate, here.
797 int isolated=0;
798 AggregateDescriptor maxAggregate=0;
799
800 for(std::size_t i=0; i < amap.noVertices(); ++i)
801 if(amap[i]==AggregatesMap::ISOLATED)
802 isolated++;
803 else
804 maxAggregate = std::max(maxAggregate, amap[i]);
805
806 subdomains.resize(maxAggregate+1+isolated);
807
808 // reset the subdomains
809 for(typename Vector::size_type i=0; i < subdomains.size(); ++i)
810 subdomains[i].clear();
811
812 // Create the subdomains from the aggregates mapping.
813 // For each aggregate we mark all entries and the
814 // neighbouring vertices as belonging to the same subdomain
815 VertexAdder aggregateVisitor(subdomains, amap);
816
817 for(VertexDescriptor i=0; i < amap.noVertices(); ++i)
818 if(!get(visitedMap, i)) {
819 AggregateDescriptor aggregate=amap[i];
820
821 if(amap[i]==AggregatesMap::ISOLATED) {
822 // isolated vertex gets its own aggregate
823 subdomains.push_back(Subdomain());
824 aggregate=subdomains.size()-1;
825 }
826 overlapVisitor.setAggregate(aggregate);
827 aggregateVisitor.setAggregate(aggregate);
828 subdomains[aggregate].insert(i);
829 typename AggregatesMap::VertexList vlist;
830 amap.template breadthFirstSearch<false,false>(i, aggregate, graph, vlist, aggregateVisitor,
831 overlapVisitor, visitedMap);
832 }
833
834 std::size_t minsize=10000;
835 std::size_t maxsize=0;
836 int sum=0;
837 for(typename Vector::size_type i=0; i < subdomains.size(); ++i) {
838 sum+=subdomains[i].size();
839 minsize=std::min(minsize, subdomains[i].size());
840 maxsize=std::max(maxsize, subdomains[i].size());
841 }
842 Dune::dinfo<<"Subdomain size: min="<<minsize<<" max="<<maxsize<<" avg="<<(sum/subdomains.size())
843 <<" no="<<subdomains.size()<<" isolated="<<isolated<<std::endl;
844
845
846
847 }
848 Vector subdomains;
849 };
850
851
852 template<class M, class X, class TM, class TS, class TA>
853 struct ConstructionTraits<SeqOverlappingSchwarz<M,X,TM,TS,TA> >
854 {
855 typedef ConstructionArgs<SeqOverlappingSchwarz<M,X,TM,TS,TA> > Arguments;
856
857 static inline std::shared_ptr<SeqOverlappingSchwarz<M,X,TM,TS,TA>> construct(Arguments& args)
858 {
859 return std::make_shared<SeqOverlappingSchwarz<M,X,TM,TS,TA>>
860 (args.getMatrix(),
861 args.getSubDomains(),
862 args.getArgs().relaxationFactor,
863 args.getArgs().onthefly);
864 }
865 };
866
867
868 } // namespace Amg
869 } // namespace Dune
870
871
872
873 #endif