46 #ifndef MUELU_STRUCTUREDAGGREGATIONFACTORY_KOKKOS_DEF_HPP
47 #define MUELU_STRUCTUREDAGGREGATIONFACTORY_KOKKOS_DEF_HPP
50 #include <Xpetra_Map.hpp>
59 #include "MueLu_LWGraph_kokkos.hpp"
60 #include "MueLu_Aggregates.hpp"
61 #include "MueLu_IndexManager_kokkos.hpp"
62 #include "MueLu_AggregationStructuredAlgorithm.hpp"
68 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
71 : bDefinitionPhase_(true) {}
73 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
78 #define SET_VALID_ENTRY(name) validParamList->setEntry(name, MasterList::getEntry(name))
81 SET_VALID_ENTRY(
"aggregation: error on nodes with no on-rank neighbors");
83 #undef SET_VALID_ENTRY
86 validParamList->
set<std::string>(
"aggregation: output type",
"Aggregates",
87 "Type of object holding the aggregation data: Aggregtes or CrsGraph");
88 validParamList->
set<std::string>(
"aggregation: coarsening rate",
"{3}",
89 "Coarsening rate per spatial dimensions");
90 validParamList->
set<
int>(
"aggregation: coarsening order", 0,
91 "The interpolation order used to construct grid transfer operators based off these aggregates.");
93 "Graph of the matrix after amalgamation but without dropping.");
95 "Number of degrees of freedom per mesh node, provided by the coalsce drop factory.");
97 "Number of spatial dimension provided by CoordinatesTransferFactory.");
99 "Number of nodes per spatial dimmension provided by CoordinatesTransferFactory.");
101 return validParamList;
104 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
107 Input(currentLevel,
"Graph");
108 Input(currentLevel,
"DofsPerNode");
117 "numDimensions was not provided by the user on level0!");
124 "lNodesPerDim was not provided by the user on level0!");
127 Input(currentLevel,
"lNodesPerDim");
128 Input(currentLevel,
"numDimensions");
132 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
138 if (
const char* dbg = std::getenv(
"MUELU_STRUCTUREDAGGREGATION_DEBUG")) {
139 out = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
145 using device_type =
typename LWGraph_kokkos::local_graph_type::device_type;
146 using execution_space =
typename LWGraph_kokkos::local_graph_type::device_type::execution_space;
147 using memory_space =
typename LWGraph_kokkos::local_graph_type::device_type::memory_space;
149 *out <<
"Entering structured aggregation" << std::endl;
152 bDefinitionPhase_ =
false;
157 const int myRank = fineMap->getComm()->getRank();
158 const LO dofsPerNode = Get<LO>(currentLevel,
"DofsPerNode");
162 const int interpolationOrder = pL.
get<
int>(
"aggregation: coarsening order");
163 std::string outputType = pL.
get<std::string>(
"aggregation: output type");
164 const bool outputAggregates = (outputType ==
"Aggregates" ?
true :
false);
167 if (currentLevel.GetLevelID() == 0) {
170 numDimensions = currentLevel.Get<
int>(
"numDimensions",
NoFactory::get());
173 lFineNodesPerDir = Get<Array<LO> >(currentLevel,
"lNodesPerDim");
174 numDimensions = Get<int>(currentLevel,
"numDimensions");
178 for (
int dim = 0; dim < 3; ++dim) {
179 if (dim >= numDimensions) {
180 lFineNodesPerDir[dim] = 1;
185 std::string coarseningRate = pL.
get<std::string>(
"aggregation: coarsening rate");
188 coarseRate = Teuchos::fromStringToArray<LO>(coarseningRate);
190 GetOStream(
Errors, -1) <<
" *** \"aggregation: coarsening rate\" must be a string convertible into an array! *** "
196 "\"aggregation: coarsening rate\" must have at least as many"
197 " components as the number of spatial dimensions in the problem.");
201 interpolationOrder, myRank,
205 *out <<
"The index manager has now been built" << std::endl;
208 "The local number of elements in the graph's map is not equal to "
209 "the number of nodes given by: lNodesPerDim!");
215 if (interpolationOrder == 0 && outputAggregates) {
223 Kokkos::View<unsigned*, device_type> aggStat(
"aggStat", numNonAggregatedNodes);
224 Kokkos::parallel_for(
225 "StructuredAggregation: initialize aggStat",
226 Kokkos::RangePolicy<execution_space>(0, numNonAggregatedNodes),
227 KOKKOS_LAMBDA(
const LO nodeIdx) { aggStat(nodeIdx) =
READY; });
229 myStructuredAlgorithm->
BuildAggregates(pL, *graph, *aggregates, aggStat,
230 numNonAggregatedNodes);
232 *out <<
"numNonAggregatedNodes: " << numNonAggregatedNodes << std::endl;
235 "MueLu::StructuredAggregationFactory::Build: Leftover nodes found! Error!");
238 Set(currentLevel,
"Aggregates", aggregates);
243 myStructuredAlgorithm->
BuildGraph(*graph, geoData, dofsPerNode, myGraph);
244 Set(currentLevel,
"prolongatorGraph", myGraph);
248 Set(currentLevel,
"indexManager", geoData);
249 Set(currentLevel,
"structuredInterpolationOrder", interpolationOrder);
250 Set(currentLevel,
"numDimensions", numDimensions);
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
void SetIndexManagerKokkos(RCP< IndexManager_kokkos > &geoDataKokkos)
Set the index manager used by structured aggregation algorithms. This has to be done by the aggregati...
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.
LO getNumCoarseNodes() const
void Build(Level ¤tLevel) const
Build aggregates.
static const NoFactory * get()
LO getNumLocalFineNodes() const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Class that holds all level-specific information.
Array< LO > getCoarseNodesPerDirArray() const
void BuildAggregates(const Teuchos::ParameterList ¶ms, const LWGraph_kokkos &graph, Aggregates &aggregates, typename AggregationAlgorithmBase< LocalOrdinal, GlobalOrdinal, Node >::AggStatType &aggStat, LO &numNonAggregatedNodes) const
Build aggregates object.
virtual void setObjectLabel(const std::string &objectLabel)
basic_FancyOStream & setShowAllFrontMatter(const bool showAllFrontMatter)
const RCP< const Map > GetDomainMap() const
KOKKOS_INLINE_FUNCTION void AggregatesCrossProcessors(const bool &flag)
Record whether aggregates include DOFs from other processes.
Container class for mesh layout and indices calculation.
int GetLevelID() const
Return level number.
Exception throws to report errors in the internal logical of the program.
void BuildGraph(const LWGraph_kokkos &graph, RCP< IndexManager_kokkos > &geoData, const LO dofsPerNode, RCP< CrsGraph > &myGraph) const
Build a CrsGraph instead of aggregates.
std::string description() const
Return a simple one-line description of this object.
#define SET_VALID_ENTRY(name)
StructuredAggregationFactory_kokkos()
Constructor.
void DeclareInput(const std::string &ename, const FactoryBase *factory, const FactoryBase *requestedBy=NoFactory::get())
Callback from FactoryBase::CallDeclareInput() and FactoryBase::DeclareInput()
aggregates_sizes_type::const_type ComputeAggregateSizes(bool forceRecompute=false) const
Compute sizes of aggregates.
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.
void DeclareInput(Level ¤tLevel) const
Input.