Dune Core Modules (2.5.0)

globalaggregates.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_GLOBALAGGREGATES_HH
4#define DUNE_GLOBALAGGREGATES_HH
5
16#include "aggregates.hh"
17#include "pinfo.hh"
19#include <dune/common/unused.hh>
20
21namespace Dune
22{
23 namespace Amg
24 {
25
26 template<typename T, typename TI>
27 struct GlobalAggregatesMap
28 {
29 public:
30 typedef TI ParallelIndexSet;
31
32 typedef typename ParallelIndexSet::GlobalIndex GlobalIndex;
33
34 typedef typename ParallelIndexSet::GlobalIndex IndexedType;
35
36 typedef typename ParallelIndexSet::LocalIndex LocalIndex;
37
38 typedef T Vertex;
39
40 GlobalAggregatesMap(AggregatesMap<Vertex>& aggregates,
41 const GlobalLookupIndexSet<ParallelIndexSet>& indexset)
42 : aggregates_(aggregates), indexset_(indexset)
43 {}
44
45 inline const GlobalIndex& operator[](std::size_t index) const
46 {
47 const Vertex& aggregate = aggregates_[index];
48 if(aggregate >= AggregatesMap<Vertex>::ISOLATED) {
49 assert(aggregate != AggregatesMap<Vertex>::UNAGGREGATED);
50 return isolatedMarker;
51 }else{
52 const Dune::IndexPair<GlobalIndex,LocalIndex >* pair = indexset_.pair(aggregate);
53 assert(pair!=0);
54 return pair->global();
55 }
56 }
57
58
59 inline GlobalIndex& get(std::size_t index)
60 {
61 const Vertex& aggregate = aggregates_[index];
62 assert(aggregate < AggregatesMap<Vertex>::ISOLATED);
63 const Dune::IndexPair<GlobalIndex,LocalIndex >* pair = indexset_.pair(aggregate);
64 assert(pair!=0);
65 return const_cast<GlobalIndex&>(pair->global());
66 }
67
68 class Proxy
69 {
70 public:
71 Proxy(const GlobalLookupIndexSet<ParallelIndexSet>& indexset, Vertex& aggregate)
72 : indexset_(&indexset), aggregate_(&aggregate)
73 {}
74
75 Proxy& operator=(const GlobalIndex& global)
76 {
77 if(global==isolatedMarker)
79 else{
80 //assert(global < AggregatesMap<Vertex>::ISOLATED);
81 *aggregate_ = indexset_->operator[](global).local();
82 }
83 return *this;
84 }
85 private:
86 const GlobalLookupIndexSet<ParallelIndexSet>* indexset_;
87 Vertex* aggregate_;
88 };
89
90 inline Proxy operator[](std::size_t index)
91 {
92 return Proxy(indexset_, aggregates_[index]);
93 }
94
95 inline void put(const GlobalIndex& global, size_t i)
96 {
97 aggregates_[i]=indexset_[global].local();
98
99 }
100
101 private:
102 AggregatesMap<Vertex>& aggregates_;
103 const GlobalLookupIndexSet<ParallelIndexSet>& indexset_;
104 static const GlobalIndex isolatedMarker;
105 };
106
107 template<typename T, typename TI>
108 const typename TI::GlobalIndex GlobalAggregatesMap<T,TI>::isolatedMarker =
109 std::numeric_limits<typename TI::GlobalIndex>::max();
110
111 template<typename T, typename TI>
112 struct AggregatesGatherScatter
113 {
114 typedef TI ParallelIndexSet;
115 typedef typename ParallelIndexSet::GlobalIndex GlobalIndex;
116
117 static const GlobalIndex& gather(const GlobalAggregatesMap<T,TI>& ga, size_t i)
118 {
119 return ga[i];
120 }
121
122 static void scatter(GlobalAggregatesMap<T,TI>& ga, GlobalIndex global, size_t i)
123 {
124 ga[i]=global;
125 }
126 };
127
128 template<typename T, typename O, typename I>
129 struct AggregatesPublisher
130 {};
131
132#if HAVE_MPI
133
134#endif
135
136 } // namespace Amg
137
138#if HAVE_MPI
139 // forward declaration
140 template<class T1, class T2>
141 class OwnerOverlapCopyCommunication;
142#endif
143
144 namespace Amg
145 {
146
147#if HAVE_MPI
157 template<typename T, typename O, typename T1, typename T2>
158 struct AggregatesPublisher<T,O,OwnerOverlapCopyCommunication<T1,T2> >
159 {
160 typedef T Vertex;
161 typedef O OverlapFlags;
165
166 static void publish(AggregatesMap<Vertex>& aggregates,
167 ParallelInformation& pinfo,
168 const GlobalLookupIndexSet& globalLookup)
169 {
170 typedef Dune::Amg::GlobalAggregatesMap<Vertex,IndexSet> GlobalMap;
171 GlobalMap gmap(aggregates, globalLookup);
172 pinfo.copyOwnerToAll(gmap,gmap);
173 // communication only needed for ALU
174 // (ghosts with same global id as owners on the same process)
175 if (pinfo.getSolverCategory() ==
176 static_cast<int>(SolverCategory::nonoverlapping))
177 pinfo.copyCopyToAll(gmap,gmap);
178
179 typedef typename ParallelInformation::RemoteIndices::const_iterator Lists;
180 Lists lists = pinfo.remoteIndices().find(pinfo.communicator().rank());
181 if(lists!=pinfo.remoteIndices().end()) {
182
183 // For periodic boundary conditions we must renumber
184 // the aggregates of vertices in the overlap whose owners are
185 // on the same process
186 Vertex maxAggregate =0;
187 typedef typename AggregatesMap<Vertex>::const_iterator Iter;
188 for(Iter i=aggregates.begin(), end=aggregates.end(); i!=end; ++i)
189 maxAggregate = std::max(maxAggregate, *i);
190
191 // Compute new mapping of aggregates in the overlap that we also own
192 std::map<Vertex,Vertex> newMapping;
193
194 // insert all elements into map
195 typedef typename ParallelInformation::RemoteIndices::RemoteIndexList
196 ::const_iterator RIter;
197 for(RIter ri=lists->second.first->begin(), rend = lists->second.first->end();
198 ri!=rend; ++ri)
199 if(O::contains(ri->localIndexPair().local().attribute()))
200 newMapping.insert(std::make_pair(aggregates[ri->localIndexPair().local()],
201 maxAggregate));
202 // renumber
203 typedef typename std::map<Vertex,Vertex>::iterator MIter;
204 for(MIter mi=newMapping.begin(), mend=newMapping.end();
205 mi != mend; ++mi)
206 mi->second=++maxAggregate;
207
208
209 for(RIter ri=lists->second.first->begin(), rend = lists->second.first->end();
210 ri!=rend; ++ri)
211 if(O::contains(ri->localIndexPair().local().attribute()))
212 aggregates[ri->localIndexPair().local()] =
213 newMapping[aggregates[ri->localIndexPair().local()]];
214 }
215 }
216 };
217#endif
218
219 template<typename T, typename O>
220 struct AggregatesPublisher<T,O,SequentialInformation>
221 {
222 typedef T Vertex;
223 typedef SequentialInformation ParallelInformation;
224 typedef typename ParallelInformation::GlobalLookupIndexSet GlobalLookupIndexSet;
225
226 static void publish(AggregatesMap<Vertex>& aggregates,
227 ParallelInformation& pinfo,
228 const GlobalLookupIndexSet& globalLookup)
229 {
230 DUNE_UNUSED_PARAMETER(aggregates);
232 DUNE_UNUSED_PARAMETER(globalLookup);
233 }
234 };
235
236 } // end Amg namespace
237
238
239#if HAVE_MPI
240 template<typename T, typename TI>
241 struct CommPolicy<Amg::GlobalAggregatesMap<T,TI> >
242 {
243 typedef Amg::AggregatesMap<T> Type;
244 typedef typename Amg::GlobalAggregatesMap<T,TI>::IndexedType IndexedType;
245 typedef SizeOne IndexedTypeFlag;
246 static int getSize(const Type&, int)
247 {
248 return 1;
249 }
250 };
251#endif
252
253} // end Dune namespace
254 /* @} */
255#endif
Provides classes for the Coloring process of AMG.
int rank() const
Return rank, is between 0 and size()-1.
Definition: mpicollectivecommunication.hh:166
A pair consisting of a global and local index.
Definition: indexset.hh:84
A class setting up standard communication for a two-valued attribute set with owner/overlap/copy sema...
Definition: owneroverlapcopy.hh:172
void copyCopyToAll(const T &source, T &dest) const
Communicate values from copy data points to all other data points.
Definition: owneroverlapcopy.hh:332
void copyOwnerToAll(const T &source, T &dest) const
Communicate values from owner data points to all other data points.
Definition: owneroverlapcopy.hh:315
const RemoteIndices & remoteIndices() const
Get the underlying remote indices.
Definition: owneroverlapcopy.hh:472
SolverCategory::Category getSolverCategory() const
Get Solver Category.
Definition: owneroverlapcopy.hh:299
const_iterator end() const
Get an iterator over all remote index lists.
Definition: remoteindices.hh:1530
const_iterator find(int proc) const
Find an iterator over the remote index lists of a specific process.
Definition: remoteindices.hh:1516
TL LocalIndex
The type of the local index, e.g. ParallelLocalIndex.
Definition: indexset.hh:238
const GlobalIndex & global() const
Get the global index.
TG GlobalIndex
the type of the global index. This type has to provide at least a operator< for sorting.
Definition: indexset.hh:225
static const Vertex ISOLATED
Identifier of isolated vertices.
Definition: aggregates.hh:554
static const Vertex UNAGGREGATED
Identifier of not yet aggregated vertices.
Definition: aggregates.hh:549
Provides a map between global and local indices.
Dune namespace.
Definition: alignment.hh:11
V::value_type IndexedType
The type we get at each index with operator[].
Definition: communicator.hh:139
static int getSize(const V &, int index)
Get the number of primitve elements at that index.
SizeOne IndexedTypeFlag
Whether the indexed type has variable size or there is always one value at each index.
Definition: communicator.hh:145
V Type
The type the policy is for.
Definition: communicator.hh:132
@ nonoverlapping
Category for non-overlapping solvers.
Definition: solvercategory.hh:23
Definition of the DUNE_UNUSED macro for the case that config.h is not available.
#define DUNE_UNUSED_PARAMETER(parm)
A macro to mark intentionally 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 23, 23:29, 2024)