Dune Core Modules (2.8.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
20namespace Dune
21{
22 namespace Amg
23 {
24
25 template<typename T, typename TI>
26 struct GlobalAggregatesMap
27 {
28 public:
29 typedef TI ParallelIndexSet;
30
31 typedef typename ParallelIndexSet::GlobalIndex GlobalIndex;
32
33 typedef typename ParallelIndexSet::GlobalIndex IndexedType;
34
35 typedef typename ParallelIndexSet::LocalIndex LocalIndex;
36
37 typedef T Vertex;
38
39 GlobalAggregatesMap(AggregatesMap<Vertex>& aggregates,
40 const GlobalLookupIndexSet<ParallelIndexSet>& indexset)
41 : aggregates_(aggregates), indexset_(indexset)
42 {}
43
44 inline const GlobalIndex& operator[](std::size_t index) const
45 {
46 const Vertex& aggregate = aggregates_[index];
47 if(aggregate >= AggregatesMap<Vertex>::ISOLATED) {
48 assert(aggregate != AggregatesMap<Vertex>::UNAGGREGATED);
49 return isolatedMarker;
50 }else{
51 const Dune::IndexPair<GlobalIndex,LocalIndex >* pair = indexset_.pair(aggregate);
52 assert(pair!=0);
53 return pair->global();
54 }
55 }
56
57
58 inline GlobalIndex& get(std::size_t index)
59 {
60 const Vertex& aggregate = aggregates_[index];
61 assert(aggregate < AggregatesMap<Vertex>::ISOLATED);
62 const Dune::IndexPair<GlobalIndex,LocalIndex >* pair = indexset_.pair(aggregate);
63 assert(pair!=0);
64 return const_cast<GlobalIndex&>(pair->global());
65 }
66
67 class Proxy
68 {
69 public:
70 Proxy(const GlobalLookupIndexSet<ParallelIndexSet>& indexset, Vertex& aggregate)
71 : indexset_(&indexset), aggregate_(&aggregate)
72 {}
73
74 Proxy& operator=(const GlobalIndex& global)
75 {
76 if(global==isolatedMarker)
78 else{
79 //assert(global < AggregatesMap<Vertex>::ISOLATED);
80 *aggregate_ = indexset_->operator[](global).local();
81 }
82 return *this;
83 }
84 private:
85 const GlobalLookupIndexSet<ParallelIndexSet>* indexset_;
86 Vertex* aggregate_;
87 };
88
89 inline Proxy operator[](std::size_t index)
90 {
91 return Proxy(indexset_, aggregates_[index]);
92 }
93
94 inline void put(const GlobalIndex& global, size_t i)
95 {
96 aggregates_[i]=indexset_[global].local();
97
98 }
99
100 private:
101 AggregatesMap<Vertex>& aggregates_;
102 const GlobalLookupIndexSet<ParallelIndexSet>& indexset_;
103 static const GlobalIndex isolatedMarker;
104 };
105
106 template<typename T, typename TI>
107 const typename TI::GlobalIndex GlobalAggregatesMap<T,TI>::isolatedMarker =
109
110 template<typename T, typename TI>
111 struct AggregatesGatherScatter
112 {
113 typedef TI ParallelIndexSet;
114 typedef typename ParallelIndexSet::GlobalIndex GlobalIndex;
115
116 static const GlobalIndex& gather(const GlobalAggregatesMap<T,TI>& ga, size_t i)
117 {
118 return ga[i];
119 }
120
121 static void scatter(GlobalAggregatesMap<T,TI>& ga, GlobalIndex global, size_t i)
122 {
123 ga[i]=global;
124 }
125 };
126
127 template<typename T, typename O, typename I>
128 struct AggregatesPublisher
129 {};
130
131#if HAVE_MPI
132
133#endif
134
135 } // namespace Amg
136
137#if HAVE_MPI
138 // forward declaration
139 template<class T1, class T2>
140 class OwnerOverlapCopyCommunication;
141#endif
142
143 namespace Amg
144 {
145
146#if HAVE_MPI
156 template<typename T, typename O, typename T1, typename T2>
157 struct AggregatesPublisher<T,O,OwnerOverlapCopyCommunication<T1,T2> >
158 {
159 typedef T Vertex;
160 typedef O OverlapFlags;
164
165 static void publish(AggregatesMap<Vertex>& aggregates,
166 ParallelInformation& pinfo,
167 const GlobalLookupIndexSet& globalLookup)
168 {
169 typedef Dune::Amg::GlobalAggregatesMap<Vertex,IndexSet> GlobalMap;
170 GlobalMap gmap(aggregates, globalLookup);
171 pinfo.copyOwnerToAll(gmap,gmap);
172 // communication only needed for ALU
173 // (ghosts with same global id as owners on the same process)
174 if (SolverCategory::category(pinfo) == static_cast<int>(SolverCategory::nonoverlapping))
175 pinfo.copyCopyToAll(gmap,gmap);
176
177 typedef typename ParallelInformation::RemoteIndices::const_iterator Lists;
178 Lists lists = pinfo.remoteIndices().find(pinfo.communicator().rank());
179 if(lists!=pinfo.remoteIndices().end()) {
180
181 // For periodic boundary conditions we must renumber
182 // the aggregates of vertices in the overlap whose owners are
183 // on the same process
184 Vertex maxAggregate =0;
185 typedef typename AggregatesMap<Vertex>::const_iterator Iter;
186 for(Iter i=aggregates.begin(), end=aggregates.end(); i!=end; ++i)
187 maxAggregate = std::max(maxAggregate, *i);
188
189 // Compute new mapping of aggregates in the overlap that we also own
190 std::map<Vertex,Vertex> newMapping;
191
192 // insert all elements into map
193 typedef typename ParallelInformation::RemoteIndices::RemoteIndexList
194 ::const_iterator RIter;
195 for(RIter ri=lists->second.first->begin(), rend = lists->second.first->end();
196 ri!=rend; ++ri)
197 if(O::contains(ri->localIndexPair().local().attribute()))
198 newMapping.insert(std::make_pair(aggregates[ri->localIndexPair().local()],
199 maxAggregate));
200 // renumber
201 typedef typename std::map<Vertex,Vertex>::iterator MIter;
202 for(MIter mi=newMapping.begin(), mend=newMapping.end();
203 mi != mend; ++mi)
204 mi->second=++maxAggregate;
205
206
207 for(RIter ri=lists->second.first->begin(), rend = lists->second.first->end();
208 ri!=rend; ++ri)
209 if(O::contains(ri->localIndexPair().local().attribute()))
210 aggregates[ri->localIndexPair().local()] =
211 newMapping[aggregates[ri->localIndexPair().local()]];
212 }
213 }
214 };
215#endif
216
217 template<typename T, typename O>
218 struct AggregatesPublisher<T,O,SequentialInformation>
219 {
220 typedef T Vertex;
221 typedef SequentialInformation ParallelInformation;
222 typedef typename ParallelInformation::GlobalLookupIndexSet GlobalLookupIndexSet;
223
224 static void publish([[maybe_unused]] AggregatesMap<Vertex>& aggregates,
225 [[maybe_unused]] ParallelInformation& pinfo,
226 [[maybe_unused]] const GlobalLookupIndexSet& globalLookup)
227 {}
228 };
229
230 } // end Amg namespace
231
232
233#if HAVE_MPI
234 template<typename T, typename TI>
235 struct CommPolicy<Amg::GlobalAggregatesMap<T,TI> >
236 {
237 typedef Amg::AggregatesMap<T> Type;
238 typedef typename Amg::GlobalAggregatesMap<T,TI>::IndexedType IndexedType;
239 typedef SizeOne IndexedTypeFlag;
240 static int getSize(const Type&, int)
241 {
242 return 1;
243 }
244 };
245#endif
246
247} // end Dune namespace
248 /* @} */
249#endif
Provides classes for the Coloring process of AMG.
A pair consisting of a global and local index.
Definition: indexset.hh:83
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:326
void copyOwnerToAll(const T &source, T &dest) const
Communicate values from owner data points to all other data points.
Definition: owneroverlapcopy.hh:309
const RemoteIndices & remoteIndices() const
Get the underlying remote indices.
Definition: owneroverlapcopy.hh:469
const_iterator end() const
Get an iterator over all remote index lists.
Definition: remoteindices.hh:1529
const_iterator find(int proc) const
Find an iterator over the remote index lists of a specific process.
Definition: remoteindices.hh:1515
TL LocalIndex
The type of the local index, e.g. ParallelLocalIndex.
Definition: indexset.hh:237
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:224
static const Vertex ISOLATED
Identifier of isolated vertices.
Definition: aggregates.hh:569
static const Vertex UNAGGREGATED
Identifier of not yet aggregated vertices.
Definition: aggregates.hh:564
auto max(ADLTag< 0 >, const V &v1, const V &v2)
implements binary Simd::max()
Definition: defaults.hh:79
Provides a map between global and local indices.
Dune namespace.
Definition: alignedallocator.hh:11
V::value_type IndexedType
The type we get at each index with operator[].
Definition: communicator.hh:145
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:151
V Type
The type the policy is for.
Definition: communicator.hh:138
@ nonoverlapping
Category for non-overlapping solvers.
Definition: solvercategory.hh:25
static Category category(const OP &op, decltype(op.category()) *=nullptr)
Helperfunction to extract the solver category either from an enum, or from the newly introduced virtu...
Definition: solvercategory.hh:32
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 22, 23:30, 2024)