46 #ifndef MUELU_AGGREGATIONSTRUCTUREDALGORITHM_DEF_HPP_
47 #define MUELU_AGGREGATIONSTRUCTUREDALGORITHM_DEF_HPP_
50 #include <Teuchos_Comm.hpp>
51 #include <Teuchos_CommHelpers.hpp>
53 #include <Xpetra_MapFactory.hpp>
54 #include <Xpetra_Map.hpp>
55 #include <Xpetra_CrsGraphFactory.hpp>
56 #include <Xpetra_CrsGraph.hpp>
61 #include "MueLu_Aggregates.hpp"
62 #include "MueLu_IndexManager.hpp"
68 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
71 Aggregates& aggregates, std::vector<unsigned>& aggStat,
72 LO& numNonAggregatedNodes)
const {
73 Monitor m(*
this,
"BuildAggregates");
76 if(
const char* dbg = std::getenv(
"MUELU_STRUCTUREDALGORITHM_DEBUG")) {
77 out = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
91 *out <<
"Extract data for ghosted nodes" << std::endl;
93 ghostedCoarseNodeCoarsePIDs, ghostedCoarseNodeCoarseGIDs);
97 LO ghostedCoarseNodeCoarseLID, aggId;
98 *out <<
"Loop over fine nodes and assign them to an aggregate and a rank" << std::endl;
103 for(
int dim = 0; dim < 3; ++dim) {
106 if(ghostedIdx[dim] - geoData->
getOffset(dim)
112 if(rem > (rate / 2)) {++coarseIdx[dim];}
118 ghostedCoarseNodeCoarseLID);
120 aggId = ghostedCoarseNodeCoarseLIDs[ghostedCoarseNodeCoarseLID];
121 vertex2AggId[nodeIdx] = aggId;
122 procWinner[nodeIdx] = ghostedCoarseNodeCoarsePIDs[ghostedCoarseNodeCoarseLID];
124 --numNonAggregatedNodes;
130 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
135 Monitor m(*
this,
"BuildGraphP");
138 if(
const char* dbg = std::getenv(
"MUELU_STRUCTUREDALGORITHM_DEBUG")) {
139 out = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
148 int numInterpolationPoints = 0;
150 numInterpolationPoints = 1;
155 *out <<
"numInterpolationPoints=" << numInterpolationPoints << std::endl;
163 *out <<
"Compute prolongatorGraph data" << std::endl;
165 ComputeGraphDataConstant(graph, geoData, dofsPerNode, numInterpolationPoints,
166 nnzOnRow, rowPtr, colIndex);
168 ComputeGraphDataLinear(graph, geoData, dofsPerNode, numInterpolationPoints,
169 nnzOnRow, rowPtr, colIndex);
175 *out <<
"Compute domain and column maps of the CrsGraph" << std::endl;
177 *out <<
"Extract data for ghosted nodes" << std::endl;
182 ghostedCoarseNodeCoarsePIDs, ghostedCoarseNodeCoarseGIDs);
188 ghostedCoarseNodeCoarseGIDs(),
192 LO coarseNodeIdx = 0;
193 Array<GO> coarseNodeCoarseGIDs, coarseNodeFineGIDs;
195 for(LO nodeIdx = 0; nodeIdx < ghostedCoarseNodeCoarseGIDs.
size(); ++nodeIdx) {
196 if(ghostedCoarseNodeCoarsePIDs[nodeIdx] == colMap->getComm()->getRank()) {
197 coarseNodeCoarseGIDs[coarseNodeIdx] = ghostedCoarseNodeCoarseGIDs[nodeIdx];
201 domainMap = MapFactory::Build(graph.
GetDomainMap()->lib(),
203 coarseNodeCoarseGIDs(),
206 coarseCoordinatesMap = MapFactory::Build(graph.
GetDomainMap()->lib(),
208 coarseNodeCoarseGIDs(),
211 coarseCoordinatesFineMap = MapFactory::Build(graph.
GetDomainMap()->lib(),
213 coarseNodeFineGIDs(),
229 coarseCoordinatesMap = MapFactory::Build(graph.
GetDomainMap()->lib(),
234 coarseCoordinatesFineMap = MapFactory::Build(graph.
GetDomainMap()->lib(),
236 coarseNodeFineGIDs(),
241 *out <<
"Call constructor of CrsGraph" << std::endl;
242 myGraph = CrsGraphFactory::Build(rowMap,
246 *out <<
"Fill CrsGraph" << std::endl;
249 for(LO dof = 0; dof < dofsPerNode; ++dof) {
250 rowIdx = nodeIdx*dofsPerNode + dof;
251 myGraph->insertLocalIndices(rowIdx, colIndex(rowPtr[rowIdx], nnzOnRow[rowIdx]) );
255 *out <<
"Call fillComplete on CrsGraph" << std::endl;
256 myGraph->fillComplete(domainMap, rowMap);
257 *out <<
"Prolongator CrsGraph computed" << std::endl;
262 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
265 const LO dofsPerNode,
const int ,
270 if(
const char* dbg = std::getenv(
"MUELU_STRUCTUREDALGORITHM_DEBUG")) {
271 out = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
281 ghostedCoarseNodeCoarsePIDs, ghostedCoarseNodeCoarseGIDs);
283 LO ghostedCoarseNodeCoarseLID, rem, rate;
290 for(
int dim = 0; dim < 3; ++dim) {
293 if(ghostedIdx[dim] - geoData->
getOffset(dim)
299 if(rem > (rate / 2)) {++coarseIdx[dim];}
305 ghostedCoarseNodeCoarseLID);
307 for(LO dof = 0; dof < dofsPerNode; ++dof) {
308 nnzOnRow[nodeIdx*dofsPerNode + dof] = 1;
309 rowPtr[nodeIdx*dofsPerNode + dof + 1] = rowPtr[nodeIdx*dofsPerNode + dof] + 1;
310 colIndex[rowPtr[nodeIdx*dofsPerNode + dof]] =
311 ghostedCoarseNodeCoarseLIDs[ghostedCoarseNodeCoarseLID]*dofsPerNode + dof;
318 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
321 const LO dofsPerNode,
const int numInterpolationPoints,
326 if(
const char* dbg = std::getenv(
"MUELU_STRUCTUREDALGORITHM_DEBUG")) {
327 out = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
338 const LO coarsePointOffset[8][3] = {{0, 0, 0}, {1, 0, 0}, {0, 1, 0}, {1, 1, 0},
339 {0, 0, 1}, {1, 0, 1}, {0, 1, 1}, {1, 1, 1}};
345 for(
int dim=0; dim < numDimensions; dim++){
362 bool allCoarse =
true;
364 for(
int dim = 0; dim < numDimensions; ++dim) {
365 isCoarse[dim] =
false;
367 isCoarse[dim] =
true;
372 isCoarse[dim] =
true;
375 isCoarse[dim] =
true;
382 LO rowIdx = 0, colIdx = 0;
384 for(LO dof = 0; dof < dofsPerNode; ++dof) {
385 rowIdx = nodeIdx*dofsPerNode + dof;
386 nnzOnRow[rowIdx] = 1;
387 rowPtr[rowIdx + 1] = rowPtr[rowIdx] + 1;
391 colIndex[rowPtr[rowIdx]] = colIdx*dofsPerNode + dof;
395 for(
int dim = 0; dim < numDimensions; ++dim) {
400 for(LO dof = 0; dof < dofsPerNode; ++dof) {
402 rowIdx = nodeIdx*dofsPerNode + dof;
403 nnzOnRow[rowIdx] = Teuchos::as<size_t>( numInterpolationPoints );
404 rowPtr[rowIdx + 1] = rowPtr[rowIdx] + Teuchos::as<LO>(numInterpolationPoints);
406 for(LO interpIdx = 0; interpIdx < numInterpolationPoints; ++interpIdx) {
408 coarseIdx[1] + coarsePointOffset[interpIdx][1],
409 coarseIdx[2] + coarsePointOffset[interpIdx][2],
411 colIndex[rowPtr[rowIdx] + interpIdx] = colIdx*dofsPerNode + dof;
GO getStartIndex(int const dim) const
LO getLocalCoarseNodesInDir(const int dim) const
void ComputeGraphDataConstant(const GraphBase &graph, RCP< IndexManager > &geoData, const LO dofsPerNode, const int numInterpolationPoints, ArrayRCP< size_t > &nnzOnRow, Array< size_t > &rowPtr, Array< LO > &colIndex) const
virtual void getFineNodeGhostedTuple(const LO myLID, LO &i, LO &j, LO &k) const =0
bool getMeshEdge(const int dir) const
const RCP< LOVector > & GetProcWinner() const
Returns constant vector that maps local node IDs to owning processor IDs.
Container class for aggregation information.
RCP< IndexManager > & GetIndexManager()
Get the index manager used by structured aggregation algorithms.
LO getGhostedNodesInDir(const int dim) const
basic_FancyOStream & setShowProcRank(const bool showProcRank)
int getInterpolationOrder() const
GO getStartGhostedCoarseNode(int const dim) const
int getCoarseningRate(const int dim) const
virtual const RCP< const Map > GetDomainMap() const =0
virtual void getGhostedNodesData(const RCP< const Map > fineMap, Array< LO > &ghostedNodeCoarseLIDs, Array< int > &ghostedNodeCoarsePIDs, Array< GO > &ghostedNodeCoarseGIDs) const =0
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
LO getNumLocalFineNodes() const
void ComputeGraphDataLinear(const GraphBase &graph, RCP< IndexManager > &geoData, const LO dofsPerNode, const int numInterpolationPoints, ArrayRCP< size_t > &nnzOnRow, Array< size_t > &rowPtr, Array< LO > &colIndex) const
GO getNumGlobalCoarseNodes() const
virtual void getCoarseNodeGhostedLID(const LO i, const LO j, const LO k, LO &myLID) const =0
virtual void getCoarseNodesData(const RCP< const Map > fineCoordinatesMap, Array< GO > &coarseNodeCoarseGIDs, Array< GO > &coarseNodeFineGIDs) const =0
LO getNumLocalCoarseNodes() const
basic_FancyOStream & setShowAllFrontMatter(const bool showAllFrontMatter)
void BuildAggregates(const Teuchos::ParameterList ¶ms, const GraphBase &graph, Aggregates &aggregates, std::vector< unsigned > &aggStat, LO &numNonAggregatedNodes) const
Local aggregation.
const RCP< LOMultiVector > & GetVertex2AggId() const
Returns constant vector that maps local node IDs to local aggregates IDs.
LO getLocalFineNodesInDir(const int dim) const
bool isAggregationCoupled() const
MueLu representation of a graph.
LO getOffset(int const dim) const
Timer to be used in non-factories.
int getCoarseningEndRate(const int dim) const
void BuildGraph(const GraphBase &graph, RCP< IndexManager > &geoData, const LO dofsPerNode, RCP< CrsGraph > &myGraph, RCP< const Map > &coarseCoordinatesFineMap, RCP< const Map > &coarseCoordinatesMap) const
Local aggregation.
int getNumDimensions() const