dune-istl  2.7.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 #include <dune/common/unused.hh>
20 
21 namespace Dune
22 {
23  namespace Amg
24  {
25 
26  template<typename T, typename TI>
28  {
29  public:
30  typedef TI ParallelIndexSet;
31 
32  typedef typename ParallelIndexSet::GlobalIndex GlobalIndex;
33 
34  typedef typename ParallelIndexSet::GlobalIndex IndexedType;
35 
36  typedef typename ParallelIndexSet::LocalIndex LocalIndex;
37 
38  typedef T Vertex;
39 
41  const GlobalLookupIndexSet<ParallelIndexSet>& indexset)
42  : aggregates_(aggregates), indexset_(indexset)
43  {}
44 
45  inline const GlobalIndex& operator[](std::size_t index) const
46  {
47  const Vertex& aggregate = aggregates_[index];
48  if(aggregate >= AggregatesMap<Vertex>::ISOLATED) {
49  assert(aggregate != AggregatesMap<Vertex>::UNAGGREGATED);
50  return isolatedMarker;
51  }else{
52  const Dune::IndexPair<GlobalIndex,LocalIndex >* pair = indexset_.pair(aggregate);
53  assert(pair!=0);
54  return pair->global();
55  }
56  }
57 
58 
59  inline GlobalIndex& get(std::size_t index)
60  {
61  const Vertex& aggregate = aggregates_[index];
62  assert(aggregate < AggregatesMap<Vertex>::ISOLATED);
63  const Dune::IndexPair<GlobalIndex,LocalIndex >* pair = indexset_.pair(aggregate);
64  assert(pair!=0);
65  return const_cast<GlobalIndex&>(pair->global());
66  }
67 
68  class Proxy
69  {
70  public:
71  Proxy(const GlobalLookupIndexSet<ParallelIndexSet>& indexset, Vertex& aggregate)
72  : indexset_(&indexset), aggregate_(&aggregate)
73  {}
74 
75  Proxy& operator=(const GlobalIndex& global)
76  {
77  if(global==isolatedMarker)
78  *aggregate_ = AggregatesMap<Vertex>::ISOLATED;
79  else{
80  //assert(global < AggregatesMap<Vertex>::ISOLATED);
81  *aggregate_ = indexset_->operator[](global).local();
82  }
83  return *this;
84  }
85  private:
86  const GlobalLookupIndexSet<ParallelIndexSet>* indexset_;
87  Vertex* aggregate_;
88  };
89 
90  inline Proxy operator[](std::size_t index)
91  {
92  return Proxy(indexset_, aggregates_[index]);
93  }
94 
95  inline void put(const GlobalIndex& global, size_t i)
96  {
97  aggregates_[i]=indexset_[global].local();
98 
99  }
100 
101  private:
102  AggregatesMap<Vertex>& aggregates_;
103  const GlobalLookupIndexSet<ParallelIndexSet>& indexset_;
104  static const GlobalIndex isolatedMarker;
105  };
106 
107  template<typename T, typename TI>
108  const typename TI::GlobalIndex GlobalAggregatesMap<T,TI>::isolatedMarker =
109  std::numeric_limits<typename TI::GlobalIndex>::max();
110 
111  template<typename T, typename TI>
113  {
114  typedef TI ParallelIndexSet;
115  typedef typename ParallelIndexSet::GlobalIndex GlobalIndex;
116 
117  static const GlobalIndex& gather(const GlobalAggregatesMap<T,TI>& ga, size_t i)
118  {
119  return ga[i];
120  }
121 
122  static void scatter(GlobalAggregatesMap<T,TI>& ga, GlobalIndex global, size_t i)
123  {
124  ga[i]=global;
125  }
126  };
127 
128  template<typename T, typename O, typename I>
130  {};
131 
132 #if HAVE_MPI
133 
134 #endif
135 
136  } // namespace Amg
137 
138 #if HAVE_MPI
139  // forward declaration
140  template<class T1, class T2>
141  class OwnerOverlapCopyCommunication;
142 #endif
143 
144  namespace Amg
145  {
146 
147 #if HAVE_MPI
148 
157  template<typename T, typename O, typename T1, typename T2>
158  struct AggregatesPublisher<T,O,OwnerOverlapCopyCommunication<T1,T2> >
159  {
160  typedef T Vertex;
161  typedef O OverlapFlags;
162  typedef OwnerOverlapCopyCommunication<T1,T2> ParallelInformation;
163  typedef typename ParallelInformation::GlobalLookupIndexSet GlobalLookupIndexSet;
164  typedef typename ParallelInformation::ParallelIndexSet IndexSet;
165 
166  static void publish(AggregatesMap<Vertex>& aggregates,
167  ParallelInformation& pinfo,
168  const GlobalLookupIndexSet& globalLookup)
169  {
171  GlobalMap gmap(aggregates, globalLookup);
172  pinfo.copyOwnerToAll(gmap,gmap);
173  // communication only needed for ALU
174  // (ghosts with same global id as owners on the same process)
175  if (SolverCategory::category(pinfo) == static_cast<int>(SolverCategory::nonoverlapping))
176  pinfo.copyCopyToAll(gmap,gmap);
177 
178  typedef typename ParallelInformation::RemoteIndices::const_iterator Lists;
179  Lists lists = pinfo.remoteIndices().find(pinfo.communicator().rank());
180  if(lists!=pinfo.remoteIndices().end()) {
181 
182  // For periodic boundary conditions we must renumber
183  // the aggregates of vertices in the overlap whose owners are
184  // on the same process
185  Vertex maxAggregate =0;
186  typedef typename AggregatesMap<Vertex>::const_iterator Iter;
187  for(Iter i=aggregates.begin(), end=aggregates.end(); i!=end; ++i)
188  maxAggregate = std::max(maxAggregate, *i);
189 
190  // Compute new mapping of aggregates in the overlap that we also own
191  std::map<Vertex,Vertex> newMapping;
192 
193  // insert all elements into map
194  typedef typename ParallelInformation::RemoteIndices::RemoteIndexList
195  ::const_iterator RIter;
196  for(RIter ri=lists->second.first->begin(), rend = lists->second.first->end();
197  ri!=rend; ++ri)
198  if(O::contains(ri->localIndexPair().local().attribute()))
199  newMapping.insert(std::make_pair(aggregates[ri->localIndexPair().local()],
200  maxAggregate));
201  // renumber
202  typedef typename std::map<Vertex,Vertex>::iterator MIter;
203  for(MIter mi=newMapping.begin(), mend=newMapping.end();
204  mi != mend; ++mi)
205  mi->second=++maxAggregate;
206 
207 
208  for(RIter ri=lists->second.first->begin(), rend = lists->second.first->end();
209  ri!=rend; ++ri)
210  if(O::contains(ri->localIndexPair().local().attribute()))
211  aggregates[ri->localIndexPair().local()] =
212  newMapping[aggregates[ri->localIndexPair().local()]];
213  }
214  }
215  };
216 #endif
217 
218  template<typename T, typename O>
220  {
221  typedef T Vertex;
224 
225  static void publish(AggregatesMap<Vertex>& aggregates,
226  ParallelInformation& pinfo,
227  const GlobalLookupIndexSet& globalLookup)
228  {
229  DUNE_UNUSED_PARAMETER(aggregates);
230  DUNE_UNUSED_PARAMETER(pinfo);
231  DUNE_UNUSED_PARAMETER(globalLookup);
232  }
233  };
234 
235  } // end Amg namespace
236 
237 
238 #if HAVE_MPI
239  template<typename T, typename TI>
240  struct CommPolicy<Amg::GlobalAggregatesMap<T,TI> >
241  {
242  typedef Amg::AggregatesMap<T> Type;
243  typedef typename Amg::GlobalAggregatesMap<T,TI>::IndexedType IndexedType;
244  typedef SizeOne IndexedTypeFlag;
245  static int getSize(const Type&, int)
246  {
247  return 1;
248  }
249  };
250 #endif
251 
252 } // end Dune namespace
253  /* @} */
254 #endif
Dune::Amg::AggregatesGatherScatter::GlobalIndex
ParallelIndexSet::GlobalIndex GlobalIndex
Definition: globalaggregates.hh:115
Dune::Amg::GlobalAggregatesMap::IndexedType
ParallelIndexSet::GlobalIndex IndexedType
Definition: globalaggregates.hh:34
aggregates.hh
Provides classes for the Coloring process of AMG.
Dune::Amg::AggregatesPublisher< T, O, SequentialInformation >::publish
static void publish(AggregatesMap< Vertex > &aggregates, ParallelInformation &pinfo, const GlobalLookupIndexSet &globalLookup)
Definition: globalaggregates.hh:225
Dune::Amg::AggregatesGatherScatter::ParallelIndexSet
TI ParallelIndexSet
Definition: globalaggregates.hh:114
Dune::Amg::GlobalAggregatesMap::Vertex
T Vertex
Definition: globalaggregates.hh:38
pinfo.hh
Dune::Amg::AggregatesGatherScatter
Definition: globalaggregates.hh:112
Dune::Amg::AggregatesMap< Vertex >::const_iterator
const typedef AggregateDescriptor * const_iterator
Definition: aggregates.hh:721
Dune::Amg::GlobalAggregatesMap::ParallelIndexSet
TI ParallelIndexSet
Definition: globalaggregates.hh:30
Dune::Amg::GlobalAggregatesMap::Proxy
Definition: globalaggregates.hh:68
Dune::Amg::GlobalAggregatesMap::LocalIndex
ParallelIndexSet::LocalIndex LocalIndex
Definition: globalaggregates.hh:36
Dune::SolverCategory::nonoverlapping
@ nonoverlapping
Category for non-overlapping solvers.
Definition: solvercategory.hh:25
Dune::Amg::SequentialInformation::GlobalLookupIndexSet
int GlobalLookupIndexSet
Definition: pinfo.hh:58
Dune::Amg::GlobalAggregatesMap::GlobalIndex
ParallelIndexSet::GlobalIndex GlobalIndex
Definition: globalaggregates.hh:32
Dune::Amg::GlobalAggregatesMap::operator[]
const GlobalIndex & operator[](std::size_t index) const
Definition: globalaggregates.hh:45
Dune::Amg::GlobalAggregatesMap::Proxy::Proxy
Proxy(const GlobalLookupIndexSet< ParallelIndexSet > &indexset, Vertex &aggregate)
Definition: globalaggregates.hh:71
Dune
Definition: allocator.hh:7
Dune::Amg::AggregatesMap< Vertex >
Dune::Amg::AggregatesGatherScatter::scatter
static void scatter(GlobalAggregatesMap< T, TI > &ga, GlobalIndex global, size_t i)
Definition: globalaggregates.hh:122
Dune::Amg::SequentialInformation
Definition: pinfo.hh:25
Dune::Amg::GlobalAggregatesMap::Proxy::operator=
Proxy & operator=(const GlobalIndex &global)
Definition: globalaggregates.hh:75
Dune::Amg::GlobalAggregatesMap::operator[]
Proxy operator[](std::size_t index)
Definition: globalaggregates.hh:90
Dune::Amg::AggregatesPublisher< T, O, SequentialInformation >::ParallelInformation
SequentialInformation ParallelInformation
Definition: globalaggregates.hh:222
Dune::Amg::GlobalAggregatesMap::put
void put(const GlobalIndex &global, size_t i)
Definition: globalaggregates.hh:95
Dune::Amg::GlobalAggregatesMap::GlobalAggregatesMap
GlobalAggregatesMap(AggregatesMap< Vertex > &aggregates, const GlobalLookupIndexSet< ParallelIndexSet > &indexset)
Definition: globalaggregates.hh:40
Dune::SolverCategory::category
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
Dune::Amg::AggregatesPublisher< T, O, SequentialInformation >::GlobalLookupIndexSet
ParallelInformation::GlobalLookupIndexSet GlobalLookupIndexSet
Definition: globalaggregates.hh:223
Dune::Amg::GlobalAggregatesMap::get
GlobalIndex & get(std::size_t index)
Definition: globalaggregates.hh:59
Dune::Amg::AggregatesPublisher< T, O, SequentialInformation >::Vertex
T Vertex
Definition: globalaggregates.hh:221
Dune::Amg::AggregatesPublisher
Definition: globalaggregates.hh:129
Dune::Amg::GlobalAggregatesMap
Definition: globalaggregates.hh:27
Dune::Amg::AggregatesGatherScatter::gather
static const GlobalIndex & gather(const GlobalAggregatesMap< T, TI > &ga, size_t i)
Definition: globalaggregates.hh:117