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>
246 ParallelIndexSet& coarseIndices,
247 ParallelAggregateRenumberer<Graph,I>& renumberer)
251 typedef typename Graph::VertexDescriptor Vertex;
252 typedef typename Graph::ConstVertexIterator Iterator;
253 typedef typename ParallelInformation::GlobalLookupIndexSet GlobalLookupIndexSet;
255 Iterator end = fineGraph.end();
256 const GlobalLookupIndexSet& lookup = pinfo.globalLookup();
258 coarseIndices.beginResize();
269 if(!
get(visitedMap, *
index)){
271 typedef typename GlobalLookupIndexSet::IndexPair IndexPair;
272 const IndexPair* pair= lookup.pair(*
index);
279 assert(!ExcludedAttributes::contains(pair->local().attribute()));
280 renumberer.attribute(pair->local().attribute());
281 renumberer.isPublic(pair->local().isPublic());
282 renumberer.globalIndex(pair->global());
286 aggregates.template breadthFirstSearch<false>(*
index, aggregates[*
index],
287 fineGraph, renumberer, visitedMap);
289 typedef typename GlobalLookupIndexSet::IndexPair::GlobalIndex GlobalIndex;
291 if(renumberer.globalIndex()!=std::numeric_limits<GlobalIndex>::max()){
294 coarseIndices.add(renumberer.globalIndex(),
295 LocalIndex(renumberer, renumberer.attribute(),
296 renumberer.isPublic()));
299 aggregates[*
index] = renumberer;
304 coarseIndices.endResize();
306 assert(static_cast<std::size_t>(renumberer) >= coarseIndices.size());
309 for(Iterator vertex=fineGraph.begin(); vertex != end; ++vertex)
310 put(visitedMap, *vertex,
false);
313 template<
typename T,
typename E>
314 template<
typename Graph,
typename I>
315 void ParallelIndicesCoarsener<T,E>::buildCoarseRemoteIndices(
const RemoteIndices& fineRemote,
316 const AggregatesMap<typename Graph::VertexDescriptor>& aggregates,
317 ParallelIndexSet& coarseIndices,
318 RemoteIndices& coarseRemote,
319 ParallelAggregateRenumberer<Graph,I>& renumberer)
321 std::vector<char> attributes(static_cast<std::size_t>(renumberer));
323 GlobalLookupIndexSet<ParallelIndexSet> coarseLookup(coarseIndices, static_cast<std::size_t>(renumberer));
325 typedef typename RemoteIndices::const_iterator Iterator;
326 Iterator end = fineRemote.end();
328 for(Iterator neighbour = fineRemote.begin();
329 neighbour != end; ++neighbour){
330 int process = neighbour->first;
332 assert(neighbour->second.first==neighbour->second.second);
335 typedef typename std::vector<char>::iterator CIterator;
337 for(CIterator iter=attributes.begin(); iter!= attributes.end(); ++iter)
338 *iter = std::numeric_limits<char>::max();
340 typedef typename RemoteIndices::RemoteIndexList::const_iterator Iterator;
341 Iterator riEnd = neighbour->second.second->end();
343 for(Iterator index = neighbour->second.second->begin();
344 index != riEnd; ++
index){
345 if(!E::contains(index->localIndexPair().local().attribute()) &&
346 aggregates[index->localIndexPair().local()] !=
347 AggregatesMap<typename Graph::VertexDescriptor>::ISOLATED)
349 assert(aggregates[index->localIndexPair().local()]<attributes.size());
350 if (attributes[aggregates[index->localIndexPair().local()]] != 3)
351 attributes[aggregates[index->localIndexPair().local()]] = index->attribute();
356 typedef RemoteIndexListModifier<ParallelIndexSet,typename RemoteIndices::Allocator,false> Modifier;
357 typedef typename RemoteIndices::RemoteIndex RemoteIndex;
358 typedef typename ParallelIndexSet::const_iterator IndexIterator;
360 Modifier coarseList = coarseRemote.template getModifier<false,true>(process);
362 IndexIterator iend = coarseIndices.end();
363 for(IndexIterator index = coarseIndices.begin(); index != iend; ++
index)
364 if(attributes[index->local()] != std::numeric_limits<char>::max()){
366 coarseList.insert(RemoteIndex(Attribute(attributes[index->local()]), &(*index)));
372 assert(coarseRemote.neighbours()==fineRemote.neighbours());
376 IndicesSyncer<ParallelIndexSet> syncer(coarseIndices, coarseRemote);
377 syncer.sync(renumberer);
384 template<
typename Graph,
typename VM>
385 typename Graph::VertexDescriptor
392 typedef typename Graph::VertexDescriptor Vertex;
394 typedef typename Graph::VertexIterator Iterator;
396 for(Iterator vertex=fineGraph.begin(), endVertex=fineGraph.end();
397 vertex != endVertex; ++vertex)
399 !
get(visitedMap, *vertex)){
401 aggregates.template breadthFirstSearch<false>(*vertex, aggregates[*vertex],
402 fineGraph, renumberer, visitedMap);
403 aggregates[*vertex] = renumberer;
407 for(Iterator vertex=fineGraph.begin(), endVertex=fineGraph.end();
408 vertex != endVertex; ++vertex)
409 put(visitedMap, *vertex,
false);