105 Teuchos::ParameterList paramList = paramList_in;
107 RCP<Teuchos::FancyOStream> out = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
120 MUELU_READ_PARAM(paramList,
"aggregation: type", std::string,
"Uncoupled", agg_type);
122 MUELU_READ_PARAM(paramList,
"aggregation: damping factor",
double, (
double)4 / (
double)3, agg_damping);
124 MUELU_READ_PARAM(paramList,
"aggregation: nodes per aggregate",
int, 1, minPerAgg);
126 MUELU_READ_PARAM(paramList,
"null space: type", std::string,
"default vectors", nullspaceType);
127 MUELU_READ_PARAM(paramList,
"null space: dimension",
int, -1, nullspaceDim);
128 MUELU_READ_PARAM(paramList,
"null space: vectors",
double*, NULL, nullspaceVec);
130 MUELU_READ_PARAM(paramList,
"energy minimization: enable",
bool,
false, bEnergyMinimization);
138 ParameterList paramListWithSubList;
140 paramList = paramListWithSubList;
145 int maxNbrAlreadySelected = 0;
148 this->blksize_ = nDofsPerNode;
151 Teuchos::EVerbosityLevel eVerbLevel = Teuchos::VERB_NONE;
152 if (verbosityLevel == 0) eVerbLevel = Teuchos::VERB_NONE;
153 if (verbosityLevel > 0) eVerbLevel = Teuchos::VERB_LOW;
154 if (verbosityLevel > 4) eVerbLevel = Teuchos::VERB_MEDIUM;
155 if (verbosityLevel > 7) eVerbLevel = Teuchos::VERB_HIGH;
156 if (verbosityLevel > 9) eVerbLevel = Teuchos::VERB_EXTREME;
158 TEUCHOS_TEST_FOR_EXCEPTION(agg_type !=
"Uncoupled",
Exceptions::RuntimeError,
"MueLu::MLParameterListInterpreter::Setup(): parameter \"aggregation: type\": only 'Uncoupled' aggregation is supported.");
167 AggFact->SetMinNodesPerAggregate(minPerAgg);
168 AggFact->SetMaxNeighAlreadySelected(maxNbrAlreadySelected);
169 AggFact->SetOrdering(
"natural");
171 if (verbosityLevel > 3) {
172 *out <<
"========================= Aggregate option summary =========================" << std::endl;
173 *out <<
"min Nodes per aggregate : " << minPerAgg << std::endl;
174 *out <<
"min # of root nbrs already aggregated : " << maxNbrAlreadySelected << std::endl;
175 *out <<
"aggregate ordering : natural" << std::endl;
176 *out <<
"=============================================================================" << std::endl;
182 if (agg_damping == 0.0 && bEnergyMinimization ==
false) {
186 }
else if (agg_damping != 0.0 && bEnergyMinimization ==
false) {
188 RCP<SaPFactory> SaPFact = rcp(
new SaPFactory());
189 SaPFact->SetParameter(
"sa: damping factor", ParameterEntry(agg_damping));
192 }
else if (bEnergyMinimization ==
true) {
198 RCP<RAPFactory> AcFact = rcp(
new RAPFactory());
199 for (
size_t i = 0; i < TransferFacts_.size(); i++) {
200 AcFact->AddTransferFactory(TransferFacts_[i]);
210 if (nullspaceType !=
"default vectors") {
211 TEUCHOS_TEST_FOR_EXCEPTION(nullspaceType !=
"pre-computed",
Exceptions::RuntimeError,
"MueLu::MLParameterListInterpreter: no valid nullspace (no pre-computed null space). error.");
212 TEUCHOS_TEST_FOR_EXCEPTION(nullspaceDim == -1,
Exceptions::RuntimeError,
"MueLu::MLParameterListInterpreter: no valid nullspace (nullspace dim == -1). error.");
213 TEUCHOS_TEST_FOR_EXCEPTION(nullspaceVec == NULL,
Exceptions::RuntimeError,
"MueLu::MLParameterListInterpreter: no valid nullspace (nullspace == NULL). You have to provide a valid fine-level nullspace in \'null space: vectors\'");
215 nullspaceDim_ = nullspaceDim;
216 nullspace_ = nullspaceVec;
219 Teuchos::RCP<NullspaceFactory> nspFact = Teuchos::rcp(
new NullspaceFactory());
220 nspFact->SetFactory(
"Nullspace", PtentFact);
228 this->numDesiredLevel_ = maxLevels;
229 this->maxCoarseSize_ = maxCoarseSize;
232 RCP<SmootherFactory> initSmootherFact = Teuchos::null;
233 if (paramList.isSublist(
"init smoother")) {
234 ParameterList& initList = paramList.sublist(
"init smoother");
235 initSmootherFact = AdaptiveDetails::getSmoother<SC, LO, GO, NO>(initList);
237 std::string ifpackType =
"RELAXATION";
238 Teuchos::ParameterList smootherParamList;
239 smootherParamList.set(
"relaxation: type",
"symmetric Gauss-Seidel");
240 smootherParamList.set(
"smoother: sweeps", 1);
241 smootherParamList.set(
"smoother: damping factor", 1.0);
242 RCP<SmootherPrototype> smooProto = rcp(
new TrilinosSmoother(ifpackType, smootherParamList, 0));
245 initSmootherFact->SetSmootherPrototypes(smooProto, smooProto);
251 ParameterList& coarseList = paramList.sublist(
"coarse: list");
253 RCP<SmootherFactory> coarseFact = AdaptiveDetails::getSmoother<SC, LO, GO, NO>(coarseList);
266 for (
int levelID = 0; levelID < maxLevels; levelID++) {
282 ParameterList levelSmootherParam =
GetMLSubList(paramList,
"smoother", levelID);
288 RCP<SmootherFactory> smootherFact = AdaptiveDetails::getSmoother<SC, LO, GO, NO>(levelSmootherParam);
289 manager->SetFactory(
"Smoother", smootherFact);
290 smootherFact->DisableMultipleCallCheck();
292 initmanager->SetFactory(
"Smoother", initSmootherFact);
293 initmanager->SetFactory(
"CoarseSolver", initSmootherFact);
294 initSmootherFact->DisableMultipleCallCheck();
301 Teuchos::rcp_dynamic_cast<PFactory>(PFact)->DisableMultipleCallCheck();
302 Teuchos::rcp_dynamic_cast<PFactory>(PtentFact)->DisableMultipleCallCheck();
303 Teuchos::rcp_dynamic_cast<TwoLevelFactoryBase>(RFact)->DisableMultipleCallCheck();
304 Teuchos::rcp_dynamic_cast<SingleLevelFactoryBase>(coarseFact)->DisableMultipleCallCheck();
305 Teuchos::rcp_dynamic_cast<SingleLevelFactoryBase>(dropFact)->DisableMultipleCallCheck();
306 Teuchos::rcp_dynamic_cast<SingleLevelFactoryBase>(AggFact)->DisableMultipleCallCheck();
307 Teuchos::rcp_dynamic_cast<TwoLevelFactoryBase>(AcFact)->DisableMultipleCallCheck();
308 Teuchos::rcp_dynamic_cast<SingleLevelFactoryBase>(nspFact)->DisableMultipleCallCheck();
310 manager->SetFactory(
"CoarseSolver", coarseFact);
311 manager->SetFactory(
"Graph", dropFact);
312 manager->SetFactory(
"Aggregates", AggFact);
313 manager->SetFactory(
"DofsPerNode", dropFact);
314 manager->SetFactory(
"A", AcFact);
315 manager->SetFactory(
"P", PFact);
316 manager->SetFactory(
"Ptent", PtentFact);
317 manager->SetFactory(
"R", RFact);
318 manager->SetFactory(
"Nullspace", nspFact);
321 initmanager->SetFactory(
"Graph", dropFact);
322 initmanager->SetFactory(
"Aggregates", AggFact);
323 initmanager->SetFactory(
"DofsPerNode", dropFact);
324 initmanager->SetFactory(
"A", AcFact);
325 initmanager->SetFactory(
"P", PtentFact);
326 initmanager->SetFactory(
"Ptent", PtentFact);
327 initmanager->SetFactory(
"R", RFact);
328 initmanager->SetFactory(
"Nullspace", nspFact);
330 this->AddFactoryManager(levelID, 1, manager);
331 this->AddInitFactoryManager(levelID, 1, initmanager);
367 if (this->nullspace_ != NULL) {
368 RCP<Level> fineLevel = H.
GetLevel(0);
369 const RCP<const Map> rowMap = fineLevel->Get<RCP<Matrix> >(
"A")->getRowMap();
370 RCP<MultiVector> nullspace = MultiVectorFactory::Build(rowMap, nullspaceDim_,
true);
372 for (
size_t i = 0; i < Teuchos::as<size_t>(nullspaceDim_); i++) {
373 Teuchos::ArrayRCP<Scalar> nullspacei = nullspace->getDataNonConst(i);
374 const size_t myLength = nullspace->getLocalLength();
376 for (
size_t j = 0; j < myLength; j++) {
377 nullspacei[j] = nullspace_[i * myLength + j];
381 fineLevel->Set(
"Nullspace", nullspace);
390 SetupInitHierarchy(H);
394 Teuchos::RCP<MueLu::Level> Finest = H.
GetLevel(0);
395 Teuchos::RCP<MultiVector> nspVector2 = Finest->Get<Teuchos::RCP<MultiVector> >(
"Nullspace");
397 Xpetra::IO<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Write(
"orig_nsp.vec", *nspVector2);
399 RCP<Matrix> Op = Finest->Get<RCP<Matrix> >(
"A");
400 Xpetra::IO<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Write(
"A.mat", *Op);
402 Teuchos::RCP<MultiVector> homogRhsVec = MultiVectorFactory::Build(nspVector2->getMap(), nspVector2->getNumVectors(),
true);
403 homogRhsVec->putScalar(0.0);
408 H.
Iterate(*homogRhsVec, *nspVector2, 1,
false);
411 Finest->Set(
"Nullspace", nspVector2);
413 Xpetra::IO<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Write(
"new_nsp.vec", *nspVector2);