147 Teuchos::ParameterList paramList = paramList_in;
160 MUELU_READ_PARAM(paramList,
"aggregation: type", std::string,
"Uncoupled", agg_type);
162 MUELU_READ_PARAM(paramList,
"aggregation: damping factor",
double, (
double)4/(
double)3, agg_damping);
164 MUELU_READ_PARAM(paramList,
"aggregation: nodes per aggregate",
int, 1, minPerAgg);
165 MUELU_READ_PARAM(paramList,
"aggregation: keep Dirichlet bcs",
bool,
false, bKeepDirichletBcs);
166 MUELU_READ_PARAM(paramList,
"aggregation: max neighbours already aggregated",
int, 0, maxNbrAlreadySelected);
167 MUELU_READ_PARAM(paramList,
"aggregation: aux: enable",
bool,
false, agg_use_aux);
168 MUELU_READ_PARAM(paramList,
"aggregation: aux: threshold",
double,
false, agg_aux_thresh);
170 MUELU_READ_PARAM(paramList,
"null space: type", std::string,
"default vectors", nullspaceType);
171 MUELU_READ_PARAM(paramList,
"null space: dimension",
int, -1, nullspaceDim);
172 MUELU_READ_PARAM(paramList,
"null space: vectors",
double*, NULL, nullspaceVec);
174 MUELU_READ_PARAM(paramList,
"energy minimization: enable",
bool,
false, bEnergyMinimization);
176 MUELU_READ_PARAM(paramList,
"RAP: fix diagonal",
bool,
false, bFixDiagonal);
189 ParameterList paramListWithSubList;
191 paramList = paramListWithSubList;
194 bool setKokkosRefactor =
false;
195 bool useKokkosRefactor;
196# ifdef HAVE_MUELU_SERIAL
197 if (
typeid(
Node).name() ==
typeid(Tpetra::KokkosCompat::KokkosSerialWrapperNode).name())
198 useKokkosRefactor =
false;
200# ifdef HAVE_MUELU_OPENMP
201 if (
typeid(
Node).name() ==
typeid(Tpetra::KokkosCompat::KokkosOpenMPWrapperNode).name())
202 useKokkosRefactor =
true;
204# ifdef HAVE_MUELU_CUDA
205 if (
typeid(
Node).name() ==
typeid(Tpetra::KokkosCompat::KokkosCudaWrapperNode).name())
206 useKokkosRefactor =
true;
208# ifdef HAVE_MUELU_HIP
209 if (
typeid(
Node).name() ==
typeid(Tpetra::KokkosCompat::KokkosHIPWrapperNode).name())
210 useKokkosRefactor =
true;
212# ifdef HAVE_MUELU_SYCL
213 if (
typeid(
Node).name() ==
typeid(Tpetra::KokkosCompat::KokkosSYCLWrapperNode).name())
214 useKokkosRefactor =
true;
216 if (paramList.isType<
bool>(
"use kokkos refactor")) {
217 useKokkosRefactor = paramList.get<
bool>(
"use kokkos refactor");
218 setKokkosRefactor =
true;
219 paramList.remove(
"use kokkos refactor");
227 bool validate = paramList.get(
"ML validate parameter list",
true);
230#if defined(HAVE_MUELU_ML) && defined(HAVE_MUELU_EPETRA)
232 int depth = paramList.get(
"ML validate depth", 5);
234 "ERROR: ML's Teuchos::ParameterList contains incorrect parameter!");
237 this->
GetOStream(
Warnings0) <<
"Warning: MueLu_ENABLE_ML=OFF. The parameter list cannot be validated." << std::endl;
238 paramList.set(
"ML validate parameter list",
false);
252 if (verbosityLevel == 0) eVerbLevel =
None;
253 if (verbosityLevel >= 1) eVerbLevel =
Low;
254 if (verbosityLevel >= 5) eVerbLevel =
Medium;
255 if (verbosityLevel >= 10) eVerbLevel =
High;
256 if (verbosityLevel >= 11) eVerbLevel =
Extreme;
257 if (verbosityLevel >= 42) eVerbLevel =
Test;
263 "MueLu::MLParameterListInterpreter::SetParameterList(): parameter \"aggregation: type\": only 'Uncoupled' aggregation is supported.");
266 RCP<Factory> dropFact;
267 if(useKokkosRefactor)
273 dropFact->SetParameter(
"aggregation: drop scheme",Teuchos::ParameterEntry(std::string(
"distance laplacian")));
274 dropFact->SetParameter(
"aggregation: drop tol",Teuchos::ParameterEntry(agg_aux_thresh));
278 RCP<Factory> AggFact = Teuchos::null;
279 if(useKokkosRefactor) {
285 AggFact->SetFactory(
"Graph", dropFact);
286 AggFact->SetFactory(
"DofsPerNode", dropFact);
287 AggFact->SetParameter(
"aggregation: preserve Dirichlet points", Teuchos::ParameterEntry(bKeepDirichletBcs));
288 AggFact->SetParameter(
"aggregation: ordering", Teuchos::ParameterEntry(std::string(
"natural")));
289 AggFact->SetParameter(
"aggregation: max selected neighbors", Teuchos::ParameterEntry(maxNbrAlreadySelected));
290 AggFact->SetParameter(
"aggregation: min agg size", Teuchos::ParameterEntry(minPerAgg));
293 if (verbosityLevel > 3) {
294 std::ostringstream oss;
295 oss <<
"========================= Aggregate option summary =========================" << std::endl;
296 oss <<
"min Nodes per aggregate : " << minPerAgg << std::endl;
297 oss <<
"min # of root nbrs already aggregated : " << maxNbrAlreadySelected << std::endl;
298 oss <<
"aggregate ordering : natural" << std::endl;
299 oss <<
"=============================================================================" << std::endl;
305 RCP<Factory> PtentFact;
306 if(useKokkosRefactor)
310 if (agg_damping == 0.0 && bEnergyMinimization ==
false) {
314 }
else if (agg_damping != 0.0 && bEnergyMinimization ==
false) {
316 RCP<Factory> SaPFact;
317 if(useKokkosRefactor)
321 SaPFact->SetParameter(
"sa: damping factor", ParameterEntry(agg_damping));
324 }
else if (bEnergyMinimization ==
true) {
330 RCP<RAPFactory> AcFact = rcp(
new RAPFactory() );
331 AcFact->SetParameter(
"RepairMainDiagonal", Teuchos::ParameterEntry(bFixDiagonal));
339#if defined(HAVE_MUELU_ISORROPIA) && defined(HAVE_MPI)
340 Teuchos::RCP<Factory> RebalancedPFact = Teuchos::null;
341 Teuchos::RCP<Factory> RebalancedRFact = Teuchos::null;
342 Teuchos::RCP<Factory> RepartitionFact = Teuchos::null;
343 Teuchos::RCP<RebalanceAcFactory> RebalancedAFact = Teuchos::null;
346 if (bDoRepartition == 1) {
349 RFact->SetFactory(
"P", PFact);
351 AcFact->SetFactory(
"P", PFact);
352 AcFact->SetFactory(
"R", RFact);
356 rebAmalgFact->SetFactory(
"A", AcFact);
358 MUELU_READ_PARAM(paramList,
"repartition: max min ratio",
double, 1.3, maxminratio);
359 MUELU_READ_PARAM(paramList,
"repartition: min per proc",
int, 512, minperproc);
364 Teuchos::ParameterList paramListRepFact;
365 paramListRepFact.set(
"repartition: min rows per proc", minperproc);
366 paramListRepFact.set(
"repartition: max imbalance", maxminratio);
367 RepartitionHeuristicFact->SetParameterList(paramListRepFact);
369 RepartitionHeuristicFact->SetFactory(
"A", AcFact);
373 isoInterface->SetFactory(
"A", AcFact);
374 isoInterface->SetFactory(
"number of partitions", RepartitionHeuristicFact);
375 isoInterface->SetFactory(
"UnAmalgamationInfo", rebAmalgFact);
379 repInterface->SetFactory(
"A", AcFact);
380 repInterface->SetFactory(
"number of partitions", RepartitionHeuristicFact);
381 repInterface->SetFactory(
"AmalgamatedPartition", isoInterface);
386 RepartitionFact->SetFactory(
"A", AcFact);
387 RepartitionFact->SetFactory(
"number of partitions", RepartitionHeuristicFact);
388 RepartitionFact->SetFactory(
"Partition", repInterface);
392 RebalancedPFact->SetParameter(
"type", Teuchos::ParameterEntry(std::string(
"Interpolation")));
393 RebalancedPFact->SetFactory(
"P", PFact);
394 RebalancedPFact->SetFactory(
"Nullspace", PtentFact);
395 RebalancedPFact->SetFactory(
"Importer", RepartitionFact);
398 RebalancedRFact->SetParameter(
"type", Teuchos::ParameterEntry(std::string(
"Restriction")));
399 RebalancedRFact->SetFactory(
"R", RFact);
400 RebalancedRFact->SetFactory(
"Importer", RepartitionFact);
404 RebalancedAFact->SetFactory(
"A", AcFact);
420 if (nullspaceType !=
"default vectors") {
421 TEUCHOS_TEST_FOR_EXCEPTION(nullspaceType !=
"pre-computed",
Exceptions::RuntimeError,
"MueLu::MLParameterListInterpreter: no valid nullspace (no pre-computed null space). error.");
422 TEUCHOS_TEST_FOR_EXCEPTION(nullspaceDim == -1,
Exceptions::RuntimeError,
"MueLu::MLParameterListInterpreter: no valid nullspace (nullspace dim == -1). error.");
423 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\'");
429 Teuchos::RCP<NullspaceFactory> nspFact = Teuchos::rcp(
new NullspaceFactory(
"Nullspace"));
430 nspFact->SetFactory(
"Nullspace", PtentFact);
451 ParameterList& coarseList = paramList.sublist(
"coarse: list");
453 if (!coarseList.isParameter(
"smoother: type"))
454 coarseList.set(
"smoother: type",
"Amesos-KLU");
466 for (
int levelID=0; levelID < maxLevels; levelID++) {
473 if (setKokkosRefactor)
474 manager->SetKokkosRefactor(useKokkosRefactor);
484 ParameterList levelSmootherParam =
GetMLSubList(paramList,
"smoother", levelID);
489 RCP<SmootherFactory> smootherFact =
GetSmootherFactory(levelSmootherParam, Teuchos::null);
491 manager->SetFactory(
"Smoother", smootherFact);
498 manager->SetFactory(
"CoarseSolver", coarseFact);
499 manager->SetFactory(
"Graph", dropFact);
500 manager->SetFactory(
"Aggregates", AggFact);
501 manager->SetFactory(
"DofsPerNode", dropFact);
502 manager->SetFactory(
"Ptent", PtentFact);
504#if defined(HAVE_MUELU_ISORROPIA) && defined(HAVE_MPI)
505 if (bDoRepartition == 1) {
506 manager->SetFactory(
"A", RebalancedAFact);
507 manager->SetFactory(
"P", RebalancedPFact);
508 manager->SetFactory(
"R", RebalancedRFact);
509 manager->SetFactory(
"Nullspace", RebalancedPFact);
510 manager->SetFactory(
"Importer", RepartitionFact);
513 manager->SetFactory(
"Nullspace", nspFact);
514 manager->SetFactory(
"A", AcFact);
515 manager->SetFactory(
"P", PFact);
516 manager->SetFactory(
"R", RFact);
517#if defined(HAVE_MUELU_ISORROPIA) && defined(HAVE_MPI)
531 RCP<Level> fineLevel = H.
GetLevel(0);
532 RCP<Operator> Op = fineLevel->Get<RCP<Operator> >(
"A");
533 RCP<Matrix> A = rcp_dynamic_cast<Matrix>(Op);
535 const RCP<const Map> rowMap = fineLevel->Get< RCP<Matrix> >(
"A")->getRowMap();
536 RCP<MultiVector> nullspace = MultiVectorFactory::Build(rowMap,
nullspaceDim_,
true);
538 for (
size_t i=0; i < Teuchos::as<size_t>(
nullspaceDim_); i++) {
539 Teuchos::ArrayRCP<Scalar> nullspacei = nullspace->getDataNonConst(i);
540 const size_t myLength = nullspace->getLocalLength();
542 for (
size_t j = 0; j < myLength; j++) {
547 fineLevel->Set(
"Nullspace", nullspace);
552 size_t num_coords = 0;
553 double * coordPTR[3];
567 Teuchos::RCP<Level> fineLevel = H.
GetLevel(0);
568 Teuchos::RCP<Operator> Op = fineLevel->Get<RCP<Operator> >(
"A");
569 Teuchos::RCP<Matrix> A = rcp_dynamic_cast<Matrix>(Op);
571 const Teuchos::RCP<const Map> rowMap = fineLevel->Get< RCP<Matrix> >(
"A")->getRowMap();
572 Teuchos::RCP<MultiVector> coordinates = MultiVectorFactory::Build(rowMap, num_coords,
true);
574 for (
size_t i=0; i < num_coords; i++) {
575 Teuchos::ArrayRCP<Scalar> coordsi = coordinates->getDataNonConst(i);
576 const size_t myLength = coordinates->getLocalLength();
577 for (
size_t j = 0; j < myLength; j++) {
578 coordsi[j] = coordPTR[i][j];
581 fineLevel->Set(
"Coordinates",coordinates);
593 const RCP<FactoryBase> & AFact)
595 typedef Teuchos::ScalarTraits<Scalar> STS;
598 std::string type =
"symmetric Gauss-Seidel";
620 if (paramList.isParameter(
"smoother: type")) type = paramList.get<std::string>(
"smoother: type");
621 TEUCHOS_TEST_FOR_EXCEPTION(type.empty(),
Exceptions::RuntimeError,
"MueLu::MLParameterListInterpreter: no \"smoother: type\" in the smoother parameter list" << std::endl << paramList);
627 RCP<SmootherPrototype> smooProto;
628 std::string ifpackType;
629 Teuchos::ParameterList smootherParamList;
631 if (type ==
"Jacobi" || type ==
"Gauss-Seidel" || type ==
"symmetric Gauss-Seidel") {
632 if (type ==
"symmetric Gauss-Seidel") type =
"Symmetric Gauss-Seidel";
634 ifpackType =
"RELAXATION";
635 smootherParamList.set(
"relaxation: type", type);
637 MUELU_COPY_PARAM(paramList,
"smoother: sweeps",
int, 2, smootherParamList,
"relaxation: sweeps");
638 MUELU_COPY_PARAM(paramList,
"smoother: damping factor",
Scalar, one, smootherParamList,
"relaxation: damping factor");
641 smooProto->SetFactory(
"A", AFact);
643 }
else if (type ==
"Chebyshev" || type ==
"MLS") {
645 ifpackType =
"CHEBYSHEV";
647 MUELU_COPY_PARAM(paramList,
"smoother: sweeps",
int, 2, smootherParamList,
"chebyshev: degree");
648 if (paramList.isParameter(
"smoother: MLS alpha")) {
649 MUELU_COPY_PARAM(paramList,
"smoother: MLS alpha",
double, 20, smootherParamList,
"chebyshev: ratio eigenvalue");
651 MUELU_COPY_PARAM(paramList,
"smoother: Chebyshev alpha",
double, 20, smootherParamList,
"chebyshev: ratio eigenvalue");
656 smooProto->SetFactory(
"A", AFact);
658 }
else if (type ==
"Hiptmair") {
659 ifpackType =
"HIPTMAIR";
660 std::string subSmootherType =
"Chebyshev";
661 if (paramList.isParameter(
"subsmoother: type"))
662 subSmootherType = paramList.get<std::string>(
"subsmoother: type");
663 std::string subSmootherIfpackType;
664 if (subSmootherType ==
"Chebyshev")
665 subSmootherIfpackType =
"CHEBYSHEV";
666 else if (subSmootherType ==
"Jacobi" || subSmootherType ==
"Gauss-Seidel" || subSmootherType ==
"symmetric Gauss-Seidel") {
667 if (subSmootherType ==
"symmetric Gauss-Seidel") subSmootherType =
"Symmetric Gauss-Seidel";
668 subSmootherIfpackType =
"RELAXATION";
670 TEUCHOS_TEST_FOR_EXCEPTION(
true,
Exceptions::RuntimeError,
"MueLu::MLParameterListInterpreter: unknown smoother type. '" << subSmootherType <<
"' not supported by MueLu.");
672 smootherParamList.set(
"hiptmair: smoother type 1", subSmootherIfpackType);
673 smootherParamList.set(
"hiptmair: smoother type 2", subSmootherIfpackType);
675 auto smoother1ParamList = smootherParamList.sublist(
"hiptmair: smoother list 1");
676 auto smoother2ParamList = smootherParamList.sublist(
"hiptmair: smoother list 2");
678 if (subSmootherType ==
"Chebyshev") {
679 MUELU_COPY_PARAM(paramList,
"subsmoother: edge sweeps",
int, 2, smoother1ParamList,
"chebyshev: degree");
680 MUELU_COPY_PARAM(paramList,
"subsmoother: node sweeps",
int, 2, smoother2ParamList,
"chebyshev: degree");
682 MUELU_COPY_PARAM(paramList,
"subsmoother: Chebyshev",
double, 20, smoother1ParamList,
"chebyshev: ratio eigenvalue");
683 MUELU_COPY_PARAM(paramList,
"subsmoother: Chebyshev",
double, 20, smoother2ParamList,
"chebyshev: ratio eigenvalue");
685 MUELU_COPY_PARAM(paramList,
"subsmoother: edge sweeps",
int, 2, smoother1ParamList,
"relaxation: sweeps");
686 MUELU_COPY_PARAM(paramList,
"subsmoother: node sweeps",
int, 2, smoother2ParamList,
"relaxation: sweeps");
688 MUELU_COPY_PARAM(paramList,
"subsmoother: SGS damping factor",
double, 0.8, smoother2ParamList,
"relaxation: damping factor");
693 smooProto->SetFactory(
"A", AFact);
695 }
else if (type ==
"IFPACK") {
697#if defined(HAVE_MUELU_EPETRA) && defined(HAVE_MUELU_IFPACK)
698 ifpackType = paramList.get<std::string>(
"smoother: ifpack type");
700 if (ifpackType ==
"ILU") {
703 if (paramList.isParameter(
"smoother: ifpack level-of-fill"))
704 smootherParamList.set(
"fact: level-of-fill", Teuchos::as<int>(paramList.get<
double>(
"smoother: ifpack level-of-fill")));
705 else smootherParamList.set(
"fact: level-of-fill", as<int>(0));
707 MUELU_COPY_PARAM(paramList,
"smoother: ifpack overlap",
int, 2, smootherParamList,
"partitioner: overlap");
713 paramList.get<
int> (
"smoother: ifpack overlap"));
714 smooProto->SetFactory(
"A", AFact);
716 TEUCHOS_TEST_FOR_EXCEPTION(
true,
Exceptions::RuntimeError,
"MueLu::MLParameterListInterpreter: unknown ML smoother type " + type +
" (IFPACK) not supported by MueLu. Only ILU is supported.");
719 TEUCHOS_TEST_FOR_EXCEPTION(
true,
Exceptions::RuntimeError,
"MueLu::MLParameterListInterpreter: MueLu compiled without Ifpack support");
722 }
else if (type.length() > strlen(
"Amesos") && type.substr(0, strlen(
"Amesos")) ==
"Amesos") {
723 std::string solverType = type.substr(strlen(
"Amesos")+1);
727 const int validatorSize = 5;
728 std::string validator[validatorSize] = {
"Superlu",
"Superludist",
"KLU",
"UMFPACK",
"MUMPS"};
729 for (
int i=0; i < validatorSize; i++) {
if (validator[i] == solverType) valid =
true; }
730 TEUCHOS_TEST_FOR_EXCEPTION(!valid,
Exceptions::RuntimeError,
"MueLu::MLParameterListInterpreter: unknown smoother type. '" << type <<
"' not supported.");
733 std::transform(solverType.begin()+1, solverType.end(), solverType.begin()+1, ::tolower);
735 smooProto = Teuchos::rcp(
new DirectSolver(solverType, Teuchos::ParameterList()) );
736 smooProto->SetFactory(
"A", AFact);
740 TEUCHOS_TEST_FOR_EXCEPTION(
true,
Exceptions::RuntimeError,
"MueLu::MLParameterListInterpreter: unknown smoother type. '" << type <<
"' not supported by MueLu.");
743 TEUCHOS_TEST_FOR_EXCEPTION(smooProto == Teuchos::null,
Exceptions::RuntimeError,
"MueLu::MLParameterListInterpreter: no smoother prototype. fatal error.");
752 MUELU_READ_PARAM(paramList,
"smoother: pre or post", std::string,
"both", preOrPost);
753 if (preOrPost ==
"both") {
754 SmooFact->SetSmootherPrototypes(smooProto, smooProto);
755 }
else if (preOrPost ==
"pre") {
756 SmooFact->SetSmootherPrototypes(smooProto, Teuchos::null);
757 }
else if (preOrPost ==
"post") {
758 SmooFact->SetSmootherPrototypes(Teuchos::null, smooProto);