150 Teuchos::ParameterList paramList = paramList_in;
163 MUELU_READ_PARAM(paramList,
"aggregation: type", std::string,
"Uncoupled", agg_type);
165 MUELU_READ_PARAM(paramList,
"aggregation: damping factor",
double, (
double)4/(
double)3, agg_damping);
167 MUELU_READ_PARAM(paramList,
"aggregation: nodes per aggregate",
int, 1, minPerAgg);
168 MUELU_READ_PARAM(paramList,
"aggregation: keep Dirichlet bcs",
bool,
false, bKeepDirichletBcs);
169 MUELU_READ_PARAM(paramList,
"aggregation: max neighbours already aggregated",
int, 0, maxNbrAlreadySelected);
170 MUELU_READ_PARAM(paramList,
"aggregation: aux: enable",
bool,
false, agg_use_aux);
171 MUELU_READ_PARAM(paramList,
"aggregation: aux: threshold",
double,
false, agg_aux_thresh);
173 MUELU_READ_PARAM(paramList,
"null space: type", std::string,
"default vectors", nullspaceType);
174 MUELU_READ_PARAM(paramList,
"null space: dimension",
int, -1, nullspaceDim);
175 MUELU_READ_PARAM(paramList,
"null space: vectors",
double*, NULL, nullspaceVec);
177 MUELU_READ_PARAM(paramList,
"energy minimization: enable",
bool,
false, bEnergyMinimization);
179 MUELU_READ_PARAM(paramList,
"RAP: fix diagonal",
bool,
false, bFixDiagonal);
192 ParameterList paramListWithSubList;
194 paramList = paramListWithSubList;
197 bool setKokkosRefactor =
false;
198 bool useKokkosRefactor;
199# ifdef HAVE_MUELU_SERIAL
200 if (
typeid(
Node).name() ==
typeid(Kokkos::Compat::KokkosSerialWrapperNode).name())
201 useKokkosRefactor =
false;
203# ifdef HAVE_MUELU_OPENMP
204 if (
typeid(
Node).name() ==
typeid(Kokkos::Compat::KokkosOpenMPWrapperNode).name())
205 useKokkosRefactor =
true;
207# ifdef HAVE_MUELU_CUDA
208 if (
typeid(
Node).name() ==
typeid(Kokkos::Compat::KokkosCudaWrapperNode).name())
209 useKokkosRefactor =
true;
211# ifdef HAVE_MUELU_HIP
212 if (
typeid(
Node).name() ==
typeid(Kokkos::Compat::KokkosHIPWrapperNode).name())
213 useKokkosRefactor =
true;
215 if (paramList.isType<
bool>(
"use kokkos refactor")) {
216 useKokkosRefactor = paramList.get<
bool>(
"use kokkos refactor");
217 setKokkosRefactor =
true;
218 paramList.remove(
"use kokkos refactor");
226 bool validate = paramList.get(
"ML validate parameter list",
true);
229#if defined(HAVE_MUELU_ML) && defined(HAVE_MUELU_EPETRA)
231 int depth = paramList.get(
"ML validate depth", 5);
233 "ERROR: ML's Teuchos::ParameterList contains incorrect parameter!");
236 this->GetOStream(
Warnings0) <<
"Warning: MueLu_ENABLE_ML=OFF. The parameter list cannot be validated." << std::endl;
237 paramList.set(
"ML validate parameter list",
false);
245 blksize_ = nDofsPerNode;
251 if (verbosityLevel == 0) eVerbLevel =
None;
252 if (verbosityLevel >= 1) eVerbLevel =
Low;
253 if (verbosityLevel >= 5) eVerbLevel =
Medium;
254 if (verbosityLevel >= 10) eVerbLevel =
High;
255 if (verbosityLevel >= 11) eVerbLevel =
Extreme;
256 if (verbosityLevel >= 42) eVerbLevel =
Test;
258 this->verbosity_ = eVerbLevel;
262 "MueLu::MLParameterListInterpreter::SetParameterList(): parameter \"aggregation: type\": only 'Uncoupled' or 'Coupled' aggregation is supported.");
265 RCP<Factory> dropFact;
266 if(useKokkosRefactor)
272 dropFact->SetParameter(
"aggregation: drop scheme",Teuchos::ParameterEntry(std::string(
"distance laplacian")));
273 dropFact->SetParameter(
"aggregation: drop tol",Teuchos::ParameterEntry(agg_aux_thresh));
276 RCP<Factory> AggFact = Teuchos::null;
277 if (agg_type ==
"Uncoupled") {
279 RCP<Factory> MyUncoupledAggFact;
280 if(useKokkosRefactor) {
286 MyUncoupledAggFact->SetFactory(
"Graph", dropFact);
287 MyUncoupledAggFact->SetFactory(
"DofsPerNode", dropFact);
288 MyUncoupledAggFact->SetParameter(
"aggregation: preserve Dirichlet points", Teuchos::ParameterEntry(bKeepDirichletBcs));
289 MyUncoupledAggFact->SetParameter(
"aggregation: ordering", Teuchos::ParameterEntry(std::string(
"natural")));
290 MyUncoupledAggFact->SetParameter(
"aggregation: max selected neighbors", Teuchos::ParameterEntry(maxNbrAlreadySelected));
291 MyUncoupledAggFact->SetParameter(
"aggregation: min agg size", Teuchos::ParameterEntry(minPerAgg));
293 AggFact = MyUncoupledAggFact;
296 if(useKokkosRefactor) {
300 CoupledAggFact2->SetMinNodesPerAggregate(minPerAgg);
301 CoupledAggFact2->SetMaxNeighAlreadySelected(maxNbrAlreadySelected);
302 CoupledAggFact2->SetOrdering(
"natural");
303 CoupledAggFact2->SetPhase3AggCreation(0.5);
304 CoupledAggFact2->SetFactory(
"Graph", dropFact);
305 CoupledAggFact2->SetFactory(
"DofsPerNode", dropFact);
306 AggFact = CoupledAggFact2;
309 if (verbosityLevel > 3) {
310 std::ostringstream oss;
311 oss <<
"========================= Aggregate option summary  =========================" << std::endl;
312 oss <<
"min Nodes per aggregate : Â Â Â Â Â Â Â " << minPerAgg << std::endl;
313 oss <<
"min # of root nbrs already aggregated : " << maxNbrAlreadySelected << std::endl;
314 oss <<
"aggregate ordering : Â Â Â Â Â Â Â Â Â Â natural" << std::endl;
315 oss <<
"=============================================================================" << std::endl;
316 this->GetOStream(
Runtime1) << oss.str();
321 RCP<Factory> PtentFact;
322 if(useKokkosRefactor)
326 if (agg_damping == 0.0 && bEnergyMinimization ==
false) {
330 }
else if (agg_damping != 0.0 && bEnergyMinimization ==
false) {
332 RCP<Factory> SaPFact;
333 if(useKokkosRefactor)
337 SaPFact->SetParameter(
"sa: damping factor", ParameterEntry(agg_damping));
340 }
else if (bEnergyMinimization ==
true) {
346 RCP<RAPFactory> AcFact = rcp(
new RAPFactory() );
347 AcFact->SetParameter(
"RepairMainDiagonal", Teuchos::ParameterEntry(bFixDiagonal));
348 for (
size_t i = 0; i<TransferFacts_.size(); i++) {
349 AcFact->AddTransferFactory(TransferFacts_[i]);
355#if defined(HAVE_MUELU_ISORROPIA) && defined(HAVE_MPI)
356 Teuchos::RCP<Factory> RebalancedPFact = Teuchos::null;
357 Teuchos::RCP<Factory> RebalancedRFact = Teuchos::null;
358 Teuchos::RCP<Factory> RepartitionFact = Teuchos::null;
359 Teuchos::RCP<RebalanceAcFactory> RebalancedAFact = Teuchos::null;
362 if (bDoRepartition == 1) {
365 RFact->SetFactory(
"P", PFact);
367 AcFact->SetFactory(
"P", PFact);
368 AcFact->SetFactory(
"R", RFact);
372 rebAmalgFact->SetFactory(
"A", AcFact);
374 MUELU_READ_PARAM(paramList,
"repartition: max min ratio",
double, 1.3, maxminratio);
375 MUELU_READ_PARAM(paramList,
"repartition: min per proc",
int, 512, minperproc);
380 Teuchos::ParameterList paramListRepFact;
381 paramListRepFact.set(
"repartition: min rows per proc", minperproc);
382 paramListRepFact.set(
"repartition: max imbalance", maxminratio);
383 RepartitionHeuristicFact->SetParameterList(paramListRepFact);
385 RepartitionHeuristicFact->SetFactory(
"A", AcFact);
389 isoInterface->SetFactory(
"A", AcFact);
390 isoInterface->SetFactory(
"number of partitions", RepartitionHeuristicFact);
391 isoInterface->SetFactory(
"UnAmalgamationInfo", rebAmalgFact);
395 repInterface->SetFactory(
"A", AcFact);
396 repInterface->SetFactory(
"number of partitions", RepartitionHeuristicFact);
397 repInterface->SetFactory(
"AmalgamatedPartition", isoInterface);
402 RepartitionFact->SetFactory(
"A", AcFact);
403 RepartitionFact->SetFactory(
"number of partitions", RepartitionHeuristicFact);
404 RepartitionFact->SetFactory(
"Partition", repInterface);
408 RebalancedPFact->SetParameter(
"type", Teuchos::ParameterEntry(std::string(
"Interpolation")));
409 RebalancedPFact->SetFactory(
"P", PFact);
410 RebalancedPFact->SetFactory(
"Nullspace", PtentFact);
411 RebalancedPFact->SetFactory(
"Importer", RepartitionFact);
414 RebalancedRFact->SetParameter(
"type", Teuchos::ParameterEntry(std::string(
"Restriction")));
415 RebalancedRFact->SetFactory(
"R", RFact);
416 RebalancedRFact->SetFactory(
"Importer", RepartitionFact);
420 RebalancedAFact->SetFactory(
"A", AcFact);
436 if (nullspaceType !=
"default vectors") {
437 TEUCHOS_TEST_FOR_EXCEPTION(nullspaceType !=
"pre-computed",
Exceptions::RuntimeError,
"MueLu::MLParameterListInterpreter: no valid nullspace (no pre-computed null space). error.");
438 TEUCHOS_TEST_FOR_EXCEPTION(nullspaceDim == -1,
Exceptions::RuntimeError,
"MueLu::MLParameterListInterpreter: no valid nullspace (nullspace dim == -1). error.");
439 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\'");
441 nullspaceDim_ = nullspaceDim;
442 nullspace_ = nullspaceVec;
445 Teuchos::RCP<NullspaceFactory> nspFact = Teuchos::rcp(
new NullspaceFactory(
"Nullspace"));
446 nspFact->SetFactory(
"Nullspace", PtentFact);
461 this->numDesiredLevel_ = maxLevels;
462 this->maxCoarseSize_ = maxCoarseSize;
467 ParameterList& coarseList = paramList.sublist(
"coarse: list");
469 if (!coarseList.isParameter(
"smoother: type"))
470 coarseList.set(
"smoother: type",
"Amesos-KLU");
471 RCP<SmootherFactory> coarseFact = GetSmootherFactory(coarseList, Teuchos::null);
482 for (
int levelID=0; levelID < maxLevels; levelID++) {
489 if (setKokkosRefactor)
490 manager->SetKokkosRefactor(useKokkosRefactor);
500 ParameterList levelSmootherParam =
GetMLSubList(paramList,
"smoother", levelID);
505 RCP<SmootherFactory> smootherFact = GetSmootherFactory(levelSmootherParam, Teuchos::null);
507 manager->SetFactory(
"Smoother", smootherFact);
514 manager->SetFactory(
"CoarseSolver", coarseFact);
515 manager->SetFactory(
"Graph", dropFact);
516 manager->SetFactory(
"Aggregates", AggFact);
517 manager->SetFactory(
"DofsPerNode", dropFact);
518 manager->SetFactory(
"Ptent", PtentFact);
520#if defined(HAVE_MUELU_ISORROPIA) && defined(HAVE_MPI)
521 if (bDoRepartition == 1) {
522 manager->SetFactory(
"A", RebalancedAFact);
523 manager->SetFactory(
"P", RebalancedPFact);
524 manager->SetFactory(
"R", RebalancedRFact);
525 manager->SetFactory(
"Nullspace", RebalancedPFact);
526 manager->SetFactory(
"Importer", RepartitionFact);
529 manager->SetFactory(
"Nullspace", nspFact);
530 manager->SetFactory(
"A", AcFact);
531 manager->SetFactory(
"P", PFact);
532 manager->SetFactory(
"R", RFact);
533#if defined(HAVE_MUELU_ISORROPIA) && defined(HAVE_MPI)
537 this->AddFactoryManager(levelID, 1, manager);
546 if (nullspace_ != NULL) {
547 RCP<Level> fineLevel = H.
GetLevel(0);
548 RCP<Operator> Op = fineLevel->Get<RCP<Operator> >(
"A");
549 RCP<Matrix> A = rcp_dynamic_cast<Matrix>(Op);
551 const RCP<const Map> rowMap = fineLevel->Get< RCP<Matrix> >(
"A")->getRowMap();
552 RCP<MultiVector> nullspace = MultiVectorFactory::Build(rowMap, nullspaceDim_,
true);
554 for (
size_t i=0; i < Teuchos::as<size_t>(nullspaceDim_); i++) {
555 Teuchos::ArrayRCP<Scalar> nullspacei = nullspace->getDataNonConst(i);
556 const size_t myLength = nullspace->getLocalLength();
558 for (
size_t j = 0; j < myLength; j++) {
559 nullspacei[j] = nullspace_[i*myLength + j];
563 fineLevel->Set(
"Nullspace", nullspace);
568 size_t num_coords = 0;
569 double * coordPTR[3];
571 coordPTR[0] = xcoord_;
574 coordPTR[1] = ycoord_;
577 coordPTR[2] = zcoord_;
583 Teuchos::RCP<Level> fineLevel = H.
GetLevel(0);
584 Teuchos::RCP<Operator> Op = fineLevel->Get<RCP<Operator> >(
"A");
585 Teuchos::RCP<Matrix> A = rcp_dynamic_cast<Matrix>(Op);
587 const Teuchos::RCP<const Map> rowMap = fineLevel->Get< RCP<Matrix> >(
"A")->getRowMap();
588 Teuchos::RCP<MultiVector> coordinates = MultiVectorFactory::Build(rowMap, num_coords,
true);
590 for (
size_t i=0; i < num_coords; i++) {
591 Teuchos::ArrayRCP<Scalar> coordsi = coordinates->getDataNonConst(i);
592 const size_t myLength = coordinates->getLocalLength();
593 for (
size_t j = 0; j < myLength; j++) {
594 coordsi[j] = coordPTR[i][j];
597 fineLevel->Set(
"Coordinates",coordinates);
609 const RCP<FactoryBase> & AFact)
611 typedef Teuchos::ScalarTraits<Scalar> STS;
614 std::string type =
"symmetric Gauss-Seidel";
636 if (paramList.isParameter(
"smoother: type")) type = paramList.get<std::string>(
"smoother: type");
637 TEUCHOS_TEST_FOR_EXCEPTION(type.empty(),
Exceptions::RuntimeError,
"MueLu::MLParameterListInterpreter: no \"smoother: type\" in the smoother parameter list" << std::endl << paramList);
643 RCP<SmootherPrototype> smooProto;
644 std::string ifpackType;
645 Teuchos::ParameterList smootherParamList;
647 if (type ==
"Jacobi" || type ==
"Gauss-Seidel" || type ==
"symmetric Gauss-Seidel") {
648 if (type ==
"symmetric Gauss-Seidel") type =
"Symmetric Gauss-Seidel";
650 ifpackType =
"RELAXATION";
651 smootherParamList.set(
"relaxation: type", type);
653 MUELU_COPY_PARAM(paramList,
"smoother: sweeps",
int, 2, smootherParamList,
"relaxation: sweeps");
654 MUELU_COPY_PARAM(paramList,
"smoother: damping factor",
Scalar, one, smootherParamList,
"relaxation: damping factor");
657 smooProto->SetFactory(
"A", AFact);
659 }
else if (type ==
"Chebyshev" || type ==
"MLS") {
661 ifpackType =
"CHEBYSHEV";
663 MUELU_COPY_PARAM(paramList,
"smoother: sweeps",
int, 2, smootherParamList,
"chebyshev: degree");
664 if (paramList.isParameter(
"smoother: MLS alpha")) {
665 MUELU_COPY_PARAM(paramList,
"smoother: MLS alpha",
double, 20, smootherParamList,
"chebyshev: ratio eigenvalue");
667 MUELU_COPY_PARAM(paramList,
"smoother: Chebyshev alpha",
double, 20, smootherParamList,
"chebyshev: ratio eigenvalue");
672 smooProto->SetFactory(
"A", AFact);
674 }
else if (type ==
"Hiptmair") {
675 ifpackType =
"HIPTMAIR";
676 std::string subSmootherType =
"Chebyshev";
677 if (paramList.isParameter(
"subsmoother: type"))
678 subSmootherType = paramList.get<std::string>(
"subsmoother: type");
679 std::string subSmootherIfpackType;
680 if (subSmootherType ==
"Chebyshev")
681 subSmootherIfpackType =
"CHEBYSHEV";
682 else if (subSmootherType ==
"Jacobi" || subSmootherType ==
"Gauss-Seidel" || subSmootherType ==
"symmetric Gauss-Seidel") {
683 if (subSmootherType ==
"symmetric Gauss-Seidel") subSmootherType =
"Symmetric Gauss-Seidel";
684 subSmootherIfpackType =
"RELAXATION";
686 TEUCHOS_TEST_FOR_EXCEPTION(
true,
Exceptions::RuntimeError,
"MueLu::MLParameterListInterpreter: unknown smoother type. '" << subSmootherType <<
"' not supported by MueLu.");
688 smootherParamList.set(
"hiptmair: smoother type 1", subSmootherIfpackType);
689 smootherParamList.set(
"hiptmair: smoother type 2", subSmootherIfpackType);
691 auto smoother1ParamList = smootherParamList.sublist(
"hiptmair: smoother list 1");
692 auto smoother2ParamList = smootherParamList.sublist(
"hiptmair: smoother list 2");
694 if (subSmootherType ==
"Chebyshev") {
695 MUELU_COPY_PARAM(paramList,
"subsmoother: edge sweeps",
int, 2, smoother1ParamList,
"chebyshev: degree");
696 MUELU_COPY_PARAM(paramList,
"subsmoother: node sweeps",
int, 2, smoother2ParamList,
"chebyshev: degree");
698 MUELU_COPY_PARAM(paramList,
"subsmoother: Chebyshev",
double, 20, smoother1ParamList,
"chebyshev: ratio eigenvalue");
699 MUELU_COPY_PARAM(paramList,
"subsmoother: Chebyshev",
double, 20, smoother2ParamList,
"chebyshev: ratio eigenvalue");
701 MUELU_COPY_PARAM(paramList,
"subsmoother: edge sweeps",
int, 2, smoother1ParamList,
"relaxation: sweeps");
702 MUELU_COPY_PARAM(paramList,
"subsmoother: node sweeps",
int, 2, smoother2ParamList,
"relaxation: sweeps");
704 MUELU_COPY_PARAM(paramList,
"subsmoother: SGS damping factor",
double, 0.8, smoother2ParamList,
"relaxation: damping factor");
709 smooProto->SetFactory(
"A", AFact);
711 }
else if (type ==
"IFPACK") {
713#if defined(HAVE_MUELU_EPETRA) && defined(HAVE_MUELU_IFPACK)
714 ifpackType = paramList.get<std::string>(
"smoother: ifpack type");
716 if (ifpackType ==
"ILU") {
719 if (paramList.isParameter(
"smoother: ifpack level-of-fill"))
720 smootherParamList.set(
"fact: level-of-fill", Teuchos::as<int>(paramList.get<
double>(
"smoother: ifpack level-of-fill")));
721 else smootherParamList.set(
"fact: level-of-fill", as<int>(0));
723 MUELU_COPY_PARAM(paramList,
"smoother: ifpack overlap",
int, 2, smootherParamList,
"partitioner: overlap");
727 MueLu::GetIfpackSmoother<Scalar, LocalOrdinal, GlobalOrdinal, Node> (ifpackType,
729 paramList.get<
int> (
"smoother: ifpack overlap"));
730 smooProto->SetFactory(
"A", AFact);
732 TEUCHOS_TEST_FOR_EXCEPTION(
true,
Exceptions::RuntimeError,
"MueLu::MLParameterListInterpreter: unknown ML smoother type " + type +
" (IFPACK) not supported by MueLu. Only ILU is supported.");
735 TEUCHOS_TEST_FOR_EXCEPTION(
true,
Exceptions::RuntimeError,
"MueLu::MLParameterListInterpreter: MueLu compiled without Ifpack support");
738 }
else if (type.length() > strlen(
"Amesos") && type.substr(0, strlen(
"Amesos")) ==
"Amesos") {
739 std::string solverType = type.substr(strlen(
"Amesos")+1);
743 const int validatorSize = 5;
744 std::string validator[validatorSize] = {
"Superlu",
"Superludist",
"KLU",
"UMFPACK",
"MUMPS"};
745 for (
int i=0; i < validatorSize; i++) {
if (validator[i] == solverType) valid =
true; }
746 TEUCHOS_TEST_FOR_EXCEPTION(!valid,
Exceptions::RuntimeError,
"MueLu::MLParameterListInterpreter: unknown smoother type. '" << type <<
"' not supported.");
749 std::transform(solverType.begin()+1, solverType.end(), solverType.begin()+1, ::tolower);
751 smooProto = Teuchos::rcp(
new DirectSolver(solverType, Teuchos::ParameterList()) );
752 smooProto->SetFactory(
"A", AFact);
756 TEUCHOS_TEST_FOR_EXCEPTION(
true,
Exceptions::RuntimeError,
"MueLu::MLParameterListInterpreter: unknown smoother type. '" << type <<
"' not supported by MueLu.");
759 TEUCHOS_TEST_FOR_EXCEPTION(smooProto == Teuchos::null,
Exceptions::RuntimeError,
"MueLu::MLParameterListInterpreter: no smoother prototype. fatal error.");
768 MUELU_READ_PARAM(paramList,
"smoother: pre or post", std::string,
"both", preOrPost);
769 if (preOrPost ==
"both") {
770 SmooFact->SetSmootherPrototypes(smooProto, smooProto);
771 }
else if (preOrPost ==
"pre") {
772 SmooFact->SetSmootherPrototypes(smooProto, Teuchos::null);
773 }
else if (preOrPost ==
"post") {
774 SmooFact->SetSmootherPrototypes(Teuchos::null, smooProto);