2 #ifndef DUNE_AMG_INDICESCOARSENER_HH
3 #define DUNE_AMG_INDICESCOARSENER_HH
5 #include<dune/common/parallel/indicessyncer.hh>
31 template<
typename T,
typename E>
39 template<
typename T,
typename E>
63 typedef typename ParallelIndexSet::LocalIndex
LocalIndex;
86 template<
typename Graph,
typename VM>
87 static typename Graph::VertexDescriptor
95 template<
typename G,
typename I>
98 typedef typename G::VertexDescriptor Vertex;
100 typedef I GlobalLookupIndexSet;
102 typedef typename GlobalLookupIndexSet::IndexPair IndexPair;
104 typedef typename IndexPair::GlobalIndex
GlobalIndex;
109 globalIndex_(std::numeric_limits<GlobalIndex>::max())
113 void operator()(
const typename G::ConstEdgeIterator& edge)
116 const IndexPair* pair= lookup_.pair(edge.target());
118 globalIndex(pair->global());
119 attribute(pair->local().attribute());
120 isPublic(pair->local().isPublic());
124 Vertex operator()(
const GlobalIndex& global)
126 Vertex current = this->
number_;
136 void isPublic(
bool b)
138 isPublic_ = isPublic_ || b;
143 globalIndex_ = std::numeric_limits<GlobalIndex>::max();
149 attribute_=attribute;
157 const GlobalIndex& globalIndex()
const
162 void globalIndex(
const GlobalIndex& global)
164 globalIndex_ = global;
170 const GlobalLookupIndexSet& lookup_;
174 template<
typename Graph,
typename VM,
typename I>
180 ParallelAggregateRenumberer<Graph,I>& renumberer);
182 template<
typename Graph,
typename I>
183 static void buildCoarseRemoteIndices(
const RemoteIndices& fineRemote,
187 ParallelAggregateRenumberer<Graph,I>& renumberer);
194 template<
typename G,
typename L,
typename E>
212 template<
typename Graph,
typename VM>
213 static typename Graph::VertexDescriptor
222 template<
typename T,
typename E>
223 template<
typename Graph,
typename VM>
224 inline typename Graph::VertexDescriptor
231 ParallelAggregateRenumberer<Graph,typename ParallelInformation::GlobalLookupIndexSet> renumberer(aggregates, fineInfo.globalLookup());
232 buildCoarseIndexSet(fineInfo, fineGraph, visitedMap, aggregates,
233 coarseInfo.indexSet(), renumberer);
234 buildCoarseRemoteIndices(fineInfo.remoteIndices(), aggregates, coarseInfo.indexSet(),
235 coarseInfo.remoteIndices(), renumberer);
240 template<
typename T,
typename E>
241 template<
typename Graph,
typename VM,
typename I>
247 ParallelAggregateRenumberer<Graph,I>& renumberer)
251 typedef typename Graph::ConstVertexIterator Iterator;
252 typedef typename ParallelInformation::GlobalLookupIndexSet GlobalLookupIndexSet;
254 Iterator end = fineGraph.end();
255 const GlobalLookupIndexSet& lookup = pinfo.globalLookup();
257 coarseIndices.beginResize();
268 if(!
get(visitedMap, *
index)){
270 typedef typename GlobalLookupIndexSet::IndexPair IndexPair;
271 const IndexPair* pair= lookup.pair(*
index);
278 assert(!ExcludedAttributes::contains(pair->local().attribute()));
279 renumberer.attribute(pair->local().attribute());
280 renumberer.isPublic(pair->local().isPublic());
281 renumberer.globalIndex(pair->global());
285 aggregates.template breadthFirstSearch<false>(*
index, aggregates[*
index],
286 fineGraph, renumberer, visitedMap);
288 typedef typename GlobalLookupIndexSet::IndexPair::GlobalIndex
GlobalIndex;
290 if(renumberer.globalIndex()!=std::numeric_limits<GlobalIndex>::max()){
293 coarseIndices.add(renumberer.globalIndex(),
294 LocalIndex(renumberer, renumberer.attribute(),
295 renumberer.isPublic()));
298 aggregates[*
index] = renumberer;
303 coarseIndices.endResize();
305 assert(static_cast<std::size_t>(renumberer) >= coarseIndices.size());
308 for(Iterator vertex=fineGraph.begin(); vertex != end; ++vertex)
309 put(visitedMap, *vertex,
false);
312 template<
typename T,
typename E>
313 template<
typename Graph,
typename I>
318 ParallelAggregateRenumberer<Graph,I>& renumberer)
320 std::vector<char> attributes(static_cast<std::size_t>(renumberer));
322 GlobalLookupIndexSet<ParallelIndexSet> coarseLookup(coarseIndices, static_cast<std::size_t>(renumberer));
324 typedef typename RemoteIndices::const_iterator Iterator;
325 Iterator end = fineRemote.end();
327 for(Iterator neighbour = fineRemote.begin();
328 neighbour != end; ++neighbour){
329 int process = neighbour->first;
331 assert(neighbour->second.first==neighbour->second.second);
334 typedef typename std::vector<char>::iterator CIterator;
336 for(CIterator iter=attributes.begin(); iter!= attributes.end(); ++iter)
337 *iter = std::numeric_limits<char>::max();
339 typedef typename RemoteIndices::RemoteIndexList::const_iterator Iterator;
340 Iterator riEnd = neighbour->second.second->end();
342 for(Iterator
index = neighbour->second.second->begin();
344 if(!E::contains(
index->localIndexPair().local().attribute()) &&
345 aggregates[
index->localIndexPair().local()] !=
348 assert(aggregates[
index->localIndexPair().local()]<attributes.size());
349 if (attributes[aggregates[
index->localIndexPair().local()]] != 3)
350 attributes[aggregates[
index->localIndexPair().local()]] =
index->attribute();
355 typedef RemoteIndexListModifier<ParallelIndexSet,typename RemoteIndices::Allocator,false> Modifier;
356 typedef typename RemoteIndices::RemoteIndex RemoteIndex;
357 typedef typename ParallelIndexSet::const_iterator IndexIterator;
359 Modifier coarseList = coarseRemote.template getModifier<false,true>(process);
361 IndexIterator iend = coarseIndices.end();
362 for(IndexIterator
index = coarseIndices.begin();
index != iend; ++
index)
363 if(attributes[
index->local()] != std::numeric_limits<char>::max()){
371 assert(coarseRemote.neighbours()==fineRemote.neighbours());
375 IndicesSyncer<ParallelIndexSet> syncer(coarseIndices, coarseRemote);
376 syncer.sync(renumberer);
383 template<
typename Graph,
typename VM>
384 typename Graph::VertexDescriptor
391 typedef typename Graph::VertexDescriptor Vertex;
393 typedef typename Graph::VertexIterator Iterator;
395 for(Iterator vertex=fineGraph.begin(), endVertex=fineGraph.end();
396 vertex != endVertex; ++vertex)
398 !
get(visitedMap, *vertex)){
400 aggregates.template breadthFirstSearch<false>(*vertex, aggregates[*vertex],
401 fineGraph, renumberer, visitedMap);
402 aggregates[*vertex] = renumberer;
406 for(Iterator vertex=fineGraph.begin(), endVertex=fineGraph.end();
407 vertex != endVertex; ++vertex)
408 put(visitedMap, *vertex,
false);