10 #ifndef MUELU_STRUCTUREDAGGREGATIONFACTORY_DEF_HPP_
11 #define MUELU_STRUCTUREDAGGREGATIONFACTORY_DEF_HPP_
13 #include <Xpetra_Map.hpp>
16 #include "MueLu_AggregationStructuredAlgorithm.hpp"
18 #include "MueLu_LWGraph.hpp"
19 #include "MueLu_Aggregates.hpp"
22 #include "MueLu_UncoupledIndexManager.hpp"
23 #include "MueLu_LocalLexicographicIndexManager.hpp"
24 #include "MueLu_GlobalLexicographicIndexManager.hpp"
30 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
33 : bDefinitionPhase_(true) {}
35 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
40 #define SET_VALID_ENTRY(name) validParamList->setEntry(name, MasterList::getEntry(name))
43 SET_VALID_ENTRY(
"aggregation: error on nodes with no on-rank neighbors");
52 #undef SET_VALID_ENTRY
54 "Graph of the matrix after amalgamation but without dropping.");
56 "Number of spatial dimension provided by CoordinatesTransferFactory.");
58 "Global number of nodes per spatial dimension provided by CoordinatesTransferFactory.");
60 "Local number of nodes per spatial dimension provided by CoordinatesTransferFactory.");
62 "Generating factory for variable \'DofsPerNode\', usually the same as the \'Graph\' factory");
63 validParamList->
set<
const bool>(
"aggregation: single coarse point",
false,
64 "Allows the aggreagtion process to reduce spacial dimensions to a single layer");
66 return validParamList;
69 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
72 Input(currentLevel,
"Graph");
73 Input(currentLevel,
"DofsPerNode");
76 std::string coupling = pL.
get<std::string>(
"aggregation: mode");
77 const bool coupled = (coupling ==
"coupled" ?
true :
false);
86 "gNodesPerDim was not provided by the user on level0!");
89 Input(currentLevel,
"gNodesPerDim");
100 "numDimensions was not provided by the user on level0!");
107 "lNodesPerDim was not provided by the user on level0!");
110 Input(currentLevel,
"numDimensions");
111 Input(currentLevel,
"lNodesPerDim");
115 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
121 if (
const char* dbg = std::getenv(
"MUELU_STRUCTUREDAGGREGATION_DEBUG")) {
122 out = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
128 *out <<
"Entering structured aggregation" << std::endl;
131 bDefinitionPhase_ =
false;
136 const int myRank = fineMap->getComm()->getRank();
137 const int numRanks = fineMap->getComm()->getSize();
138 const GO minGlobalIndex = fineMap->getMinGlobalIndex();
139 const LO dofsPerNode = Get<LO>(currentLevel,
"DofsPerNode");
143 const int interpolationOrder = pL.
get<
int>(
"aggregation: coarsening order");
144 std::string meshLayout = pL.
get<std::string>(
"aggregation: mesh layout");
145 std::string coupling = pL.
get<std::string>(
"aggregation: mode");
146 const bool coupled = (coupling ==
"coupled" ?
true :
false);
147 std::string outputType = pL.
get<std::string>(
"aggregation: output type");
148 const bool outputAggregates = (outputType ==
"Aggregates" ?
true :
false);
149 const bool singleCoarsePoint = pL.
get<
bool>(
"aggregation: single coarse point");
153 if (currentLevel.GetLevelID() == 0) {
155 numDimensions = currentLevel.Get<
int>(
"numDimensions",
NoFactory::get());
162 numDimensions = Get<int>(currentLevel,
"numDimensions");
163 lFineNodesPerDir = Get<Array<LO> >(currentLevel,
"lNodesPerDim");
165 gFineNodesPerDir = Get<Array<GO> >(currentLevel,
"gNodesPerDim");
170 for (
int dim = 0; dim < 3; ++dim) {
171 if (dim >= numDimensions) {
172 gFineNodesPerDir[dim] = 1;
173 lFineNodesPerDir[dim] = 1;
178 std::string coarseningRate = pL.
get<std::string>(
"aggregation: coarsening rate");
181 coarseRate = Teuchos::fromStringToArray<LO>(coarseningRate);
183 GetOStream(
Errors, -1) <<
" *** \"aggregation: coarsening rate\" must be a string convertible into an array! *** "
189 "\"aggregation: coarsening rate\" must have at least as many"
190 " components as the number of spatial dimensions in the problem.");
205 }
else if (meshLayout ==
"Local Lexicographic") {
207 if (currentLevel.GetLevelID() == 0) {
211 "The meshData array is empty, somehow the input for structured"
212 " aggregation are not captured correctly.");
215 meshData = Get<Array<GO> >(currentLevel,
"aggregation: mesh data");
231 }
else if (meshLayout ==
"Global Lexicographic") {
246 *out <<
"The index manager has now been built" << std::endl;
247 *out <<
"graph num nodes: " << fineMap->getLocalNumElements()
251 "The local number of elements in the graph's map is not equal to "
252 "the number of nodes given by: lNodesPerDim!");
256 "The global number of elements in the graph's map is not equal to "
257 "the number of nodes given by: gNodesPerDim!");
260 *out <<
"Compute coarse mesh data" << std::endl;
270 if (interpolationOrder == 0 && outputAggregates) {
272 *out <<
"Compute Aggregates" << std::endl;
279 AggStatHostType aggStat(Kokkos::ViewAllocateWithoutInitializing(
"aggregation status"), geoData->
getNumLocalFineNodes());
280 Kokkos::deep_copy(aggStat,
READY);
283 myStructuredAlgorithm->BuildAggregatesNonKokkos(pL, *graph, *aggregates, aggStat,
284 numNonAggregatedNodes);
287 "MueLu::StructuredAggregationFactory::Build: Leftover nodes found! Error!");
290 Set(currentLevel,
"Aggregates", aggregates);
294 *out <<
"Compute CrsGraph" << std::endl;
296 myStructuredAlgorithm->BuildGraphOnHost(*graph, geoData, dofsPerNode, myGraph,
297 coarseCoordinatesFineMap, coarseCoordinatesMap);
298 Set(currentLevel,
"prolongatorGraph", myGraph);
305 Set(currentLevel,
"coarseCoordinatesFineMap", coarseCoordinatesFineMap);
306 Set(currentLevel,
"coarseCoordinatesMap", coarseCoordinatesMap);
307 Set(currentLevel,
"structuredInterpolationOrder", interpolationOrder);
308 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)
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.
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
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