dune-istl 2.10
Loading...
Searching...
No Matches
globalaggregates.hh
Go to the documentation of this file.
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
18#include "aggregates.hh"
19#include "pinfo.hh"
20#include <dune/common/parallel/indexset.hh>
21
22namespace Dune
23{
24 namespace Amg
25 {
26
27 template<typename T, typename TI>
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
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)
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>
114 {
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>
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>
143#endif
144
145 namespace Amg
146 {
147
148#if HAVE_MPI
158 template<typename T, typename O, typename T1, typename T2>
160 {
161 typedef T Vertex;
162 typedef O OverlapFlags;
166
167 static void publish(AggregatesMap<Vertex>& aggregates,
168 ParallelInformation& pinfo,
169 const GlobalLookupIndexSet& globalLookup)
170 {
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>
221 {
222 typedef T Vertex;
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 {
241 typedef SizeOne IndexedTypeFlag;
242 static int getSize(const Type&, int)
243 {
244 return 1;
245 }
246 };
247#endif
248
249} // end Dune namespace
251#endif
Provides classes for the Coloring process of AMG.
const_iterator begin() const
Definition aggregates.hh:725
const_iterator end() const
Definition aggregates.hh:730
const AggregateDescriptor * const_iterator
Definition aggregates.hh:723
Definition allocator.hh:11
A class setting up standard communication for a two-valued attribute set with owner/overlap/copy sema...
Definition globalaggregates.hh:142
Dune::GlobalLookupIndexSet< ParallelIndexSet > GlobalLookupIndexSet
The type of the reverse lookup of indices.
Definition owneroverlapcopy.hh:456
void copyCopyToAll(const T &source, T &dest) const
Communicate values from copy data points to all other data points.
Definition owneroverlapcopy.hh:328
Dune::ParallelIndexSet< GlobalIdType, LI, 512 > ParallelIndexSet
The type of the parallel index set.
Definition owneroverlapcopy.hh:449
const Communication< MPI_Comm > & communicator() const
Definition owneroverlapcopy.hh:299
void copyOwnerToAll(const T &source, T &dest) const
Communicate values from owner data points to all other data points.
Definition owneroverlapcopy.hh:311
const RemoteIndices & remoteIndices() const
Get the underlying remote indices.
Definition owneroverlapcopy.hh:471
Class providing information about the mapping of the vertices onto aggregates.
Definition aggregates.hh:560
Definition globalaggregates.hh:29
const GlobalIndex & operator[](std::size_t index) const
Definition globalaggregates.hh:46
ParallelIndexSet::GlobalIndex IndexedType
Definition globalaggregates.hh:35
GlobalIndex & get(std::size_t index)
Definition globalaggregates.hh:60
void put(const GlobalIndex &global, size_t i)
Definition globalaggregates.hh:96
GlobalAggregatesMap(AggregatesMap< Vertex > &aggregates, const GlobalLookupIndexSet< ParallelIndexSet > &indexset)
Definition globalaggregates.hh:41
ParallelIndexSet::LocalIndex LocalIndex
Definition globalaggregates.hh:37
T Vertex
Definition globalaggregates.hh:39
TI ParallelIndexSet
Definition globalaggregates.hh:31
ParallelIndexSet::GlobalIndex GlobalIndex
Definition globalaggregates.hh:33
Proxy operator[](std::size_t index)
Definition globalaggregates.hh:91
Definition globalaggregates.hh:70
Proxy(const GlobalLookupIndexSet< ParallelIndexSet > &indexset, Vertex &aggregate)
Definition globalaggregates.hh:72
Proxy & operator=(const GlobalIndex &global)
Definition globalaggregates.hh:76
Definition globalaggregates.hh:114
TI ParallelIndexSet
Definition globalaggregates.hh:115
static void scatter(GlobalAggregatesMap< T, TI > &ga, GlobalIndex global, size_t i)
Definition globalaggregates.hh:123
static const GlobalIndex & gather(const GlobalAggregatesMap< T, TI > &ga, size_t i)
Definition globalaggregates.hh:118
ParallelIndexSet::GlobalIndex GlobalIndex
Definition globalaggregates.hh:116
Definition globalaggregates.hh:131
ParallelInformation::ParallelIndexSet IndexSet
Definition globalaggregates.hh:165
OwnerOverlapCopyCommunication< T1, T2 > ParallelInformation
Definition globalaggregates.hh:163
ParallelInformation::GlobalLookupIndexSet GlobalLookupIndexSet
Definition globalaggregates.hh:164
static void publish(AggregatesMap< Vertex > &aggregates, ParallelInformation &pinfo, const GlobalLookupIndexSet &globalLookup)
Definition globalaggregates.hh:167
ParallelInformation::GlobalLookupIndexSet GlobalLookupIndexSet
Definition globalaggregates.hh:224
static void publish(AggregatesMap< Vertex > &aggregates, ParallelInformation &pinfo, const GlobalLookupIndexSet &globalLookup)
Definition globalaggregates.hh:226
SequentialInformation ParallelInformation
Definition globalaggregates.hh:223
static int getSize(const Type &, int)
Definition globalaggregates.hh:242
SizeOne IndexedTypeFlag
Definition globalaggregates.hh:241
Amg::GlobalAggregatesMap< T, TI >::IndexedType IndexedType
Definition globalaggregates.hh:240
Amg::AggregatesMap< T > Type
Definition globalaggregates.hh:239
Definition pinfo.hh:28
int GlobalLookupIndexSet
Definition pinfo.hh:54
@ nonoverlapping
Category for non-overlapping solvers.
Definition solvercategory.hh:27
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:34