10 #ifndef MUELU_STRUCTUREDAGGREGATIONFACTORY_KOKKOS_DEF_HPP
11 #define MUELU_STRUCTUREDAGGREGATIONFACTORY_KOKKOS_DEF_HPP
14 #include <Xpetra_Map.hpp>
23 #include "MueLu_LWGraph_kokkos.hpp"
24 #include "MueLu_Aggregates.hpp"
25 #include "MueLu_IndexManager_kokkos.hpp"
26 #include "MueLu_AggregationStructuredAlgorithm.hpp"
32 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
35 : bDefinitionPhase_(true) {}
37 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
42 #define SET_VALID_ENTRY(name) validParamList->setEntry(name, MasterList::getEntry(name))
45 SET_VALID_ENTRY(
"aggregation: error on nodes with no on-rank neighbors");
47 #undef SET_VALID_ENTRY
50 validParamList->
set<std::string>(
"aggregation: output type",
"Aggregates",
51 "Type of object holding the aggregation data: Aggregtes or CrsGraph");
52 validParamList->
set<std::string>(
"aggregation: coarsening rate",
"{3}",
53 "Coarsening rate per spatial dimensions");
54 validParamList->
set<
int>(
"aggregation: coarsening order", 0,
55 "The interpolation order used to construct grid transfer operators based off these aggregates.");
57 "Graph of the matrix after amalgamation but without dropping.");
59 "Number of degrees of freedom per mesh node, provided by the coalsce drop factory.");
61 "Number of spatial dimension provided by CoordinatesTransferFactory.");
63 "Number of nodes per spatial dimmension provided by CoordinatesTransferFactory.");
65 return validParamList;
68 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
71 Input(currentLevel,
"Graph");
72 Input(currentLevel,
"DofsPerNode");
81 "numDimensions was not provided by the user on level0!");
88 "lNodesPerDim was not provided by the user on level0!");
91 Input(currentLevel,
"lNodesPerDim");
92 Input(currentLevel,
"numDimensions");
96 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
102 if (
const char* dbg = std::getenv(
"MUELU_STRUCTUREDAGGREGATION_DEBUG")) {
103 out = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
109 using device_type =
typename LWGraph_kokkos::local_graph_type::device_type;
110 using execution_space =
typename LWGraph_kokkos::local_graph_type::device_type::execution_space;
111 using memory_space =
typename LWGraph_kokkos::local_graph_type::device_type::memory_space;
113 *out <<
"Entering structured aggregation" << std::endl;
116 bDefinitionPhase_ =
false;
121 const int myRank = fineMap->getComm()->getRank();
122 const LO dofsPerNode = Get<LO>(currentLevel,
"DofsPerNode");
126 const int interpolationOrder = pL.
get<
int>(
"aggregation: coarsening order");
127 std::string outputType = pL.
get<std::string>(
"aggregation: output type");
128 const bool outputAggregates = (outputType ==
"Aggregates" ?
true :
false);
131 if (currentLevel.GetLevelID() == 0) {
134 numDimensions = currentLevel.Get<
int>(
"numDimensions",
NoFactory::get());
137 lFineNodesPerDir = Get<Array<LO> >(currentLevel,
"lNodesPerDim");
138 numDimensions = Get<int>(currentLevel,
"numDimensions");
142 for (
int dim = 0; dim < 3; ++dim) {
143 if (dim >= numDimensions) {
144 lFineNodesPerDir[dim] = 1;
149 std::string coarseningRate = pL.
get<std::string>(
"aggregation: coarsening rate");
152 coarseRate = Teuchos::fromStringToArray<LO>(coarseningRate);
154 GetOStream(
Errors, -1) <<
" *** \"aggregation: coarsening rate\" must be a string convertible into an array! *** "
160 "\"aggregation: coarsening rate\" must have at least as many"
161 " components as the number of spatial dimensions in the problem.");
165 interpolationOrder, myRank,
169 *out <<
"The index manager has now been built" << std::endl;
172 "The local number of elements in the graph's map is not equal to "
173 "the number of nodes given by: lNodesPerDim!");
179 if (interpolationOrder == 0 && outputAggregates) {
187 Kokkos::View<unsigned*, device_type> aggStat(
"aggStat", numNonAggregatedNodes);
188 Kokkos::parallel_for(
189 "StructuredAggregation: initialize aggStat",
190 Kokkos::RangePolicy<execution_space>(0, numNonAggregatedNodes),
191 KOKKOS_LAMBDA(
const LO nodeIdx) { aggStat(nodeIdx) =
READY; });
193 myStructuredAlgorithm->
BuildAggregates(pL, *graph, *aggregates, aggStat,
194 numNonAggregatedNodes);
196 *out <<
"numNonAggregatedNodes: " << numNonAggregatedNodes << std::endl;
199 "MueLu::StructuredAggregationFactory::Build: Leftover nodes found! Error!");
202 Set(currentLevel,
"Aggregates", aggregates);
207 myStructuredAlgorithm->
BuildGraph(*graph, geoData, dofsPerNode, myGraph);
208 Set(currentLevel,
"prolongatorGraph", myGraph);
212 Set(currentLevel,
"indexManager", geoData);
213 Set(currentLevel,
"structuredInterpolationOrder", interpolationOrder);
214 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)
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.
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
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.