46 #ifndef MUELU_STRUCTUREDAGGREGATIONFACTORY_DEF_HPP_
47 #define MUELU_STRUCTUREDAGGREGATIONFACTORY_DEF_HPP_
49 #include <Xpetra_Map.hpp>
52 #include "MueLu_AggregationStructuredAlgorithm.hpp"
54 #include "MueLu_LWGraph.hpp"
55 #include "MueLu_Aggregates.hpp"
58 #include "MueLu_UncoupledIndexManager.hpp"
59 #include "MueLu_LocalLexicographicIndexManager.hpp"
60 #include "MueLu_GlobalLexicographicIndexManager.hpp"
66 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
69 : bDefinitionPhase_(true) {}
71 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
76 #define SET_VALID_ENTRY(name) validParamList->setEntry(name, MasterList::getEntry(name))
79 SET_VALID_ENTRY(
"aggregation: error on nodes with no on-rank neighbors");
88 #undef SET_VALID_ENTRY
90 "Graph of the matrix after amalgamation but without dropping.");
92 "Number of spatial dimension provided by CoordinatesTransferFactory.");
94 "Global number of nodes per spatial dimension provided by CoordinatesTransferFactory.");
96 "Local number of nodes per spatial dimension provided by CoordinatesTransferFactory.");
98 "Generating factory for variable \'DofsPerNode\', usually the same as the \'Graph\' factory");
99 validParamList->
set<
const bool>(
"aggregation: single coarse point",
false,
100 "Allows the aggreagtion process to reduce spacial dimensions to a single layer");
102 return validParamList;
105 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
108 Input(currentLevel,
"Graph");
109 Input(currentLevel,
"DofsPerNode");
112 std::string coupling = pL.
get<std::string>(
"aggregation: mode");
113 const bool coupled = (coupling ==
"coupled" ?
true :
false);
122 "gNodesPerDim was not provided by the user on level0!");
125 Input(currentLevel,
"gNodesPerDim");
136 "numDimensions was not provided by the user on level0!");
143 "lNodesPerDim was not provided by the user on level0!");
146 Input(currentLevel,
"numDimensions");
147 Input(currentLevel,
"lNodesPerDim");
151 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
157 if (
const char* dbg = std::getenv(
"MUELU_STRUCTUREDAGGREGATION_DEBUG")) {
158 out = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
164 *out <<
"Entering structured aggregation" << std::endl;
167 bDefinitionPhase_ =
false;
172 const int myRank = fineMap->getComm()->getRank();
173 const int numRanks = fineMap->getComm()->getSize();
174 const GO minGlobalIndex = fineMap->getMinGlobalIndex();
175 const LO dofsPerNode = Get<LO>(currentLevel,
"DofsPerNode");
179 const int interpolationOrder = pL.
get<
int>(
"aggregation: coarsening order");
180 std::string meshLayout = pL.
get<std::string>(
"aggregation: mesh layout");
181 std::string coupling = pL.
get<std::string>(
"aggregation: mode");
182 const bool coupled = (coupling ==
"coupled" ?
true :
false);
183 std::string outputType = pL.
get<std::string>(
"aggregation: output type");
184 const bool outputAggregates = (outputType ==
"Aggregates" ?
true :
false);
185 const bool singleCoarsePoint = pL.
get<
bool>(
"aggregation: single coarse point");
189 if (currentLevel.GetLevelID() == 0) {
191 numDimensions = currentLevel.Get<
int>(
"numDimensions",
NoFactory::get());
198 numDimensions = Get<int>(currentLevel,
"numDimensions");
199 lFineNodesPerDir = Get<Array<LO> >(currentLevel,
"lNodesPerDim");
201 gFineNodesPerDir = Get<Array<GO> >(currentLevel,
"gNodesPerDim");
206 for (
int dim = 0; dim < 3; ++dim) {
207 if (dim >= numDimensions) {
208 gFineNodesPerDir[dim] = 1;
209 lFineNodesPerDir[dim] = 1;
214 std::string coarseningRate = pL.
get<std::string>(
"aggregation: coarsening rate");
217 coarseRate = Teuchos::fromStringToArray<LO>(coarseningRate);
219 GetOStream(
Errors, -1) <<
" *** \"aggregation: coarsening rate\" must be a string convertible into an array! *** "
225 "\"aggregation: coarsening rate\" must have at least as many"
226 " components as the number of spatial dimensions in the problem.");
241 }
else if (meshLayout ==
"Local Lexicographic") {
243 if (currentLevel.GetLevelID() == 0) {
247 "The meshData array is empty, somehow the input for structured"
248 " aggregation are not captured correctly.");
251 meshData = Get<Array<GO> >(currentLevel,
"aggregation: mesh data");
267 }
else if (meshLayout ==
"Global Lexicographic") {
282 *out <<
"The index manager has now been built" << std::endl;
283 *out <<
"graph num nodes: " << fineMap->getLocalNumElements()
287 "The local number of elements in the graph's map is not equal to "
288 "the number of nodes given by: lNodesPerDim!");
292 "The global number of elements in the graph's map is not equal to "
293 "the number of nodes given by: gNodesPerDim!");
296 *out <<
"Compute coarse mesh data" << std::endl;
306 if (interpolationOrder == 0 && outputAggregates) {
308 *out <<
"Compute Aggregates" << std::endl;
315 AggStatHostType aggStat(Kokkos::ViewAllocateWithoutInitializing(
"aggregation status"), geoData->
getNumLocalFineNodes());
316 Kokkos::deep_copy(aggStat,
READY);
319 myStructuredAlgorithm->BuildAggregatesNonKokkos(pL, *graph, *aggregates, aggStat,
320 numNonAggregatedNodes);
323 "MueLu::StructuredAggregationFactory::Build: Leftover nodes found! Error!");
326 Set(currentLevel,
"Aggregates", aggregates);
330 *out <<
"Compute CrsGraph" << std::endl;
332 myStructuredAlgorithm->BuildGraphOnHost(*graph, geoData, dofsPerNode, myGraph,
333 coarseCoordinatesFineMap, coarseCoordinatesMap);
334 Set(currentLevel,
"prolongatorGraph", myGraph);
341 Set(currentLevel,
"coarseCoordinatesFineMap", coarseCoordinatesFineMap);
342 Set(currentLevel,
"coarseCoordinatesMap", coarseCoordinatesMap);
343 Set(currentLevel,
"structuredInterpolationOrder", interpolationOrder);
344 Set(currentLevel,
"numDimensions", numDimensions);
Kokkos::View< unsigned *, typename LWGraphHostType::device_type > AggStatHostType
Container class for aggregation information.
basic_FancyOStream & setShowProcRank(const bool showProcRank)
T & get(const std::string &name, T def_value)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Timer to be used in factories. Similar to Monitor but with additional timers.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Algorithm for coarsening a graph with structured aggregation.
void SetIndexManager(RCP< IndexManager > &geoData)
Set the index manager used by various aggregation algorithms. This has to be done by the aggregation ...
StructuredAggregationFactory()
Constructor.
static const NoFactory * get()
void DeclareInput(Level ¤tLevel) const
Input.
Array< GO > getGlobalCoarseNodesPerDir() const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
LO getNumLocalFineNodes() const
Class that holds all level-specific information.
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
LO getNumLocalCoarseNodes() const
virtual void setObjectLabel(const std::string &objectLabel)
basic_FancyOStream & setShowAllFrontMatter(const bool showAllFrontMatter)
virtual std::vector< std::vector< GO > > getCoarseMeshData() const =0
const RCP< const Map > GetDomainMap() const
KOKKOS_INLINE_FUNCTION void AggregatesCrossProcessors(const bool &flag)
Record whether aggregates include DOFs from other processes.
int GetLevelID() const
Return level number.
Exception throws to report errors in the internal logical of the program.
std::string description() const
Return a simple one-line description of this object.
void DeclareInput(const std::string &ename, const FactoryBase *factory, const FactoryBase *requestedBy=NoFactory::get())
Callback from FactoryBase::CallDeclareInput() and FactoryBase::DeclareInput()
void Build(Level ¤tLevel) const
Build aggregates.
aggregates_sizes_type::const_type ComputeAggregateSizes(bool forceRecompute=false) const
Compute sizes of aggregates.
#define SET_VALID_ENTRY(name)
Array< LO > getLocalCoarseNodesPerDir() const
bool IsAvailable(const std::string &ename, const FactoryBase *factory=NoFactory::get()) const
Test whether a need's value has been saved.
void SetNumAggregates(LO nAggregates)
Set number of local aggregates on current processor.
GO getNumGlobalFineNodes() const