3 #ifndef DUNE_AMG_INDICESCOARSENER_HH
4 #define DUNE_AMG_INDICESCOARSENER_HH
6 #include <dune/common/parallel/indicessyncer.hh>
7 #include <dune/common/unused.hh>
33 template<
typename T,
typename E>
40 template<
typename T,
typename E>
41 class ParallelIndicesCoarsener
47 typedef E ExcludedAttributes;
52 typedef T ParallelInformation;
54 typedef typename ParallelInformation::ParallelIndexSet ParallelIndexSet;
59 typedef typename ParallelIndexSet::GlobalIndex GlobalIndex;
64 typedef typename ParallelIndexSet::LocalIndex LocalIndex;
69 typedef typename LocalIndex::Attribute Attribute;
74 typedef Dune::RemoteIndices<ParallelIndexSet> RemoteIndices;
87 template<
typename Graph,
typename VM>
88 static typename Graph::VertexDescriptor
89 coarsen(ParallelInformation& fineInfo,
93 ParallelInformation& coarseInfo,
94 typename Graph::VertexDescriptor noAggregates);
97 template<
typename G,
typename I>
100 typedef typename G::VertexDescriptor Vertex;
102 typedef I GlobalLookupIndexSet;
104 typedef typename GlobalLookupIndexSet::IndexPair IndexPair;
106 typedef typename IndexPair::GlobalIndex GlobalIndex;
111 globalIndex_(std::numeric_limits<GlobalIndex>::max())
115 void operator()(
const typename G::ConstEdgeIterator& edge)
118 const IndexPair* pair= lookup_.pair(edge.target());
120 globalIndex(pair->global());
121 attribute(pair->local().attribute());
122 isPublic(pair->local().isPublic());
126 Vertex operator()(
const GlobalIndex& global)
128 DUNE_UNUSED_PARAMETER(global);
129 Vertex current = this->number_;
139 void isPublic(
bool b)
141 isPublic_ = isPublic_ || b;
146 globalIndex_ = std::numeric_limits<GlobalIndex>::max();
150 void attribute(
const Attribute& attribute)
152 attribute_=attribute;
155 Attribute attribute()
160 const GlobalIndex& globalIndex()
const
165 void globalIndex(
const GlobalIndex& global)
167 globalIndex_ = global;
172 Attribute attribute_;
173 const GlobalLookupIndexSet& lookup_;
174 GlobalIndex globalIndex_;
177 template<
typename Graph,
typename VM,
typename I>
178 static void buildCoarseIndexSet(
const ParallelInformation& pinfo,
181 AggregatesMap<typename Graph::VertexDescriptor>& aggregates,
182 ParallelIndexSet& coarseIndices,
183 ParallelAggregateRenumberer<Graph,I>& renumberer);
185 template<
typename Graph,
typename I>
186 static void buildCoarseRemoteIndices(
const RemoteIndices& fineRemote,
187 const AggregatesMap<typename Graph::VertexDescriptor>& aggregates,
188 ParallelIndexSet& coarseIndices,
189 RemoteIndices& coarseRemote,
190 ParallelAggregateRenumberer<Graph,I>& renumberer);
197 template<
typename G,
typename L,
typename E>
198 class IndicesCoarsener<OwnerOverlapCopyCommunication<G,L>,E>
199 :
public ParallelIndicesCoarsener<OwnerOverlapCopyCommunication<G,L>,E>
215 template<
typename Graph,
typename VM>
216 static typename Graph::VertexDescriptor
222 typename Graph::VertexDescriptor noAggregates);
226 template<
typename T,
typename E>
227 template<
typename Graph,
typename VM>
228 inline typename Graph::VertexDescriptor
229 ParallelIndicesCoarsener<T,E>::coarsen(ParallelInformation& fineInfo,
233 ParallelInformation& coarseInfo,
234 typename Graph::VertexDescriptor noAggregates)
236 DUNE_UNUSED_PARAMETER(noAggregates);
237 ParallelAggregateRenumberer<Graph,typename ParallelInformation::GlobalLookupIndexSet> renumberer(aggregates, fineInfo.globalLookup());
238 buildCoarseIndexSet(fineInfo, fineGraph, visitedMap, aggregates,
239 coarseInfo.indexSet(), renumberer);
240 buildCoarseRemoteIndices(fineInfo.remoteIndices(), aggregates, coarseInfo.indexSet(),
241 coarseInfo.remoteIndices(), renumberer);
246 template<
typename T,
typename E>
247 template<
typename Graph,
typename VM,
typename I>
248 void ParallelIndicesCoarsener<T,E>::buildCoarseIndexSet(
const ParallelInformation& pinfo,
251 AggregatesMap<typename Graph::VertexDescriptor>& aggregates,
252 ParallelIndexSet& coarseIndices,
253 ParallelAggregateRenumberer<Graph,I>& renumberer)
257 typedef typename Graph::ConstVertexIterator Iterator;
258 typedef typename ParallelInformation::GlobalLookupIndexSet GlobalLookupIndexSet;
260 Iterator end = fineGraph.end();
261 const GlobalLookupIndexSet& lookup = pinfo.globalLookup();
263 coarseIndices.beginResize();
268 for(Iterator index = fineGraph.begin(); index != end; ++index) {
274 if(!
get(visitedMap, *index)) {
276 typedef typename GlobalLookupIndexSet::IndexPair IndexPair;
277 const IndexPair* pair= lookup.pair(*index);
284 assert(!ExcludedAttributes::contains(pair->local().attribute()));
285 renumberer.attribute(pair->local().attribute());
286 renumberer.isPublic(pair->local().isPublic());
287 renumberer.globalIndex(pair->global());
291 aggregates.template breadthFirstSearch<false>(*index, aggregates[*index],
292 fineGraph, renumberer, visitedMap);
294 typedef typename GlobalLookupIndexSet::IndexPair::GlobalIndex GlobalIndex;
296 if(renumberer.globalIndex()!=std::numeric_limits<GlobalIndex>::max()) {
299 coarseIndices.add(renumberer.globalIndex(),
300 LocalIndex(renumberer, renumberer.attribute(),
301 renumberer.isPublic()));
304 aggregates[*index] = renumberer;
309 coarseIndices.endResize();
311 assert(
static_cast<std::size_t
>(renumberer) >= coarseIndices.size());
314 for(Iterator vertex=fineGraph.begin(); vertex != end; ++vertex)
315 put(visitedMap, *vertex,
false);
318 template<
typename T,
typename E>
319 template<
typename Graph,
typename I>
320 void ParallelIndicesCoarsener<T,E>::buildCoarseRemoteIndices(
const RemoteIndices& fineRemote,
321 const AggregatesMap<typename Graph::VertexDescriptor>& aggregates,
322 ParallelIndexSet& coarseIndices,
323 RemoteIndices& coarseRemote,
324 ParallelAggregateRenumberer<Graph,I>& renumberer)
326 std::vector<char> attributes(
static_cast<std::size_t
>(renumberer));
328 GlobalLookupIndexSet<ParallelIndexSet> coarseLookup(coarseIndices,
static_cast<std::size_t
>(renumberer));
330 typedef typename RemoteIndices::const_iterator Iterator;
331 Iterator end = fineRemote.end();
333 for(Iterator neighbour = fineRemote.begin();
334 neighbour != end; ++neighbour) {
335 int process = neighbour->first;
337 assert(neighbour->second.first==neighbour->second.second);
340 typedef typename std::vector<char>::iterator CIterator;
342 for(CIterator iter=attributes.begin(); iter!= attributes.end(); ++iter)
343 *iter = std::numeric_limits<char>::max();
345 typedef typename RemoteIndices::RemoteIndexList::const_iterator Iterator;
346 Iterator riEnd = neighbour->second.second->end();
348 for(Iterator index = neighbour->second.second->begin();
349 index != riEnd; ++index) {
350 if(!E::contains(index->localIndexPair().local().attribute()) &&
351 aggregates[index->localIndexPair().local()] !=
354 assert(aggregates[index->localIndexPair().local()]<attributes.size());
355 if (attributes[aggregates[index->localIndexPair().local()]] != 3)
356 attributes[aggregates[index->localIndexPair().local()]] = index->attribute();
361 typedef RemoteIndexListModifier<ParallelIndexSet,typename RemoteIndices::Allocator,false> Modifier;
362 typedef typename RemoteIndices::RemoteIndex RemoteIndex;
363 typedef typename ParallelIndexSet::const_iterator IndexIterator;
365 Modifier coarseList = coarseRemote.template getModifier<false,true>(process);
367 IndexIterator iend = coarseIndices.end();
368 for(IndexIterator index = coarseIndices.begin(); index != iend; ++index)
369 if(attributes[index->local()] != std::numeric_limits<char>::max()) {
371 coarseList.insert(RemoteIndex(Attribute(attributes[index->local()]), &(*index)));
377 assert(coarseRemote.neighbours()==fineRemote.neighbours());
381 IndicesSyncer<ParallelIndexSet> syncer(coarseIndices, coarseRemote);
382 syncer.sync(renumberer);
389 template<
typename Graph,
typename VM>
390 typename Graph::VertexDescriptor
396 typename Graph::VertexDescriptor noAggregates)
398 DUNE_UNUSED_PARAMETER(fineInfo);
399 DUNE_UNUSED_PARAMETER(fineGraph);
400 DUNE_UNUSED_PARAMETER(visitedMap);
401 DUNE_UNUSED_PARAMETER(aggregates);
402 DUNE_UNUSED_PARAMETER(coarseInfo);
403 DUNE_UNUSED_PARAMETER(noAggregates);