Debian Codegraph @

dune/istl/paamg/globalaggregates.hh

raw
1 // SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root
2 // SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
3 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4 // vi: set et ts=4 sw=2 sts=2:
5 #ifndef DUNE_GLOBALAGGREGATES_HH
6 #define DUNE_GLOBALAGGREGATES_HH
7
8 /**
9 * @addtogroup ISTL_PAAMG
10 *
11 * @{
12 */
13 /** @file
14 * @author Markus Blatt
15 * @brief Provdes class for identifying aggregates globally.
16 */
17
18 #include "aggregates.hh"
19 #include "pinfo.hh"
20 #include <dune/common/parallel/indexset.hh>
21
22 namespace Dune
23 {
24 namespace Amg
25 {
26
27 template<typename T, typename TI>
28 struct GlobalAggregatesMap
29 {
30 public:
31 typedef TI ParallelIndexSet;
32
33 typedef typename ParallelIndexSet::GlobalIndex GlobalIndex;
34
35 typedef typename ParallelIndexSet::GlobalIndex IndexedType;
36
37 typedef typename ParallelIndexSet::LocalIndex LocalIndex;
38
39 typedef T Vertex;
40
41 GlobalAggregatesMap(AggregatesMap<Vertex>& aggregates,
42 const GlobalLookupIndexSet<ParallelIndexSet>& indexset)
43 : aggregates_(aggregates), indexset_(indexset)
44 {}
45
46 inline const GlobalIndex& operator[](std::size_t index) const
47 {
48 const Vertex& aggregate = aggregates_[index];
49 if(aggregate >= AggregatesMap<Vertex>::ISOLATED) {
50 assert(aggregate != AggregatesMap<Vertex>::UNAGGREGATED);
51 return isolatedMarker;
52 }else{
53 const Dune::IndexPair<GlobalIndex,LocalIndex >* pair = indexset_.pair(aggregate);
54 assert(pair!=0);
55 return pair->global();
56 }
57 }
58
59
60 inline GlobalIndex& get(std::size_t index)
61 {
62 const Vertex& aggregate = aggregates_[index];
63 assert(aggregate < AggregatesMap<Vertex>::ISOLATED);
64 const Dune::IndexPair<GlobalIndex,LocalIndex >* pair = indexset_.pair(aggregate);
65 assert(pair!=0);
66 return const_cast<GlobalIndex&>(pair->global());
67 }
68
69 class Proxy
70 {
71 public:
72 Proxy(const GlobalLookupIndexSet<ParallelIndexSet>& indexset, Vertex& aggregate)
73 : indexset_(&indexset), aggregate_(&aggregate)
74 {}
75
76 Proxy& operator=(const GlobalIndex& global)
77 {
78 if(global==isolatedMarker)
79 *aggregate_ = AggregatesMap<Vertex>::ISOLATED;
80 else{
81 //assert(global < AggregatesMap<Vertex>::ISOLATED);
82 *aggregate_ = indexset_->operator[](global).local();
83 }
84 return *this;
85 }
86 private:
87 const GlobalLookupIndexSet<ParallelIndexSet>* indexset_;
88 Vertex* aggregate_;
89 };
90
91 inline Proxy operator[](std::size_t index)
92 {
93 return Proxy(indexset_, aggregates_[index]);
94 }
95
96 inline void put(const GlobalIndex& global, size_t i)
97 {
98 aggregates_[i]=indexset_[global].local();
99
100 }
101
102 private:
103 AggregatesMap<Vertex>& aggregates_;
104 const GlobalLookupIndexSet<ParallelIndexSet>& indexset_;
105 static const GlobalIndex isolatedMarker;
106 };
107
108 template<typename T, typename TI>
109 const typename TI::GlobalIndex GlobalAggregatesMap<T,TI>::isolatedMarker =
110 std::numeric_limits<typename TI::GlobalIndex>::max();
111
112 template<typename T, typename TI>
113 struct AggregatesGatherScatter
114 {
115 typedef TI ParallelIndexSet;
116 typedef typename ParallelIndexSet::GlobalIndex GlobalIndex;
117
118 static const GlobalIndex& gather(const GlobalAggregatesMap<T,TI>& ga, size_t i)
119 {
120 return ga[i];
121 }
122
123 static void scatter(GlobalAggregatesMap<T,TI>& ga, GlobalIndex global, size_t i)
124 {
125 ga[i]=global;
126 }
127 };
128
129 template<typename T, typename O, typename I>
130 struct AggregatesPublisher
131 {};
132
133 #if HAVE_MPI
134
135 #endif
136
137 } // namespace Amg
138
139 #if HAVE_MPI
140 // forward declaration
141 template<class T1, class T2>
142 class OwnerOverlapCopyCommunication;
143 #endif
144
145 namespace Amg
146 {
147
148 #if HAVE_MPI
149 /**
150 * @brief Utility class for publishing the aggregate number
151 * of the DOFs in the overlap to other processors and convert
152 * them to local indices.
153 * @tparam T The type of the vertices
154 * @tparam O The set of overlap flags.
155 * @tparam T1 The type of the global indices.
156 * @tparam T2 The type of the local indices.
157 */
158 template<typename T, typename O, typename T1, typename T2>
159 struct AggregatesPublisher<T,O,OwnerOverlapCopyCommunication<T1,T2> >
160 {
161 typedef T Vertex;
162 typedef O OverlapFlags;
163 typedef OwnerOverlapCopyCommunication<T1,T2> ParallelInformation;
164 typedef typename ParallelInformation::GlobalLookupIndexSet GlobalLookupIndexSet;
165 typedef typename ParallelInformation::ParallelIndexSet IndexSet;
166
167 static void publish(AggregatesMap<Vertex>& aggregates,
168 ParallelInformation& pinfo,
169 const GlobalLookupIndexSet& globalLookup)
170 {
171 typedef Dune::Amg::GlobalAggregatesMap<Vertex,IndexSet> GlobalMap;
172 GlobalMap gmap(aggregates, globalLookup);
173 pinfo.copyOwnerToAll(gmap,gmap);
174 // communication only needed for ALU
175 // (ghosts with same global id as owners on the same process)
176 if (SolverCategory::category(pinfo) == 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([[maybe_unused]] AggregatesMap<Vertex>& aggregates,
227 [[maybe_unused]] ParallelInformation& pinfo,
228 [[maybe_unused]] const GlobalLookupIndexSet& globalLookup)
229 {}
230 };
231
232 } // end Amg namespace
233
234
235 #if HAVE_MPI
236 template<typename T, typename TI>
237 struct CommPolicy<Amg::GlobalAggregatesMap<T,TI> >
238 {
239 typedef Amg::AggregatesMap<T> Type;
240 typedef typename Amg::GlobalAggregatesMap<T,TI>::IndexedType IndexedType;
241 typedef SizeOne IndexedTypeFlag;
242 static int getSize(const Type&, int)
243 {
244 return 1;
245 }
246 };
247 #endif
248
249 } // end Dune namespace
250 /** @} */
251 #endif