4 #ifndef DUNE_AMG_INDICESCOARSENER_HH
5 #define DUNE_AMG_INDICESCOARSENER_HH
7 #include <dune/common/parallel/indicessyncer.hh>
8 #include <dune/common/unused.hh>
34 template<
typename T,
typename E>
41 template<
typename T,
typename E>
65 typedef typename ParallelIndexSet::LocalIndex
LocalIndex;
88 template<
typename Graph,
typename VM>
89 static typename Graph::VertexDescriptor
95 typename Graph::VertexDescriptor noAggregates);
98 template<
typename G,
typename I>
101 typedef typename G::VertexDescriptor Vertex;
103 typedef I GlobalLookupIndexSet;
105 typedef typename GlobalLookupIndexSet::IndexPair IndexPair;
107 typedef typename IndexPair::GlobalIndex
GlobalIndex;
112 globalIndex_(std::numeric_limits<GlobalIndex>::max())
116 void operator()(
const typename G::ConstEdgeIterator& edge)
119 const IndexPair* pair= lookup_.pair(edge.target());
121 globalIndex(pair->global());
122 attribute(pair->local().attribute());
123 isPublic(pair->local().isPublic());
127 Vertex operator()(
const GlobalIndex& global)
129 DUNE_UNUSED_PARAMETER(global);
130 Vertex current = this->
number_;
140 void isPublic(
bool b)
142 isPublic_ = isPublic_ || b;
147 globalIndex_ = std::numeric_limits<GlobalIndex>::max();
153 attribute_=attribute;
161 const GlobalIndex& globalIndex()
const
166 void globalIndex(
const GlobalIndex& global)
168 globalIndex_ = global;
174 const GlobalLookupIndexSet& lookup_;
178 template<
typename Graph,
typename VM,
typename I>
184 ParallelAggregateRenumberer<Graph,I>& renumberer);
186 template<
typename Graph,
typename I>
187 static void buildCoarseRemoteIndices(
const RemoteIndices& fineRemote,
191 ParallelAggregateRenumberer<Graph,I>& renumberer);
198 template<
typename G,
typename L,
typename E>
216 template<
typename Graph,
typename VM>
217 static typename Graph::VertexDescriptor
223 typename Graph::VertexDescriptor noAggregates);
227 template<
typename T,
typename E>
228 template<
typename Graph,
typename VM>
229 inline typename Graph::VertexDescriptor
235 typename Graph::VertexDescriptor noAggregates)
237 DUNE_UNUSED_PARAMETER(noAggregates);
238 ParallelAggregateRenumberer<Graph,typename ParallelInformation::GlobalLookupIndexSet> renumberer(aggregates, fineInfo.globalLookup());
239 buildCoarseIndexSet(fineInfo, fineGraph, visitedMap, aggregates,
240 coarseInfo.indexSet(), renumberer);
241 buildCoarseRemoteIndices(fineInfo.remoteIndices(), aggregates, coarseInfo.indexSet(),
242 coarseInfo.remoteIndices(), renumberer);
247 template<
typename T,
typename E>
248 template<
typename Graph,
typename VM,
typename I>
253 ParallelIndexSet& coarseIndices,
254 ParallelAggregateRenumberer<Graph,I>& renumberer)
258 typedef typename Graph::ConstVertexIterator Iterator;
259 typedef typename ParallelInformation::GlobalLookupIndexSet GlobalLookupIndexSet;
261 Iterator end = fineGraph.end();
262 const GlobalLookupIndexSet& lookup = pinfo.globalLookup();
264 coarseIndices.beginResize();
275 if(!
get(visitedMap, *
index)) {
277 typedef typename GlobalLookupIndexSet::IndexPair IndexPair;
278 const IndexPair* pair= lookup.pair(*
index);
285 assert(!ExcludedAttributes::contains(pair->local().attribute()));
286 renumberer.attribute(pair->local().attribute());
287 renumberer.isPublic(pair->local().isPublic());
288 renumberer.globalIndex(pair->global());
292 aggregates.template breadthFirstSearch<false>(*
index, aggregates[*
index],
293 fineGraph, renumberer, visitedMap);
295 typedef typename GlobalLookupIndexSet::IndexPair::GlobalIndex GlobalIndex;
297 if(renumberer.globalIndex()!=std::numeric_limits<GlobalIndex>::max()) {
300 coarseIndices.add(renumberer.globalIndex(),
301 LocalIndex(renumberer, renumberer.attribute(),
302 renumberer.isPublic()));
305 aggregates[*
index] = renumberer;
310 coarseIndices.endResize();
312 assert(static_cast<std::size_t>(renumberer) >= coarseIndices.size());
315 for(Iterator vertex=fineGraph.begin(); vertex != end; ++vertex)
316 put(visitedMap, *vertex,
false);
319 template<
typename T,
typename E>
320 template<
typename Graph,
typename I>
321 void ParallelIndicesCoarsener<T,E>::buildCoarseRemoteIndices(
const RemoteIndices& fineRemote,
322 const AggregatesMap<typename Graph::VertexDescriptor>& aggregates,
323 ParallelIndexSet& coarseIndices,
324 RemoteIndices& coarseRemote,
325 ParallelAggregateRenumberer<Graph,I>& renumberer)
327 std::vector<char> attributes(static_cast<std::size_t>(renumberer));
329 GlobalLookupIndexSet<ParallelIndexSet> coarseLookup(coarseIndices, static_cast<std::size_t>(renumberer));
331 typedef typename RemoteIndices::const_iterator Iterator;
332 Iterator end = fineRemote.end();
334 for(Iterator neighbour = fineRemote.begin();
335 neighbour != end; ++neighbour) {
336 int process = neighbour->first;
338 assert(neighbour->second.first==neighbour->second.second);
341 typedef typename std::vector<char>::iterator CIterator;
343 for(CIterator iter=attributes.begin(); iter!= attributes.end(); ++iter)
344 *iter = std::numeric_limits<char>::max();
346 typedef typename RemoteIndices::RemoteIndexList::const_iterator Iterator;
347 Iterator riEnd = neighbour->second.second->end();
349 for(Iterator index = neighbour->second.second->begin();
350 index != riEnd; ++
index) {
351 if(!E::contains(index->localIndexPair().local().attribute()) &&
352 aggregates[index->localIndexPair().local()] !=
353 AggregatesMap<typename Graph::VertexDescriptor>::ISOLATED)
355 assert(aggregates[index->localIndexPair().local()]<attributes.size());
356 if (attributes[aggregates[index->localIndexPair().local()]] != 3)
357 attributes[aggregates[index->localIndexPair().local()]] = index->attribute();
362 typedef RemoteIndexListModifier<ParallelIndexSet,typename RemoteIndices::Allocator,false> Modifier;
363 typedef typename RemoteIndices::RemoteIndex RemoteIndex;
364 typedef typename ParallelIndexSet::const_iterator IndexIterator;
366 Modifier coarseList = coarseRemote.template getModifier<false,true>(process);
368 IndexIterator iend = coarseIndices.end();
369 for(IndexIterator index = coarseIndices.begin(); index != iend; ++
index)
370 if(attributes[index->local()] != std::numeric_limits<char>::max()) {
372 coarseList.insert(RemoteIndex(Attribute(attributes[index->local()]), &(*index)));
378 assert(coarseRemote.neighbours()==fineRemote.neighbours());
382 IndicesSyncer<ParallelIndexSet> syncer(coarseIndices, coarseRemote);
383 syncer.sync(renumberer);
390 template<
typename Graph,
typename VM>
391 typename Graph::VertexDescriptor
397 typename Graph::VertexDescriptor noAggregates)
399 DUNE_UNUSED_PARAMETER(fineInfo);
400 DUNE_UNUSED_PARAMETER(fineGraph);
401 DUNE_UNUSED_PARAMETER(visitedMap);
402 DUNE_UNUSED_PARAMETER(aggregates);
403 DUNE_UNUSED_PARAMETER(coarseInfo);
404 DUNE_UNUSED_PARAMETER(noAggregates);