46#ifndef MUELU_AGGREGATES_DEF_HPP
47#define MUELU_AGGREGATES_DEF_HPP
49#include <Xpetra_Map.hpp>
50#include <Xpetra_Vector.hpp>
51#include <Xpetra_MultiVector.hpp>
52#include <Xpetra_BlockedMultiVector.hpp>
53#include <Xpetra_BlockedVector.hpp>
54#include <Xpetra_VectorFactory.hpp>
55#include <Xpetra_MultiVectorFactory.hpp>
58#include "MueLu_Graph.hpp"
64 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
67 nGlobalAggregates_ = 0;
69 vertex2AggId_ = LOMultiVectorFactory::Build(graph.
GetImportMap(), 1);
72 procWinner_ = LOVectorFactory::Build(graph.
GetImportMap());
75 isRoot_ = Teuchos::ArrayRCP<bool>(graph.
GetImportMap()->getLocalNumElements(),
false);
78 aggregatesIncludeGhosts_ =
true;
82 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
85 nGlobalAggregates_ = 0;
87 vertex2AggId_ = LOMultiVectorFactory::Build(map, 1);
90 procWinner_ = LOVectorFactory::Build(map);
93 isRoot_ = Teuchos::ArrayRCP<bool>(map->getLocalNumElements(),
false);
96 aggregatesIncludeGhosts_ =
true;
100 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
103 if (aggregateSizes_ != Teuchos::null && !forceRecompute) {
105 return aggregateSizes_;
110 aggregateSizes_ = Teuchos::null;
112 Teuchos::ArrayRCP<LO> aggregateSizes;
113 aggregateSizes = Teuchos::ArrayRCP<LO>(nAggregates_,0);
114 int myPid = vertex2AggId_->getMap()->getComm()->getRank();
115 Teuchos::ArrayRCP<LO> procWinner = procWinner_->getDataNonConst(0);
116 Teuchos::ArrayRCP<LO> vertex2AggId = vertex2AggId_->getDataNonConst(0);
117 LO size = procWinner.size();
120 for (LO k = 0; k < size; ++k ) {
121 if (procWinner[k] == myPid) aggregateSizes[vertex2AggId[k]]++;
124 aggregateSizes_ = aggregateSizes;
126 return aggregateSizes;
131 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
133 std::ostringstream out;
135 if (nGlobalAggregates_ == -1) out <<
"{nGlobalAggregates = not computed}";
136 else out <<
"{nGlobalAggregates = " << nGlobalAggregates_ <<
"}";
140 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
146 if (nGlobalAggregates_ == -1) out0 <<
"Global number of aggregates: not computed " << std::endl;
147 else out0 <<
"Global number of aggregates: " << nGlobalAggregates_ << std::endl;
150 if(verbLevel == Teuchos::VERB_EXTREME) {
151 for(
size_t j=0; j <vertex2AggId_->getNumVectors(); j++) {
152 auto data = vertex2AggId_->getData(j);
153 for(
size_t i=0; i<vertex2AggId_->getLocalLength(); i++) {
154 out<<i<<
" : "<< data[i] <<std::endl;
162 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
164 if (nGlobalAggregates_ != -1) {
165 LO nAggregates = GetNumAggregates();
166 GO nGlobalAggregates;
167 MueLu_sumAll(vertex2AggId_->getMap()->getComm(), (GO)nAggregates, nGlobalAggregates);
168 SetNumGlobalAggregates(nGlobalAggregates);
170 return nGlobalAggregates_;
173 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
175 return vertex2AggId_->getMap();
178 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
180 LO numAggs = GetNumAggregates();
181 LO numNodes = vertex2AggId_->getLocalLength();
182 Teuchos::ArrayRCP<const LO> vertex2AggId = vertex2AggId_->getData(0);
183 Teuchos::ArrayRCP<LO> aggSizes = ComputeAggregateSizes(
true);
184 LO INVALID = Teuchos::OrdinalTraits<LO>::invalid();
186 aggPtr.resize(numAggs+1);
187 Array<LO> aggCurr(numAggs+1);
188 aggNodes.resize(numNodes);
189 unaggregated.resize(numNodes);
191 LO currNumUnaggregated=0;
195 for(LO i=0; i<numAggs; i++) {
196 aggPtr[i+1] = aggSizes[i] + aggPtr[i];
197 aggCurr[i] = aggPtr[i];
201 for(LO i=0; i<numNodes; i++) {
202 LO aggregate = vertex2AggId[i];
203 if(aggregate !=INVALID) {
204 aggNodes[aggCurr[aggregate]] = i;
205 aggCurr[aggregate]++;
208 unaggregated[currNumUnaggregated] = i;
209 currNumUnaggregated++;
212 unaggregated.resize(currNumUnaggregated);
#define MUELU_UNAGGREGATED
#define MUELU_DESCRIBE
Helper macro for implementing Describable::describe() for BaseClass objects.
#define MueLu_sumAll(rcpComm, in, out)
MueLu::DefaultGlobalOrdinal GlobalOrdinal
Teuchos::ArrayRCP< LO > ComputeAggregateSizes(bool forceRecompute=false) const
Compute sizes of aggregates.
Aggregates(const GraphBase &graph)
Standard constructor for Aggregates structure.
void print(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=verbLevel_default) const
Print the object with some verbosity level to an FancyOStream object.
const RCP< const Map > GetMap() const
returns (overlapping) map of aggregate/node distribution
GO GetNumGlobalAggregatesComputeIfNeeded()
Get global number of aggregates.
std::string description() const
Return a simple one-line description of this object.
void ComputeNodesInAggregate(Array< LO > &aggPtr, Array< LO > &aggNodes, Array< LO > &unaggregated) const
Generates a compressed list of nodes in each aggregate, where the entries in aggNodes[aggPtr[i]] up t...
virtual std::string description() const
Return a simple one-line description of this object.
MueLu representation of a graph.
virtual const RCP< const Map > GetImportMap() const =0
Namespace for MueLu classes and methods.
@ Statistics1
Print more statistics.