dune-istl  2.8.0
globalaggregates.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_GLOBALAGGREGATES_HH
4 #define DUNE_GLOBALAGGREGATES_HH
5 
16 #include "aggregates.hh"
17 #include "pinfo.hh"
18 #include <dune/common/parallel/indexset.hh>
19 
20 namespace Dune
21 {
22  namespace Amg
23  {
24 
25  template<typename T, typename TI>
27  {
28  public:
29  typedef TI ParallelIndexSet;
30 
31  typedef typename ParallelIndexSet::GlobalIndex GlobalIndex;
32 
33  typedef typename ParallelIndexSet::GlobalIndex IndexedType;
34 
35  typedef typename ParallelIndexSet::LocalIndex LocalIndex;
36 
37  typedef T Vertex;
38 
40  const GlobalLookupIndexSet<ParallelIndexSet>& indexset)
41  : aggregates_(aggregates), indexset_(indexset)
42  {}
43 
44  inline const GlobalIndex& operator[](std::size_t index) const
45  {
46  const Vertex& aggregate = aggregates_[index];
47  if(aggregate >= AggregatesMap<Vertex>::ISOLATED) {
48  assert(aggregate != AggregatesMap<Vertex>::UNAGGREGATED);
49  return isolatedMarker;
50  }else{
51  const Dune::IndexPair<GlobalIndex,LocalIndex >* pair = indexset_.pair(aggregate);
52  assert(pair!=0);
53  return pair->global();
54  }
55  }
56 
57 
58  inline GlobalIndex& get(std::size_t index)
59  {
60  const Vertex& aggregate = aggregates_[index];
61  assert(aggregate < AggregatesMap<Vertex>::ISOLATED);
62  const Dune::IndexPair<GlobalIndex,LocalIndex >* pair = indexset_.pair(aggregate);
63  assert(pair!=0);
64  return const_cast<GlobalIndex&>(pair->global());
65  }
66 
67  class Proxy
68  {
69  public:
70  Proxy(const GlobalLookupIndexSet<ParallelIndexSet>& indexset, Vertex& aggregate)
71  : indexset_(&indexset), aggregate_(&aggregate)
72  {}
73 
74  Proxy& operator=(const GlobalIndex& global)
75  {
76  if(global==isolatedMarker)
77  *aggregate_ = AggregatesMap<Vertex>::ISOLATED;
78  else{
79  //assert(global < AggregatesMap<Vertex>::ISOLATED);
80  *aggregate_ = indexset_->operator[](global).local();
81  }
82  return *this;
83  }
84  private:
85  const GlobalLookupIndexSet<ParallelIndexSet>* indexset_;
86  Vertex* aggregate_;
87  };
88 
89  inline Proxy operator[](std::size_t index)
90  {
91  return Proxy(indexset_, aggregates_[index]);
92  }
93 
94  inline void put(const GlobalIndex& global, size_t i)
95  {
96  aggregates_[i]=indexset_[global].local();
97 
98  }
99 
100  private:
101  AggregatesMap<Vertex>& aggregates_;
102  const GlobalLookupIndexSet<ParallelIndexSet>& indexset_;
103  static const GlobalIndex isolatedMarker;
104  };
105 
106  template<typename T, typename TI>
107  const typename TI::GlobalIndex GlobalAggregatesMap<T,TI>::isolatedMarker =
108  std::numeric_limits<typename TI::GlobalIndex>::max();
109 
110  template<typename T, typename TI>
112  {
113  typedef TI ParallelIndexSet;
114  typedef typename ParallelIndexSet::GlobalIndex GlobalIndex;
115 
116  static const GlobalIndex& gather(const GlobalAggregatesMap<T,TI>& ga, size_t i)
117  {
118  return ga[i];
119  }
120 
121  static void scatter(GlobalAggregatesMap<T,TI>& ga, GlobalIndex global, size_t i)
122  {
123  ga[i]=global;
124  }
125  };
126 
127  template<typename T, typename O, typename I>
129  {};
130 
131 #if HAVE_MPI
132 
133 #endif
134 
135  } // namespace Amg
136 
137 #if HAVE_MPI
138  // forward declaration
139  template<class T1, class T2>
141 #endif
142 
143  namespace Amg
144  {
145 
146 #if HAVE_MPI
156  template<typename T, typename O, typename T1, typename T2>
158  {
159  typedef T Vertex;
160  typedef O OverlapFlags;
164 
165  static void publish(AggregatesMap<Vertex>& aggregates,
166  ParallelInformation& pinfo,
167  const GlobalLookupIndexSet& globalLookup)
168  {
170  GlobalMap gmap(aggregates, globalLookup);
171  pinfo.copyOwnerToAll(gmap,gmap);
172  // communication only needed for ALU
173  // (ghosts with same global id as owners on the same process)
174  if (SolverCategory::category(pinfo) == static_cast<int>(SolverCategory::nonoverlapping))
175  pinfo.copyCopyToAll(gmap,gmap);
176 
177  typedef typename ParallelInformation::RemoteIndices::const_iterator Lists;
178  Lists lists = pinfo.remoteIndices().find(pinfo.communicator().rank());
179  if(lists!=pinfo.remoteIndices().end()) {
180 
181  // For periodic boundary conditions we must renumber
182  // the aggregates of vertices in the overlap whose owners are
183  // on the same process
184  Vertex maxAggregate =0;
185  typedef typename AggregatesMap<Vertex>::const_iterator Iter;
186  for(Iter i=aggregates.begin(), end=aggregates.end(); i!=end; ++i)
187  maxAggregate = std::max(maxAggregate, *i);
188 
189  // Compute new mapping of aggregates in the overlap that we also own
190  std::map<Vertex,Vertex> newMapping;
191 
192  // insert all elements into map
193  typedef typename ParallelInformation::RemoteIndices::RemoteIndexList
194  ::const_iterator RIter;
195  for(RIter ri=lists->second.first->begin(), rend = lists->second.first->end();
196  ri!=rend; ++ri)
197  if(O::contains(ri->localIndexPair().local().attribute()))
198  newMapping.insert(std::make_pair(aggregates[ri->localIndexPair().local()],
199  maxAggregate));
200  // renumber
201  typedef typename std::map<Vertex,Vertex>::iterator MIter;
202  for(MIter mi=newMapping.begin(), mend=newMapping.end();
203  mi != mend; ++mi)
204  mi->second=++maxAggregate;
205 
206 
207  for(RIter ri=lists->second.first->begin(), rend = lists->second.first->end();
208  ri!=rend; ++ri)
209  if(O::contains(ri->localIndexPair().local().attribute()))
210  aggregates[ri->localIndexPair().local()] =
211  newMapping[aggregates[ri->localIndexPair().local()]];
212  }
213  }
214  };
215 #endif
216 
217  template<typename T, typename O>
219  {
220  typedef T Vertex;
223 
224  static void publish([[maybe_unused]] AggregatesMap<Vertex>& aggregates,
225  [[maybe_unused]] ParallelInformation& pinfo,
226  [[maybe_unused]] const GlobalLookupIndexSet& globalLookup)
227  {}
228  };
229 
230  } // end Amg namespace
231 
232 
233 #if HAVE_MPI
234  template<typename T, typename TI>
235  struct CommPolicy<Amg::GlobalAggregatesMap<T,TI> >
236  {
239  typedef SizeOne IndexedTypeFlag;
240  static int getSize(const Type&, int)
241  {
242  return 1;
243  }
244  };
245 #endif
246 
247 } // end Dune namespace
248  /* @} */
249 #endif
Provides classes for the Coloring process of AMG.
static const GlobalIndex & gather(const GlobalAggregatesMap< T, TI > &ga, size_t i)
Definition: globalaggregates.hh:116
ParallelInformation::GlobalLookupIndexSet GlobalLookupIndexSet
Definition: globalaggregates.hh:162
static void publish([[maybe_unused]] AggregatesMap< Vertex > &aggregates, [[maybe_unused]] ParallelInformation &pinfo, [[maybe_unused]] const GlobalLookupIndexSet &globalLookup)
Definition: globalaggregates.hh:224
static int getSize(const Type &, int)
Definition: globalaggregates.hh:240
GlobalIndex & get(std::size_t index)
Definition: globalaggregates.hh:58
Amg::GlobalAggregatesMap< T, TI >::IndexedType IndexedType
Definition: globalaggregates.hh:238
SequentialInformation ParallelInformation
Definition: globalaggregates.hh:221
ParallelIndexSet::GlobalIndex GlobalIndex
Definition: globalaggregates.hh:31
ParallelInformation::ParallelIndexSet IndexSet
Definition: globalaggregates.hh:163
void put(const GlobalIndex &global, size_t i)
Definition: globalaggregates.hh:94
T Vertex
Definition: globalaggregates.hh:37
GlobalAggregatesMap(AggregatesMap< Vertex > &aggregates, const GlobalLookupIndexSet< ParallelIndexSet > &indexset)
Definition: globalaggregates.hh:39
TI ParallelIndexSet
Definition: globalaggregates.hh:29
Amg::AggregatesMap< T > Type
Definition: globalaggregates.hh:237
static void scatter(GlobalAggregatesMap< T, TI > &ga, GlobalIndex global, size_t i)
Definition: globalaggregates.hh:121
OwnerOverlapCopyCommunication< T1, T2 > ParallelInformation
Definition: globalaggregates.hh:161
const_iterator begin() const
Definition: aggregates.hh:723
SizeOne IndexedTypeFlag
Definition: globalaggregates.hh:239
Proxy(const GlobalLookupIndexSet< ParallelIndexSet > &indexset, Vertex &aggregate)
Definition: globalaggregates.hh:70
const_iterator end() const
Definition: aggregates.hh:728
static void publish(AggregatesMap< Vertex > &aggregates, ParallelInformation &pinfo, const GlobalLookupIndexSet &globalLookup)
Definition: globalaggregates.hh:165
ParallelIndexSet::GlobalIndex GlobalIndex
Definition: globalaggregates.hh:114
ParallelIndexSet::LocalIndex LocalIndex
Definition: globalaggregates.hh:35
TI ParallelIndexSet
Definition: globalaggregates.hh:113
const GlobalIndex & operator[](std::size_t index) const
Definition: globalaggregates.hh:44
ParallelInformation::GlobalLookupIndexSet GlobalLookupIndexSet
Definition: globalaggregates.hh:222
Proxy & operator=(const GlobalIndex &global)
Definition: globalaggregates.hh:74
ParallelIndexSet::GlobalIndex IndexedType
Definition: globalaggregates.hh:33
Proxy operator[](std::size_t index)
Definition: globalaggregates.hh:89
Definition: allocator.hh:9
A class setting up standard communication for a two-valued attribute set with owner/overlap/copy sema...
Definition: owneroverlapcopy.hh:172
const CollectiveCommunication< MPI_Comm > & communicator() const
Definition: owneroverlapcopy.hh:297
void copyCopyToAll(const T &source, T &dest) const
Communicate values from copy data points to all other data points.
Definition: owneroverlapcopy.hh:326
Dune::GlobalLookupIndexSet< ParallelIndexSet > GlobalLookupIndexSet
The type of the reverse lookup of indices.
Definition: owneroverlapcopy.hh:454
const RemoteIndices & remoteIndices() const
Get the underlying remote indices.
Definition: owneroverlapcopy.hh:469
void copyOwnerToAll(const T &source, T &dest) const
Communicate values from owner data points to all other data points.
Definition: owneroverlapcopy.hh:309
Dune::ParallelIndexSet< GlobalIdType, LI, 512 > ParallelIndexSet
The type of the parallel index set.
Definition: owneroverlapcopy.hh:447
Definition: globalaggregates.hh:27
Definition: globalaggregates.hh:68
Definition: globalaggregates.hh:112
Definition: globalaggregates.hh:129
Definition: pinfo.hh:26
int GlobalLookupIndexSet
Definition: pinfo.hh:52
@ nonoverlapping
Category for non-overlapping solvers.
Definition: solvercategory.hh:25
static Category category(const OP &op, decltype(op.category()) *=nullptr)
Helperfunction to extract the solver category either from an enum, or from the newly introduced virtu...
Definition: solvercategory.hh:32