46 #ifndef MUELU_AGGREGATIONSTRUCTUREDALGORITHM_DEF_HPP_
47 #define MUELU_AGGREGATIONSTRUCTUREDALGORITHM_DEF_HPP_
50 #include <Teuchos_Comm.hpp>
51 #include <Teuchos_CommHelpers.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,
247 *out <<
"Fill CrsGraph" << std::endl;
250 for(
LO dof = 0; dof < dofsPerNode; ++dof) {
251 rowIdx = nodeIdx*dofsPerNode + dof;
252 myGraph->insertLocalIndices(rowIdx, colIndex(rowPtr[rowIdx], nnzOnRow[rowIdx]) );
256 *out <<
"Call fillComplete on CrsGraph" << std::endl;
257 myGraph->fillComplete(domainMap, rowMap);
258 *out <<
"Prolongator CrsGraph computed" << std::endl;
263 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
266 const LO dofsPerNode,
const int ,
271 if(
const char* dbg = std::getenv(
"MUELU_STRUCTUREDALGORITHM_DEBUG")) {
272 out = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
282 ghostedCoarseNodeCoarsePIDs, ghostedCoarseNodeCoarseGIDs);
284 LO ghostedCoarseNodeCoarseLID, rem, rate;
291 for(
int dim = 0; dim < 3; ++dim) {
294 if(ghostedIdx[dim] - geoData->
getOffset(dim)
300 if(rem > (rate / 2)) {++coarseIdx[dim];}
306 ghostedCoarseNodeCoarseLID);
308 for(
LO dof = 0; dof < dofsPerNode; ++dof) {
309 nnzOnRow[nodeIdx*dofsPerNode + dof] = 1;
310 rowPtr[nodeIdx*dofsPerNode + dof + 1] = rowPtr[nodeIdx*dofsPerNode + dof] + 1;
311 colIndex[rowPtr[nodeIdx*dofsPerNode + dof]] =
312 ghostedCoarseNodeCoarseLIDs[ghostedCoarseNodeCoarseLID]*dofsPerNode + dof;
319 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
322 const LO dofsPerNode,
const int numInterpolationPoints,
327 if(
const char* dbg = std::getenv(
"MUELU_STRUCTUREDALGORITHM_DEBUG")) {
328 out = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
340 const LO coarsePointOffset[8][3] = {{0, 0, 0}, {1, 0, 0}, {0, 1, 0}, {1, 1, 0},
341 {0, 0, 1}, {1, 0, 1}, {0, 1, 1}, {1, 1, 1}};
347 for(
int dim=0; dim < numDimensions; dim++){
350 if(ghostedIdx[dim] - geoData->
getOffset(dim)
356 if(ijkRem[dim] > (rate / 2)) {++coarseIdx[dim];}
363 bool allCoarse =
true;
365 for(
int dim = 0; dim < numDimensions; ++dim) {
366 isCoarse[dim] =
false;
368 isCoarse[dim] =
true;
373 isCoarse[dim] =
true;
376 isCoarse[dim] =
true;
383 LO rowIdx = 0, colIdx = 0;
385 for(
LO dof = 0; dof < dofsPerNode; ++dof) {
386 rowIdx = nodeIdx*dofsPerNode + dof;
387 nnzOnRow[rowIdx] = 1;
388 rowPtr[rowIdx + 1] = rowPtr[rowIdx] + 1;
392 colIndex[rowPtr[rowIdx]] = colIdx*dofsPerNode + dof;
396 for(
int dim = 0; dim < numDimensions; ++dim) {
401 for(
LO dof = 0; dof < dofsPerNode; ++dof) {
403 rowIdx = nodeIdx*dofsPerNode + dof;
404 nnzOnRow[rowIdx] = Teuchos::as<size_t>( numInterpolationPoints );
405 rowPtr[rowIdx + 1] = rowPtr[rowIdx] + Teuchos::as<LO>(numInterpolationPoints);
407 for(
LO interpIdx = 0; interpIdx < numInterpolationPoints; ++interpIdx) {
409 coarseIdx[1] + coarsePointOffset[interpIdx][1],
410 coarseIdx[2] + coarsePointOffset[interpIdx][2],
412 colIndex[rowPtr[rowIdx] + interpIdx] = colIdx*dofsPerNode + dof;
GO getStartIndex(int const 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