DUNE-FEM (unstable)

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"
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 =
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
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;
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
251 #endif
Provides classes for the Coloring process of AMG.
int rank() const
Return rank, is between 0 and size()-1.
Definition: mpicommunication.hh:133
A pair consisting of a global and local index.
Definition: indexset.hh:85
A class setting up standard communication for a two-valued attribute set with owner/overlap/copy sema...
Definition: owneroverlapcopy.hh:174
void copyCopyToAll(const T &source, T &dest) const
Communicate values from copy data points to all other data points.
Definition: owneroverlapcopy.hh:328
const RemoteIndices & remoteIndices() const
Get the underlying remote indices.
Definition: owneroverlapcopy.hh:471
void copyOwnerToAll(const T &source, T &dest) const
Communicate values from owner data points to all other data points.
Definition: owneroverlapcopy.hh:311
Manager class for the mapping between local indices and globally unique indices.
Definition: indexset.hh:218
Provides a map between global and local indices.
const_iterator end() const
Get an iterator over all remote index lists.
Definition: remoteindices.hh:1528
const GlobalIndex & global() const
Get the global index.
TL LocalIndex
The type of the local index, e.g. ParallelLocalIndex.
Definition: indexset.hh:239
TG GlobalIndex
the type of the global index. This type has to provide at least a operator< for sorting.
Definition: indexset.hh:226
const_iterator find(int proc) const
Find an iterator over the remote index lists of a specific process.
Definition: remoteindices.hh:1514
concept IndexSet
Model of an index set.
Definition: indexidset.hh:44
constexpr auto max
Function object that returns the greater of the given values.
Definition: hybridutilities.hh:484
static const Vertex ISOLATED
Identifier of isolated vertices.
Definition: aggregates.hh:571
static const Vertex UNAGGREGATED
Identifier of not yet aggregated vertices.
Definition: aggregates.hh:566
Dune namespace.
Definition: alignedallocator.hh:13
constexpr auto get(std::integer_sequence< T, II... >, std::integral_constant< std::size_t, pos >={})
Return the entry at position pos of the given sequence.
Definition: integersequence.hh:22
V::value_type IndexedType
The type we get at each index with operator[].
Definition: communicator.hh:147
static int getSize(const V &, int index)
Get the number of primitive 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:153
V Type
The type the policy is for.
Definition: communicator.hh:140
@ 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
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 16, 22:29, 2024)