46 #ifndef MUELU_UNCOUPLEDAGGREGATIONFACTORY_DEF_HPP_
47 #define MUELU_UNCOUPLEDAGGREGATIONFACTORY_DEF_HPP_
51 #include <Xpetra_Map.hpp>
52 #include <Xpetra_Vector.hpp>
53 #include <Xpetra_MultiVectorFactory.hpp>
54 #include <Xpetra_VectorFactory.hpp>
58 #include "MueLu_InterfaceAggregationAlgorithm.hpp"
59 #include "MueLu_OnePtAggregationAlgorithm.hpp"
60 #include "MueLu_PreserveDirichletAggregationAlgorithm.hpp"
61 #include "MueLu_IsolatedNodeAggregationAlgorithm.hpp"
63 #include "MueLu_AggregationPhase1Algorithm.hpp"
64 #include "MueLu_AggregationPhase2aAlgorithm.hpp"
65 #include "MueLu_AggregationPhase2bAlgorithm.hpp"
66 #include "MueLu_AggregationPhase3Algorithm.hpp"
70 #include "MueLu_Aggregates.hpp"
73 #include "MueLu_AmalgamationInfo.hpp"
74 #include "MueLu_Utilities.hpp"
78 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
80 : bDefinitionPhase_(true)
83 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
85 RCP<ParameterList> validParamList = rcp(
new ParameterList());
90 typedef Teuchos::StringToIntegralParameterEntryValidator<int> validatorType;
91 #define SET_VALID_ENTRY(name) validParamList->setEntry(name, MasterList::getEntry(name))
96 validParamList->getEntry(
"aggregation: ordering").setValidator(
97 rcp(
new validatorType(Teuchos::tuple<std::string>(
"natural",
"graph",
"random"),
"aggregation: ordering")));
105 SET_VALID_ENTRY(
"aggregation: error on nodes with no on-rank neighbors");
107 #undef SET_VALID_ENTRY
110 validParamList->set< RCP<const FactoryBase> >(
"Graph",
null,
"Generating factory of the graph");
111 validParamList->set< RCP<const FactoryBase> >(
"DofsPerNode",
null,
"Generating factory for variable \'DofsPerNode\', usually the same as for \'Graph\'");
114 validParamList->set<
std::string > (
"OnePt aggregate map name",
"",
"Name of input map for single node aggregates. (default='')");
115 validParamList->set<
std::string > (
"OnePt aggregate map factory",
"",
"Generating factory of (DOF) map for single node aggregates.");
120 validParamList->set<
std::string > (
"Interface aggregate map name",
"",
"Name of input map for interface aggregates. (default='')");
121 validParamList->set<
std::string > (
"Interface aggregate map factory",
"",
"Generating factory of (DOF) map for interface aggregates.");
122 validParamList->set<RCP<const FactoryBase> > (
"nodeOnInterface", Teuchos::null,
"Array specifying whether or not a node is on the interface (1 or 0).");
124 return validParamList;
127 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
129 Input(currentLevel,
"Graph");
130 Input(currentLevel,
"DofsPerNode");
132 const ParameterList& pL = GetParameterList();
136 if (mapOnePtName.length() > 0) {
138 if (mapOnePtFactName ==
"" || mapOnePtFactName ==
"NoFactory") {
141 RCP<const FactoryBase> mapOnePtFact = GetFactory(mapOnePtFactName);
142 currentLevel.
DeclareInput(mapOnePtName, mapOnePtFact.get());
147 if (pL.get<
bool>(
"aggregation: use interface aggregation") ==
true){
154 "nodeOnInterface was not provided by the user on level0!");
157 Input(currentLevel,
"nodeOnInterface");
162 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
166 ParameterList pL = GetParameterList();
167 bDefinitionPhase_ =
false;
169 if (pL.get<
int>(
"aggregation: max agg size") == -1)
170 pL.set(
"aggregation: max agg size", INT_MAX);
173 RCP<const FactoryBase> graphFact = GetFactory(
"Graph");
179 if (pL.get<
bool>(
"aggregation: allow user-specified singletons") ==
true) algos_.push_back(rcp(
new OnePtAggregationAlgorithm (graphFact)));
192 RCP<Map> OnePtMap = Teuchos::null;
193 if (mapOnePtName.length()) {
195 if (mapOnePtFactName ==
"" || mapOnePtFactName ==
"NoFactory") {
198 RCP<const FactoryBase> mapOnePtFact = GetFactory(mapOnePtFactName);
199 OnePtMap = currentLevel.
Get<RCP<Map> >(mapOnePtName, mapOnePtFact.get());
205 RCP<Map> InterfaceMap = Teuchos::null;
207 RCP<const GraphBase> graph = Get< RCP<GraphBase> >(currentLevel,
"Graph");
210 RCP<Aggregates> aggregates = rcp(
new Aggregates(*graph));
211 aggregates->setObjectLabel(
"UC");
213 const LO numRows = graph->GetNodeNumVertices();
216 std::vector<unsigned> aggStat(numRows,
READY);
219 if (pL.get<
bool>(
"aggregation: use interface aggregation") ==
true){
220 Teuchos::Array<LO> nodeOnInterface = Get<Array<LO>>(currentLevel,
"nodeOnInterface");
221 for (LO i = 0; i < numRows; i++) {
222 if (nodeOnInterface[i])
227 ArrayRCP<const bool> dirichletBoundaryMap = graph->GetBoundaryNodeMap();
228 if (dirichletBoundaryMap != Teuchos::null)
229 for (LO i = 0; i < numRows; i++)
230 if (dirichletBoundaryMap[i] ==
true)
233 LO nDofsPerNode = Get<LO>(currentLevel,
"DofsPerNode");
234 GO indexBase = graph->GetDomainMap()->getIndexBase();
235 if (OnePtMap != Teuchos::null) {
236 for (LO i = 0; i < numRows; i++) {
238 GO grid = (graph->GetDomainMap()->getGlobalElement(i)-indexBase) * nDofsPerNode + indexBase;
240 for (LO kr = 0; kr < nDofsPerNode; kr++)
241 if (OnePtMap->isNodeGlobalElement(grid + kr))
248 const RCP<const Teuchos::Comm<int> > comm = graph->GetComm();
249 GO numGlobalRows = 0;
253 LO numNonAggregatedNodes = numRows;
254 GO numGlobalAggregatedPrev = 0, numGlobalAggsPrev = 0;
255 for (
size_t a = 0; a < algos_.size(); a++) {
259 int oldRank = algos_[a]->SetProcRankVerbose(this->GetProcRankVerbose());
260 algos_[a]->BuildAggregates(pL, *graph, *aggregates, aggStat, numNonAggregatedNodes);
261 algos_[a]->SetProcRankVerbose(oldRank);
264 GO numLocalAggregated = numRows - numNonAggregatedNodes, numGlobalAggregated = 0;
265 GO numLocalAggs = aggregates->GetNumAggregates(), numGlobalAggs = 0;
266 MueLu_sumAll(comm, numLocalAggregated, numGlobalAggregated);
269 double aggPercent = 100*as<double>(numGlobalAggregated)/as<double>(numGlobalRows);
270 if (aggPercent > 99.99 && aggPercent < 100.00) {
277 GetOStream(
Statistics1) <<
" aggregated : " << (numGlobalAggregated - numGlobalAggregatedPrev) <<
" (phase), " << std::fixed
278 << std::setprecision(2) << numGlobalAggregated <<
"/" << numGlobalRows <<
" [" << aggPercent <<
"%] (total)\n"
279 <<
" remaining : " << numGlobalRows - numGlobalAggregated <<
"\n"
280 <<
" aggregates : " << numGlobalAggs-numGlobalAggsPrev <<
" (phase), " << numGlobalAggs <<
" (total)" << std::endl;
281 numGlobalAggregatedPrev = numGlobalAggregated;
282 numGlobalAggsPrev = numGlobalAggs;
286 TEUCHOS_TEST_FOR_EXCEPTION(numNonAggregatedNodes,
Exceptions::RuntimeError,
"MueLu::UncoupledAggregationFactory::Build: Leftover nodes found! Error!");
288 aggregates->AggregatesCrossProcessors(
false);
289 aggregates->ComputeAggregateSizes(
true);
291 Set(currentLevel,
"Aggregates", aggregates);
293 GetOStream(
Statistics1) << aggregates->description() << std::endl;