Loading...
Searching...
No Matches
globalaggregates.hh
Go to the documentation of this file.
// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_GLOBALAGGREGATES_HH
#define DUNE_GLOBALAGGREGATES_HH
#include "aggregates.hh"
#include "pinfo.hh"
#include <dune/common/parallel/indexset.hh>
namespace Dune
{
namespace Amg
{
template<typename T, typename TI>
struct GlobalAggregatesMap
{
public:
typedef TI ParallelIndexSet;
typedef typename ParallelIndexSet::GlobalIndex GlobalIndex;
typedef typename ParallelIndexSet::GlobalIndex IndexedType;
typedef typename ParallelIndexSet::LocalIndex LocalIndex;
typedef T Vertex;
GlobalAggregatesMap(AggregatesMap<Vertex>& aggregates,
const GlobalLookupIndexSet<ParallelIndexSet>& indexset)
: aggregates_(aggregates), indexset_(indexset)
{}
inline const GlobalIndex& operator[](std::size_t index) const
{
const Vertex& aggregate = aggregates_[index];
if(aggregate >= AggregatesMap<Vertex>::ISOLATED) {
assert(aggregate != AggregatesMap<Vertex>::UNAGGREGATED);
return isolatedMarker;
}else{
const Dune::IndexPair<GlobalIndex,LocalIndex >* pair = indexset_.pair(aggregate);
assert(pair!=0);
return pair->global();
}
}
inline GlobalIndex& get(std::size_t index)
{
const Vertex& aggregate = aggregates_[index];
assert(aggregate < AggregatesMap<Vertex>::ISOLATED);
const Dune::IndexPair<GlobalIndex,LocalIndex >* pair = indexset_.pair(aggregate);
assert(pair!=0);
return const_cast<GlobalIndex&>(pair->global());
}
class Proxy
{
public:
Proxy(const GlobalLookupIndexSet<ParallelIndexSet>& indexset, Vertex& aggregate)
: indexset_(&indexset), aggregate_(&aggregate)
{}
Proxy& operator=(const GlobalIndex& global)
{
if(global==isolatedMarker)
*aggregate_ = AggregatesMap<Vertex>::ISOLATED;
else{
//assert(global < AggregatesMap<Vertex>::ISOLATED);
*aggregate_ = indexset_->operator[](global).local();
}
return *this;
}
private:
const GlobalLookupIndexSet<ParallelIndexSet>* indexset_;
Vertex* aggregate_;
};
inline Proxy operator[](std::size_t index)
{
return Proxy(indexset_, aggregates_[index]);
}
inline void put(const GlobalIndex& global, size_t i)
{
aggregates_[i]=indexset_[global].local();
}
private:
AggregatesMap<Vertex>& aggregates_;
const GlobalLookupIndexSet<ParallelIndexSet>& indexset_;
static const GlobalIndex isolatedMarker;
};
template<typename T, typename TI>
const typename TI::GlobalIndex GlobalAggregatesMap<T,TI>::isolatedMarker =
std::numeric_limits<typename TI::GlobalIndex>::max();
template<typename T, typename TI>
struct AggregatesGatherScatter
{
typedef TI ParallelIndexSet;
typedef typename ParallelIndexSet::GlobalIndex GlobalIndex;
static const GlobalIndex& gather(const GlobalAggregatesMap<T,TI>& ga, size_t i)
{
return ga[i];
}
static void scatter(GlobalAggregatesMap<T,TI>& ga, GlobalIndex global, size_t i)
{
ga[i]=global;
}
};
template<typename T, typename O, typename I>
struct AggregatesPublisher
{};
#if HAVE_MPI
#endif
} // namespace Amg
#if HAVE_MPI
// forward declaration
template<class T1, class T2>
class OwnerOverlapCopyCommunication;
#endif
namespace Amg
{
#if HAVE_MPI
template<typename T, typename O, typename T1, typename T2>
struct AggregatesPublisher<T,O,OwnerOverlapCopyCommunication<T1,T2> >
{
typedef T Vertex;
typedef O OverlapFlags;
typedef OwnerOverlapCopyCommunication<T1,T2> ParallelInformation;
typedef typename ParallelInformation::GlobalLookupIndexSet GlobalLookupIndexSet;
typedef typename ParallelInformation::ParallelIndexSet IndexSet;
static void publish(AggregatesMap<Vertex>& aggregates,
ParallelInformation& pinfo,
const GlobalLookupIndexSet& globalLookup)
{
typedef Dune::Amg::GlobalAggregatesMap<Vertex,IndexSet> GlobalMap;
GlobalMap gmap(aggregates, globalLookup);
pinfo.copyOwnerToAll(gmap,gmap);
// communication only needed for ALU
// (ghosts with same global id as owners on the same process)
if (SolverCategory::category(pinfo) == static_cast<int>(SolverCategory::nonoverlapping))
pinfo.copyCopyToAll(gmap,gmap);
typedef typename ParallelInformation::RemoteIndices::const_iterator Lists;
Lists lists = pinfo.remoteIndices().find(pinfo.communicator().rank());
if(lists!=pinfo.remoteIndices().end()) {
// For periodic boundary conditions we must renumber
// the aggregates of vertices in the overlap whose owners are
// on the same process
Vertex maxAggregate =0;
typedef typename AggregatesMap<Vertex>::const_iterator Iter;
for(Iter i=aggregates.begin(), end=aggregates.end(); i!=end; ++i)
maxAggregate = std::max(maxAggregate, *i);
// Compute new mapping of aggregates in the overlap that we also own
std::map<Vertex,Vertex> newMapping;
// insert all elements into map
typedef typename ParallelInformation::RemoteIndices::RemoteIndexList
::const_iterator RIter;
for(RIter ri=lists->second.first->begin(), rend = lists->second.first->end();
ri!=rend; ++ri)
if(O::contains(ri->localIndexPair().local().attribute()))
newMapping.insert(std::make_pair(aggregates[ri->localIndexPair().local()],
maxAggregate));
// renumber
typedef typename std::map<Vertex,Vertex>::iterator MIter;
for(MIter mi=newMapping.begin(), mend=newMapping.end();
mi != mend; ++mi)
mi->second=++maxAggregate;
for(RIter ri=lists->second.first->begin(), rend = lists->second.first->end();
ri!=rend; ++ri)
if(O::contains(ri->localIndexPair().local().attribute()))
aggregates[ri->localIndexPair().local()] =
newMapping[aggregates[ri->localIndexPair().local()]];
}
}
};
#endif
template<typename T, typename O>
struct AggregatesPublisher<T,O,SequentialInformation>
{
typedef T Vertex;
typedef SequentialInformation ParallelInformation;
typedef typename ParallelInformation::GlobalLookupIndexSet GlobalLookupIndexSet;
static void publish([[maybe_unused]] AggregatesMap<Vertex>& aggregates,
[[maybe_unused]] ParallelInformation& pinfo,
[[maybe_unused]] const GlobalLookupIndexSet& globalLookup)
{}
};
} // end Amg namespace
#if HAVE_MPI
template<typename T, typename TI>
struct CommPolicy<Amg::GlobalAggregatesMap<T,TI> >
{
typedef Amg::AggregatesMap<T> Type;
typedef typename Amg::GlobalAggregatesMap<T,TI>::IndexedType IndexedType;
typedef SizeOne IndexedTypeFlag;
static int getSize(const Type&, int)
{
return 1;
}
};
#endif
} // end Dune namespace
#endif
pinfo.hh
aggregates.hh
Provides classes for the Coloring process of AMG.
Dune::Amg::AggregatesMap::begin
const_iterator begin() const
Definition aggregates.hh:731
Dune::Amg::AggregatesMap::end
const_iterator end() const
Definition aggregates.hh:736
Dune::Amg::AggregatesMap::ISOLATED
static const V ISOLATED
Identifier of isolated vertices.
Definition aggregates.hh:577
Dune::Amg::AggregatesMap::const_iterator
const AggregateDescriptor * const_iterator
Definition aggregates.hh:729
Dune::Amg::AggregatesMap::UNAGGREGATED
static const V UNAGGREGATED
Identifier of not yet aggregated vertices.
Definition aggregates.hh:572
Dune
Definition allocator.hh:11
Dune::Amg
Definition novlpschwarz.hh:256
Dune::Amg::isolatedMarker
const TI::GlobalIndex GlobalAggregatesMap< T, TI >::isolatedMarker
Definition globalaggregates.hh:109
Dune::OwnerOverlapCopyCommunication
A class setting up standard communication for a two-valued attribute set with owner/overlap/copy sema...
Definition owneroverlapcopy.hh:174
Dune::OwnerOverlapCopyCommunication::copyCopyToAll
void copyCopyToAll(const T &source, T &dest) const
Communicate values from copy data points to all other data points.
Definition owneroverlapcopy.hh:328
Dune::OwnerOverlapCopyCommunication< T1, T2 >::GlobalLookupIndexSet
Dune::GlobalLookupIndexSet< ParallelIndexSet > GlobalLookupIndexSet
Definition owneroverlapcopy.hh:456
Dune::OwnerOverlapCopyCommunication::communicator
const Communication< MPI_Comm > & communicator() const
Definition owneroverlapcopy.hh:299
Dune::OwnerOverlapCopyCommunication::copyOwnerToAll
void copyOwnerToAll(const T &source, T &dest) const
Communicate values from owner data points to all other data points.
Definition owneroverlapcopy.hh:311
Dune::OwnerOverlapCopyCommunication::remoteIndices
const RemoteIndices & remoteIndices() const
Get the underlying remote indices.
Definition owneroverlapcopy.hh:471
Dune::OwnerOverlapCopyCommunication< T1, T2 >::ParallelIndexSet
Dune::ParallelIndexSet< T1, LI, 512 > ParallelIndexSet
Definition owneroverlapcopy.hh:449
Dune::Amg::AggregatesMap
Class providing information about the mapping of the vertices onto aggregates.
Definition aggregates.hh:566
Dune::Amg::GlobalAggregatesMap
Definition globalaggregates.hh:29
Dune::Amg::GlobalAggregatesMap::operator[]
const GlobalIndex & operator[](std::size_t index) const
Definition globalaggregates.hh:46
Dune::Amg::GlobalAggregatesMap::get
GlobalIndex & get(std::size_t index)
Definition globalaggregates.hh:60
Dune::Amg::GlobalAggregatesMap::GlobalIndex
ParallelIndexSet::GlobalIndex GlobalIndex
Definition globalaggregates.hh:33
Dune::Amg::GlobalAggregatesMap::put
void put(const GlobalIndex &global, size_t i)
Definition globalaggregates.hh:96
Dune::Amg::GlobalAggregatesMap::Vertex
T Vertex
Definition globalaggregates.hh:39
Dune::Amg::GlobalAggregatesMap::GlobalAggregatesMap
GlobalAggregatesMap(AggregatesMap< Vertex > &aggregates, const GlobalLookupIndexSet< ParallelIndexSet > &indexset)
Definition globalaggregates.hh:41
Dune::Amg::GlobalAggregatesMap::ParallelIndexSet
TI ParallelIndexSet
Definition globalaggregates.hh:31
Dune::Amg::GlobalAggregatesMap::LocalIndex
ParallelIndexSet::LocalIndex LocalIndex
Definition globalaggregates.hh:37
Dune::Amg::GlobalAggregatesMap::IndexedType
ParallelIndexSet::GlobalIndex IndexedType
Definition globalaggregates.hh:35
Dune::Amg::GlobalAggregatesMap::operator[]
Proxy operator[](std::size_t index)
Definition globalaggregates.hh:91
Dune::Amg::GlobalAggregatesMap::Proxy::Proxy
Proxy(const GlobalLookupIndexSet< ParallelIndexSet > &indexset, Vertex &aggregate)
Definition globalaggregates.hh:72
Dune::Amg::GlobalAggregatesMap::Proxy::operator=
Proxy & operator=(const GlobalIndex &global)
Definition globalaggregates.hh:76
Dune::Amg::AggregatesGatherScatter
Definition globalaggregates.hh:114
Dune::Amg::AggregatesGatherScatter::scatter
static void scatter(GlobalAggregatesMap< T, TI > &ga, GlobalIndex global, size_t i)
Definition globalaggregates.hh:123
Dune::Amg::AggregatesGatherScatter::GlobalIndex
ParallelIndexSet::GlobalIndex GlobalIndex
Definition globalaggregates.hh:116
Dune::Amg::AggregatesGatherScatter::ParallelIndexSet
TI ParallelIndexSet
Definition globalaggregates.hh:115
Dune::Amg::AggregatesGatherScatter::gather
static const GlobalIndex & gather(const GlobalAggregatesMap< T, TI > &ga, size_t i)
Definition globalaggregates.hh:118
Dune::Amg::AggregatesPublisher
Definition globalaggregates.hh:131
Dune::Amg::AggregatesPublisher< T, O, OwnerOverlapCopyCommunication< T1, T2 > >::GlobalLookupIndexSet
ParallelInformation::GlobalLookupIndexSet GlobalLookupIndexSet
Definition globalaggregates.hh:164
Dune::Amg::AggregatesPublisher< T, O, OwnerOverlapCopyCommunication< T1, T2 > >::OverlapFlags
O OverlapFlags
Definition globalaggregates.hh:162
Dune::Amg::AggregatesPublisher< T, O, OwnerOverlapCopyCommunication< T1, T2 > >::Vertex
T Vertex
Definition globalaggregates.hh:161
Dune::Amg::AggregatesPublisher< T, O, OwnerOverlapCopyCommunication< T1, T2 > >::IndexSet
ParallelInformation::ParallelIndexSet IndexSet
Definition globalaggregates.hh:165
Dune::Amg::AggregatesPublisher< T, O, OwnerOverlapCopyCommunication< T1, T2 > >::ParallelInformation
OwnerOverlapCopyCommunication< T1, T2 > ParallelInformation
Definition globalaggregates.hh:163
Dune::Amg::AggregatesPublisher< T, O, OwnerOverlapCopyCommunication< T1, T2 > >::publish
static void publish(AggregatesMap< Vertex > &aggregates, ParallelInformation &pinfo, const GlobalLookupIndexSet &globalLookup)
Definition globalaggregates.hh:167
Dune::Amg::AggregatesPublisher< T, O, SequentialInformation >::publish
static void publish(AggregatesMap< Vertex > &aggregates, ParallelInformation &pinfo, const GlobalLookupIndexSet &globalLookup)
Definition globalaggregates.hh:226
Dune::Amg::AggregatesPublisher< T, O, SequentialInformation >::ParallelInformation
SequentialInformation ParallelInformation
Definition globalaggregates.hh:223
Dune::Amg::AggregatesPublisher< T, O, SequentialInformation >::Vertex
T Vertex
Definition globalaggregates.hh:222
Dune::Amg::AggregatesPublisher< T, O, SequentialInformation >::GlobalLookupIndexSet
ParallelInformation::GlobalLookupIndexSet GlobalLookupIndexSet
Definition globalaggregates.hh:224
Dune::CommPolicy< Amg::GlobalAggregatesMap< T, TI > >::getSize
static int getSize(const Type &, int)
Definition globalaggregates.hh:242
Dune::CommPolicy< Amg::GlobalAggregatesMap< T, TI > >::IndexedType
Amg::GlobalAggregatesMap< T, TI >::IndexedType IndexedType
Definition globalaggregates.hh:240
Dune::CommPolicy< Amg::GlobalAggregatesMap< T, TI > >::Type
Amg::AggregatesMap< T > Type
Definition globalaggregates.hh:239
Dune::CommPolicy< Amg::GlobalAggregatesMap< T, TI > >::IndexedTypeFlag
SizeOne IndexedTypeFlag
Definition globalaggregates.hh:241
Dune::Amg::SequentialInformation
Definition pinfo.hh:28
Dune::Amg::SequentialInformation::GlobalLookupIndexSet
int GlobalLookupIndexSet
Definition pinfo.hh:54
Dune::SolverCategory::nonoverlapping
@ nonoverlapping
Category for non-overlapping solvers.
Definition solvercategory.hh:27
Dune::SolverCategory::category
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