Dune Core Modules (2.4.2)

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