Dune Core Modules (2.3.1)

indicescoarsener.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// $Id$
4#ifndef DUNE_AMG_INDICESCOARSENER_HH
5#define DUNE_AMG_INDICESCOARSENER_HH
6
9#include <vector>
10#include "renumberer.hh"
11
12#if HAVE_MPI
14#endif
15
16#include "pinfo.hh"
17
18namespace Dune
19{
20 namespace Amg
21 {
22
34 template<typename T, typename E>
35 class IndicesCoarsener
36 {};
37
38
39#if HAVE_MPI
40
41 template<typename T, typename E>
42 class ParallelIndicesCoarsener
43 {
44 public:
49
54
55 typedef typename ParallelInformation::ParallelIndexSet ParallelIndexSet;
56
61
66
70 typedef typename LocalIndex::Attribute Attribute;
71
76
88 template<typename Graph, typename VM>
89 static typename Graph::VertexDescriptor
90 coarsen(ParallelInformation& fineInfo,
91 Graph& fineGraph,
92 VM& visitedMap,
94 ParallelInformation& coarseInfo,
95 typename Graph::VertexDescriptor noAggregates);
96
97 private:
98 template<typename G, typename I>
99 class ParallelAggregateRenumberer : public AggregateRenumberer<G>
100 {
101 typedef typename G::VertexDescriptor Vertex;
102
103 typedef I GlobalLookupIndexSet;
104
106
107 typedef typename IndexPair::GlobalIndex GlobalIndex;
108
109 public:
110 ParallelAggregateRenumberer(AggregatesMap<Vertex>& aggregates, const I& lookup)
111 : AggregateRenumberer<G>(aggregates), isPublic_(false), lookup_(lookup),
112 globalIndex_(std::numeric_limits<GlobalIndex>::max())
113 {}
114
115
116 void operator()(const typename G::ConstEdgeIterator& edge)
117 {
118 AggregateRenumberer<G>::operator()(edge);
119 const IndexPair* pair= lookup_.pair(edge.target());
120 if(pair!=0) {
121 globalIndex(pair->global());
122 attribute(pair->local().attribute());
123 isPublic(pair->local().isPublic());
124 }
125 }
126
127 Vertex operator()(const GlobalIndex& global)
128 {
129 DUNE_UNUSED_PARAMETER(global);
130 Vertex current = this->number_;
131 this->operator++();
132 return current;
133 }
134
135 bool isPublic()
136 {
137 return isPublic_;
138 }
139
140 void isPublic(bool b)
141 {
142 isPublic_ = isPublic_ || b;
143 }
144
145 void reset()
146 {
147 globalIndex_ = std::numeric_limits<GlobalIndex>::max();
148 isPublic_=false;
149 }
150
151 void attribute(const Attribute& attribute)
152 {
153 attribute_=attribute;
154 }
155
156 Attribute attribute()
157 {
158 return attribute_;
159 }
160
161 const GlobalIndex& globalIndex() const
162 {
163 return globalIndex_;
164 }
165
166 void globalIndex(const GlobalIndex& global)
167 {
168 globalIndex_ = global;
169 }
170
171 private:
172 bool isPublic_;
173 Attribute attribute_;
174 const GlobalLookupIndexSet& lookup_;
175 GlobalIndex globalIndex_;
176 };
177
178 template<typename Graph, typename VM, typename I>
179 static void buildCoarseIndexSet(const ParallelInformation& pinfo,
180 Graph& fineGraph,
181 VM& visitedMap,
182 AggregatesMap<typename Graph::VertexDescriptor>& aggregates,
183 ParallelIndexSet& coarseIndices,
184 ParallelAggregateRenumberer<Graph,I>& renumberer);
185
186 template<typename Graph,typename I>
187 static void buildCoarseRemoteIndices(const RemoteIndices& fineRemote,
188 const AggregatesMap<typename Graph::VertexDescriptor>& aggregates,
189 ParallelIndexSet& coarseIndices,
190 RemoteIndices& coarseRemote,
191 ParallelAggregateRenumberer<Graph,I>& renumberer);
192
193 };
194
198 template<typename G, typename L, typename E>
199 class IndicesCoarsener<OwnerOverlapCopyCommunication<G,L>,E>
200 : public ParallelIndicesCoarsener<OwnerOverlapCopyCommunication<G,L>,E>
201 {};
202
203
204#endif
205
212 template<typename E>
213 class IndicesCoarsener<SequentialInformation,E>
214 {
215 public:
216 template<typename Graph, typename VM>
217 static typename Graph::VertexDescriptor
218 coarsen(const SequentialInformation & fineInfo,
219 Graph& fineGraph,
220 VM& visitedMap,
222 SequentialInformation& coarseInfo,
223 typename Graph::VertexDescriptor noAggregates);
224 };
225
226#if HAVE_MPI
227 template<typename T, typename E>
228 template<typename Graph, typename VM>
229 inline typename Graph::VertexDescriptor
230 ParallelIndicesCoarsener<T,E>::coarsen(ParallelInformation& fineInfo,
231 Graph& fineGraph,
232 VM& visitedMap,
234 ParallelInformation& coarseInfo,
235 typename Graph::VertexDescriptor noAggregates)
236 {
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);
243
244 return renumberer;
245 }
246
247 template<typename T, typename E>
248 template<typename Graph, typename VM, typename I>
249 void ParallelIndicesCoarsener<T,E>::buildCoarseIndexSet(const ParallelInformation& pinfo,
250 Graph& fineGraph,
251 VM& visitedMap,
253 ParallelIndexSet& coarseIndices,
254 ParallelAggregateRenumberer<Graph,I>& renumberer)
255 {
256 // fineGraph is the local subgraph corresponding to the vertices the process owns.
257 // i.e. no overlap/copy vertices can be visited traversing the graph
258 typedef typename Graph::ConstVertexIterator Iterator;
259 typedef typename ParallelInformation::GlobalLookupIndexSet GlobalLookupIndexSet;
260
261 Iterator end = fineGraph.end();
262 const GlobalLookupIndexSet& lookup = pinfo.globalLookup();
263
264 coarseIndices.beginResize();
265
266 // Setup the coarse index set and renumber the aggregate consecutively
267 // ascending from zero according to the minimum global index belonging
268 // to the aggregate
269 for(Iterator index = fineGraph.begin(); index != end; ++index) {
271 // Isolated vertices will not be represented on the next level.
272 // These should only be there if skipIsolated is activiated in
273 // the coarsening criterion as otherwise they will be aggregated
274 // and should have real aggregate number in the map right now.
275 if(!get(visitedMap, *index)) {
276 // This vertex was not visited by breadthFirstSearch yet.
278 const IndexPair* pair= lookup.pair(*index);
279
280 renumberer.reset(); // reset attribute and global index.
281 if(pair!=0) {
282 // vertex is in the index set. Note that not all vertices have
283 // to be in the index set, just the ones where communication
284 // will happen.
285 assert(!ExcludedAttributes::contains(pair->local().attribute()));
286 renumberer.attribute(pair->local().attribute());
287 renumberer.isPublic(pair->local().isPublic());
288 renumberer.globalIndex(pair->global());
289 }
290
291 // Reconstruct aggregate and mark vertices as visited
292 aggregates.template breadthFirstSearch<false>(*index, aggregates[*index],
293 fineGraph, renumberer, visitedMap);
294
295 typedef typename GlobalLookupIndexSet::IndexPair::GlobalIndex GlobalIndex;
296
297 if(renumberer.globalIndex()!=std::numeric_limits<GlobalIndex>::max()) {
298 // vertex is in the index set.
299 //std::cout <<" Adding global="<< renumberer.globalIndex()<<" local="<<static_cast<std::size_t>(renumberer)<<std::endl;
300 coarseIndices.add(renumberer.globalIndex(),
301 LocalIndex(renumberer, renumberer.attribute(),
302 renumberer.isPublic()));
303 }
304
305 aggregates[*index] = renumberer;
306 ++renumberer;
307 }
308 }
309
310 coarseIndices.endResize();
311
312 assert(static_cast<std::size_t>(renumberer) >= coarseIndices.size());
313
314 // Reset the visited flags
315 for(Iterator vertex=fineGraph.begin(); vertex != end; ++vertex)
316 put(visitedMap, *vertex, false);
317 }
318
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)
326 {
327 std::vector<char> attributes(static_cast<std::size_t>(renumberer));
328
329 GlobalLookupIndexSet<ParallelIndexSet> coarseLookup(coarseIndices, static_cast<std::size_t>(renumberer));
330
331 typedef typename RemoteIndices::const_iterator Iterator;
332 Iterator end = fineRemote.end();
333
334 for(Iterator neighbour = fineRemote.begin();
335 neighbour != end; ++neighbour) {
336 int process = neighbour->first;
337
338 assert(neighbour->second.first==neighbour->second.second);
339
340 // Mark all as not known
341 typedef typename std::vector<char>::iterator CIterator;
342
343 for(CIterator iter=attributes.begin(); iter!= attributes.end(); ++iter)
344 *iter = std::numeric_limits<char>::max();
345
346 typedef typename RemoteIndices::RemoteIndexList::const_iterator Iterator;
347 Iterator riEnd = neighbour->second.second->end();
348
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()] !=
354 {
355 assert(aggregates[index->localIndexPair().local()]<attributes.size());
356 if (attributes[aggregates[index->localIndexPair().local()]] != 3)
357 attributes[aggregates[index->localIndexPair().local()]] = index->attribute();
358 }
359 }
360
361 // Build remote index list
362 typedef RemoteIndexListModifier<ParallelIndexSet,typename RemoteIndices::Allocator,false> Modifier;
363 typedef typename RemoteIndices::RemoteIndex RemoteIndex;
364 typedef typename ParallelIndexSet::const_iterator IndexIterator;
365
366 Modifier coarseList = coarseRemote.template getModifier<false,true>(process);
367
368 IndexIterator iend = coarseIndices.end();
369 for(IndexIterator index = coarseIndices.begin(); index != iend; ++index)
370 if(attributes[index->local()] != std::numeric_limits<char>::max()) {
371 // remote index is present
372 coarseList.insert(RemoteIndex(Attribute(attributes[index->local()]), &(*index)));
373 }
374 //std::cout<<coarseRemote<<std::endl;
375 }
376
377 // The number of neighbours should not change!
378 assert(coarseRemote.neighbours()==fineRemote.neighbours());
379
380 // snyc the index set and the remote indices to recompute missing
381 // indices
382 IndicesSyncer<ParallelIndexSet> syncer(coarseIndices, coarseRemote);
383 syncer.sync(renumberer);
384
385 }
386
387#endif
388
389 template<typename E>
390 template<typename Graph, typename VM>
391 typename Graph::VertexDescriptor
392 IndicesCoarsener<SequentialInformation,E>::coarsen(const SequentialInformation& fineInfo,
393 Graph& fineGraph,
394 VM& visitedMap,
395 AggregatesMap<typename Graph::VertexDescriptor>& aggregates,
396 SequentialInformation& coarseInfo,
397 typename Graph::VertexDescriptor noAggregates)
398 {
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);
405 return noAggregates;
406 }
407
408 } //namespace Amg
409} // namespace Dune
410#endif
Class providing information about the mapping of the vertices onto aggregates.
Definition: aggregates.hh:498
Decorates an index set with the possibility to find a global index that is mapped to a specific local...
Definition: indexset.hh:507
A pair consisting of a global and local index.
Definition: indexset.hh:85
An index present on the local process.
Definition: localindex.hh:34
A class setting up standard communication for a two-valued attribute set with owner/overlap/copy sema...
Definition: owneroverlapcopy.hh:173
Manager class for the mapping between local indices and globally unique indices.
Definition: indexset.hh:218
The indices present on remote processes.
Definition: remoteindices.hh:183
Dune::RemoteIndex< GlobalIndex, Attribute > RemoteIndex
Type of the remote indices we manage.
Definition: remoteindices.hh:225
void beginResize()
Indicate that the index set is to be resized.
size_t size() const
Get the total number (public and nonpublic) indices.
ArrayList< IndexPair, N >::const_iterator const_iterator
The constant iterator over the pairs.
Definition: indexset.hh:306
void add(const GlobalIndex &global)
Add an new index to the set.
const_iterator end() const
Get an iterator over the indices positioned after the last index.
TL LocalIndex
The type of the local index, e.g. ParallelLocalIndex.
Definition: indexset.hh:239
const GlobalIndex & global() const
Get the global index.
void endResize()
Indicate that the resizing finishes.
const IndexPair * pair(const std::size_t &local) const
Get the index pair corresponding to a local index.
LocalIndex & local()
Get the local index.
TG GlobalIndex
the type of the global index. This type has to provide at least a operator< for sorting.
Definition: indexset.hh:226
TG GlobalIndex
the type of the global index.
Definition: indexset.hh:107
SLListConstIterator< RemoteIndex, Allocator > const_iterator
The constant iterator of the list.
Definition: sllist.hh:73
LocalIndex::Attribute Attribute
The type of the attribute.
Definition: indicescoarsener.hh:70
ParallelIndexSet::LocalIndex LocalIndex
The type of the local index.
Definition: indicescoarsener.hh:65
T ParallelInformation
The type of the parallel information.
Definition: indicescoarsener.hh:53
static const V ISOLATED
Identifier of isolated vertices.
Definition: aggregates.hh:509
ParallelIndexSet::GlobalIndex GlobalIndex
The type of the global index.
Definition: indicescoarsener.hh:60
E ExcludedAttributes
The set of excluded attributes.
Definition: indicescoarsener.hh:48
Dune::RemoteIndices< ParallelIndexSet > RemoteIndices
The type of the remote indices.
Definition: indicescoarsener.hh:75
Class for adding missing indices of a distributed index set in a local communication.
Dune namespace.
Definition: alignment.hh:14
STL namespace.
Classes providing communication interfaces for overlapping Schwarz methods.
Definition of the DUNE_UNUSED macro for the case that config.h is not available.
#define DUNE_UNUSED_PARAMETER(parm)
A macro to mark intentional unused function parameters with.
Definition: unused.hh:18
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)