void AdaptiveSaMLParameterListInterpreter<Scalar, LocalOrdinal, GlobalOrdinal, Node>::SetParameterList(const Teuchos::ParameterList & paramList_in) { Teuchos::ParameterList paramList = paramList_in; RCP<Teuchos::FancyOStream> out = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout)); // TODO: use internal out (GetOStream()) // // Read top-level of the parameter list // // hard-coded default values == ML defaults according to the manual MUELU_READ_PARAM(paramList, "ML output", int, 0, verbosityLevel); MUELU_READ_PARAM(paramList, "max levels", int, 10, maxLevels); MUELU_READ_PARAM(paramList, "PDE equations", int, 1, nDofsPerNode); MUELU_READ_PARAM(paramList, "coarse: max size", int, 128, maxCoarseSize); MUELU_READ_PARAM(paramList, "aggregation: type", std::string, "Uncoupled", agg_type); //MUELU_READ_PARAM(paramList, "aggregation: threshold", double, 0.0, agg_threshold); MUELU_READ_PARAM(paramList, "aggregation: damping factor", double, (double)4/(double)3, agg_damping); //MUELU_READ_PARAM(paramList, "aggregation: smoothing sweeps", int, 1, agg_smoothingsweeps); MUELU_READ_PARAM(paramList, "aggregation: nodes per aggregate", int, 1, minPerAgg); MUELU_READ_PARAM(paramList, "null space: type", std::string, "default vectors", nullspaceType); MUELU_READ_PARAM(paramList, "null space: dimension", int, -1, nullspaceDim); // TODO: ML default not in documentation MUELU_READ_PARAM(paramList, "null space: vectors", double*, NULL, nullspaceVec); // TODO: ML default not in documentation MUELU_READ_PARAM(paramList, "energy minimization: enable", bool, false, bEnergyMinimization); // // Move smoothers/aggregation/coarse parameters to sublists // // ML allows to have level-specific smoothers/aggregation/coarse parameters at the top level of the list or/and defined in sublists: // See also: ML Guide section 6.4.1, MueLu::CreateSublists, ML_CreateSublists ParameterList paramListWithSubList; MueLu::CreateSublists(paramList, paramListWithSubList); paramList = paramListWithSubList; // swap // std::cout << std::endl << "Parameter list after CreateSublists" << std::endl; // std::cout << paramListWithSubList << std::endl; int maxNbrAlreadySelected = 0; // Matrix option this->blksize_ = nDofsPerNode; // Translate verbosity parameter Teuchos::EVerbosityLevel eVerbLevel = Teuchos::VERB_NONE; if (verbosityLevel == 0) eVerbLevel = Teuchos::VERB_NONE; if (verbosityLevel > 0) eVerbLevel = Teuchos::VERB_LOW; if (verbosityLevel > 4) eVerbLevel = Teuchos::VERB_MEDIUM; if (verbosityLevel > 7) eVerbLevel = Teuchos::VERB_HIGH; if (verbosityLevel > 9) eVerbLevel = Teuchos::VERB_EXTREME; TEUCHOS_TEST_FOR_EXCEPTION(agg_type != "Uncoupled" && agg_type != "Coupled", Exceptions::RuntimeError, "MueLu::MLParameterListInterpreter::Setup(): parameter \"aggregation: type\": only 'Uncoupled' or 'Coupled' aggregation is supported."); // Create MueLu factories // RCP<NullspaceFactory> nspFact = rcp(new NullspaceFactory()); RCP<CoalesceDropFactory> dropFact = rcp(new CoalesceDropFactory()); //dropFact->SetVerbLevel(toMueLuVerbLevel(eVerbLevel)); RCP<FactoryBase> CoupledAggFact = Teuchos::null; if(agg_type == "Uncoupled") { // Uncoupled aggregation RCP<UncoupledAggregationFactory> CoupledAggFact2 = rcp(new UncoupledAggregationFactory()); CoupledAggFact2->SetMinNodesPerAggregate(minPerAgg); //TODO should increase if run anything other than 1D CoupledAggFact2->SetMaxNeighAlreadySelected(maxNbrAlreadySelected); CoupledAggFact2->SetOrdering("natural"); CoupledAggFact = CoupledAggFact2; } else { // Coupled Aggregation (default) RCP<CoupledAggregationFactory> CoupledAggFact2 = rcp(new CoupledAggregationFactory()); CoupledAggFact2->SetMinNodesPerAggregate(minPerAgg); //TODO should increase if run anything other than 1D CoupledAggFact2->SetMaxNeighAlreadySelected(maxNbrAlreadySelected); CoupledAggFact2->SetOrdering("natural"); CoupledAggFact2->SetPhase3AggCreation(0.5); CoupledAggFact = CoupledAggFact2; } if (verbosityLevel > 3) { // TODO fix me: Setup is a static function: we cannot use GetOStream without an object... *out << "========================= Aggregate option summary =========================" << std::endl; *out << "min Nodes per aggregate : " << minPerAgg << std::endl; *out << "min # of root nbrs already aggregated : " << maxNbrAlreadySelected << std::endl; *out << "aggregate ordering : natural" << std::endl; *out << "=============================================================================" << std::endl; } RCP<Factory> PFact; RCP<Factory> RFact; RCP<Factory> PtentFact = rcp( new TentativePFactory() ); if (agg_damping == 0.0 && bEnergyMinimization == false) { // tentative prolongation operator (PA-AMG) PFact = PtentFact; RFact = rcp( new TransPFactory() ); } else if (agg_damping != 0.0 && bEnergyMinimization == false) { // smoothed aggregation (SA-AMG) RCP<SaPFactory> SaPFact = rcp( new SaPFactory() ); SaPFact->SetParameter("sa: damping factor", ParameterEntry(agg_damping)); PFact = SaPFact; RFact = rcp( new TransPFactory() ); } else if (bEnergyMinimization == true) { // Petrov Galerkin PG-AMG smoothed aggregation (energy minimization in ML) PFact = rcp( new PgPFactory() ); RFact = rcp( new GenericRFactory() ); } RCP<RAPFactory> AcFact = rcp( new RAPFactory() ); for (size_t i = 0; i<TransferFacts_.size(); i++) { AcFact->AddTransferFactory(TransferFacts_[i]); // THIS WILL BE REPLACED with a call to the MLParamterListInterpreter } // // Nullspace factory // // Set fine level nullspace // extract pre-computed nullspace from ML parameter list // store it in nullspace_ and nullspaceDim_ if (nullspaceType != "default vectors") { TEUCHOS_TEST_FOR_EXCEPTION(nullspaceType != "pre-computed", Exceptions::RuntimeError, "MueLu::MLParameterListInterpreter: no valid nullspace (no pre-computed null space). error."); TEUCHOS_TEST_FOR_EXCEPTION(nullspaceDim == -1, Exceptions::RuntimeError, "MueLu::MLParameterListInterpreter: no valid nullspace (nullspace dim == -1). error."); 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\'"); nullspaceDim_ = nullspaceDim; nullspace_ = nullspaceVec; } Teuchos::RCP<NullspaceFactory> nspFact = Teuchos::rcp(new NullspaceFactory()); nspFact->SetFactory("Nullspace", PtentFact); // // Hierarchy + FactoryManager // // Hierarchy options this->SetVerbLevel(toMueLuVerbLevel(eVerbLevel)); this->numDesiredLevel_ = maxLevels; this->maxCoarseSize_ = maxCoarseSize; // init smoother RCP<SmootherFactory> initSmootherFact = Teuchos::null; if(paramList.isSublist("init smoother")) { ParameterList& initList = paramList.sublist("init smoother"); // TODO move this before for loop initSmootherFact = MLParameterListInterpreter::GetSmootherFactory(initList); // TODO: missing AFact input arg. } else { std::string ifpackType = "RELAXATION"; Teuchos::ParameterList smootherParamList; smootherParamList.set("relaxation: type", "symmetric Gauss-Seidel"); smootherParamList.set("smoother: sweeps", 1); smootherParamList.set("smoother: damping factor", 1.0); RCP<SmootherPrototype> smooProto = rcp( new TrilinosSmoother(ifpackType, smootherParamList, 0) ); initSmootherFact = rcp( new SmootherFactory() ); initSmootherFact->SetSmootherPrototypes(smooProto, smooProto); } // // Coarse Smoother // ParameterList& coarseList = paramList.sublist("coarse: list"); // coarseList.get("smoother: type", "Amesos-KLU"); // set default //RCP<SmootherFactory> coarseFact = this->GetSmootherFactory(coarseList); RCP<SmootherFactory> coarseFact = MLParameterListInterpreter::GetSmootherFactory(coarseList); // Smoothers Top Level Parameters RCP<ParameterList> topLevelSmootherParam = ExtractSetOfParameters(paramList, "smoother"); // std::cout << std::endl << "Top level smoother parameters:" << std::endl; // std::cout << *topLevelSmootherParam << std::endl; // // Prepare factory managers // TODO: smootherFact can be reuse accross level if same parameters/no specific parameterList for (int levelID=0; levelID < maxLevels; levelID++) { // // Level FactoryManager // RCP<FactoryManager> manager = rcp(new FactoryManager()); RCP<FactoryManager> initmanager = rcp(new FactoryManager()); // // Smoothers // { // Merge level-specific parameters with global parameters. level-specific parameters takes precedence. // TODO: unit-test this part alone ParameterList levelSmootherParam = GetMLSubList(paramList, "smoother", levelID); // copy MergeParameterList(*topLevelSmootherParam, levelSmootherParam, false); /* false = do no overwrite levelSmootherParam parameters by topLevelSmootherParam parameters */ // std::cout << std::endl << "Merged List for level " << levelID << std::endl; // std::cout << levelSmootherParam << std::endl; //RCP<SmootherFactory> smootherFact = this->GetSmootherFactory(levelSmootherParam); // TODO: missing AFact input arg. RCP<SmootherFactory> smootherFact = MLParameterListInterpreter::GetSmootherFactory(levelSmootherParam); // TODO: missing AFact input arg. manager->SetFactory("Smoother", smootherFact); smootherFact->DisableMultipleCallCheck(); initmanager->SetFactory("Smoother", initSmootherFact); initmanager->SetFactory("CoarseSolver", initSmootherFact); initSmootherFact->DisableMultipleCallCheck(); } // // Misc // Teuchos::rcp_dynamic_cast<PFactory>(PFact)->DisableMultipleCallCheck(); Teuchos::rcp_dynamic_cast<PFactory>(PtentFact)->DisableMultipleCallCheck(); Teuchos::rcp_dynamic_cast<TwoLevelFactoryBase>(RFact)->DisableMultipleCallCheck(); Teuchos::rcp_dynamic_cast<SingleLevelFactoryBase>(coarseFact)->DisableMultipleCallCheck(); Teuchos::rcp_dynamic_cast<SingleLevelFactoryBase>(dropFact)->DisableMultipleCallCheck(); Teuchos::rcp_dynamic_cast<SingleLevelFactoryBase>(CoupledAggFact)->DisableMultipleCallCheck(); Teuchos::rcp_dynamic_cast<TwoLevelFactoryBase>(AcFact)->DisableMultipleCallCheck(); Teuchos::rcp_dynamic_cast<SingleLevelFactoryBase>(nspFact)->DisableMultipleCallCheck(); manager->SetFactory("CoarseSolver", coarseFact); // TODO: should not be done in the loop manager->SetFactory("Graph", dropFact); manager->SetFactory("Aggregates", CoupledAggFact); manager->SetFactory("DofsPerNode", dropFact); manager->SetFactory("A", AcFact); manager->SetFactory("P", PFact); manager->SetFactory("Ptent", PtentFact); manager->SetFactory("R", RFact); manager->SetFactory("Nullspace", nspFact); //initmanager->SetFactory("CoarseSolver", coarseFact); initmanager->SetFactory("Graph", dropFact); initmanager->SetFactory("Aggregates", CoupledAggFact); initmanager->SetFactory("DofsPerNode", dropFact); initmanager->SetFactory("A", AcFact); initmanager->SetFactory("P", PtentFact); // use nonsmoothed transfers initmanager->SetFactory("Ptent", PtentFact); initmanager->SetFactory("R", RFact); initmanager->SetFactory("Nullspace", nspFact); this->AddFactoryManager(levelID, 1, manager); this->AddInitFactoryManager(levelID, 1, initmanager); } // for (level loop) }
void MLParameterListInterpreter<Scalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps>::SetParameterList(const Teuchos::ParameterList & paramList_in) { Teuchos::ParameterList paramList = paramList_in; RCP<Teuchos::FancyOStream> out = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout)); // TODO: use internal out (GetOStream()) // // Read top-level of the parameter list // // hard-coded default values == ML defaults according to the manual MUELU_READ_PARAM(paramList, "ML output", int, 0, verbosityLevel); MUELU_READ_PARAM(paramList, "max levels", int, 10, maxLevels); MUELU_READ_PARAM(paramList, "PDE equations", int, 1, nDofsPerNode); MUELU_READ_PARAM(paramList, "coarse: max size", int, 128, maxCoarseSize); MUELU_READ_PARAM(paramList, "aggregation: type", std::string, "Uncoupled", agg_type); //MUELU_READ_PARAM(paramList, "aggregation: threshold", double, 0.0, agg_threshold); MUELU_READ_PARAM(paramList, "aggregation: damping factor", double, (double)4/(double)3, agg_damping); //MUELU_READ_PARAM(paramList, "aggregation: smoothing sweeps", int, 1, agg_smoothingsweeps); MUELU_READ_PARAM(paramList, "aggregation: nodes per aggregate", int, 1, minPerAgg); MUELU_READ_PARAM(paramList, "aggregation: keep Dirichlet bcs", bool, false, bKeepDirichletBcs); // This is a MueLu specific extension that does not exist in ML MUELU_READ_PARAM(paramList, "aggregation: max neighbours already aggregated", int, 0, maxNbrAlreadySelected); // This is a MueLu specific extension that does not exist in ML MUELU_READ_PARAM(paramList, "null space: type", std::string, "default vectors", nullspaceType); MUELU_READ_PARAM(paramList, "null space: dimension", int, -1, nullspaceDim); // TODO: ML default not in documentation MUELU_READ_PARAM(paramList, "null space: vectors", double*, NULL, nullspaceVec); // TODO: ML default not in documentation MUELU_READ_PARAM(paramList, "energy minimization: enable", bool, false, bEnergyMinimization); MUELU_READ_PARAM(paramList, "RAP: fix diagonal", bool, false, bFixDiagonal); // This is a MueLu specific extension that does not exist in ML // // Move smoothers/aggregation/coarse parameters to sublists // // ML allows to have level-specific smoothers/aggregation/coarse parameters at the top level of the list or/and defined in sublists: // See also: ML Guide section 6.4.1, MueLu::CreateSublists, ML_CreateSublists ParameterList paramListWithSubList; MueLu::CreateSublists(paramList, paramListWithSubList); paramList = paramListWithSubList; // swap // std::cout << std::endl << "Parameter list after CreateSublists" << std::endl; // std::cout << paramListWithSubList << std::endl; // // Validate parameter list // { bool validate = paramList.get("ML validate parameter list", true); /* true = default in ML */ if (validate) { #if defined(HAVE_MUELU_ML) && defined(HAVE_MUELU_EPETRA) // Validate parameter list using ML validator int depth = paramList.get("ML validate depth", 5); /* 5 = default in ML */ TEUCHOS_TEST_FOR_EXCEPTION(! ML_Epetra::ValidateMLPParameters(paramList, depth), Exceptions::RuntimeError, "ERROR: ML's Teuchos::ParameterList contains incorrect parameter!"); #else // If no validator available: issue a warning and set parameter value to false in the output list *out << "Warning: MueLu_ENABLE_ML=OFF. The parameter list cannot be validated." << std::endl; paramList.set("ML validate parameter list", false); #endif // HAVE_MUELU_ML } // if(validate) } // scope // // // // Matrix option blksize_ = nDofsPerNode; // Translate verbosity parameter // Translate verbosity parameter MsgType eVerbLevel = None; if (verbosityLevel == 0) eVerbLevel = None; if (verbosityLevel > 0) eVerbLevel = Low; if (verbosityLevel > 4) eVerbLevel = Medium; if (verbosityLevel > 7) eVerbLevel = High; if (verbosityLevel > 9) eVerbLevel = Extreme; if (verbosityLevel > 9) eVerbLevel = Test; this->verbosity_ = eVerbLevel; TEUCHOS_TEST_FOR_EXCEPTION(agg_type != "Uncoupled" && agg_type != "Coupled", Exceptions::RuntimeError, "MueLu::MLParameterListInterpreter::Setup(): parameter \"aggregation: type\": only 'Uncoupled' or 'Coupled' aggregation is supported."); // Create MueLu factories RCP<CoalesceDropFactory> dropFact = rcp(new CoalesceDropFactory()); RCP<FactoryBase> CoupledAggFact = Teuchos::null; if(agg_type == "Uncoupled") { // Uncoupled aggregation RCP<UncoupledAggregationFactory> CoupledAggFact2 = rcp(new UncoupledAggregationFactory()); /*CoupledAggFact2->SetMinNodesPerAggregate(minPerAgg); //TODO should increase if run anything other than 1D CoupledAggFact2->SetMaxNeighAlreadySelected(maxNbrAlreadySelected); CoupledAggFact2->SetOrdering("natural");*/ CoupledAggFact2->SetFactory("Graph", dropFact); CoupledAggFact2->SetFactory("DofsPerNode", dropFact); CoupledAggFact2->SetParameter("UsePreserveDirichletAggregationAlgorithm", Teuchos::ParameterEntry(bKeepDirichletBcs)); CoupledAggFact2->SetParameter("aggregation: ordering", Teuchos::ParameterEntry(std::string("natural"))); CoupledAggFact2->SetParameter("aggregation: max selected neighbors", Teuchos::ParameterEntry(maxNbrAlreadySelected)); CoupledAggFact2->SetParameter("aggregation: min agg size", Teuchos::ParameterEntry(minPerAgg)); CoupledAggFact = CoupledAggFact2; } else { // Coupled Aggregation (default) RCP<CoupledAggregationFactory> CoupledAggFact2 = rcp(new CoupledAggregationFactory()); CoupledAggFact2->SetMinNodesPerAggregate(minPerAgg); //TODO should increase if run anything other than 1D CoupledAggFact2->SetMaxNeighAlreadySelected(maxNbrAlreadySelected); CoupledAggFact2->SetOrdering("natural"); CoupledAggFact2->SetPhase3AggCreation(0.5); CoupledAggFact2->SetFactory("Graph", dropFact); CoupledAggFact2->SetFactory("DofsPerNode", dropFact); CoupledAggFact = CoupledAggFact2; } if (verbosityLevel > 3) { // TODO fix me: Setup is a static function: we cannot use GetOStream without an object... *out << "========================= Aggregate option summary =========================" << std::endl; *out << "min Nodes per aggregate : " << minPerAgg << std::endl; *out << "min # of root nbrs already aggregated : " << maxNbrAlreadySelected << std::endl; *out << "aggregate ordering : natural" << std::endl; *out << "=============================================================================" << std::endl; } RCP<Factory> PFact; RCP<Factory> RFact; RCP<Factory> PtentFact = rcp( new TentativePFactory() ); if (agg_damping == 0.0 && bEnergyMinimization == false) { // tentative prolongation operator (PA-AMG) PFact = PtentFact; RFact = rcp( new TransPFactory() ); } else if (agg_damping != 0.0 && bEnergyMinimization == false) { // smoothed aggregation (SA-AMG) RCP<SaPFactory> SaPFact = rcp( new SaPFactory() ); SaPFact->SetDampingFactor(agg_damping); PFact = SaPFact; RFact = rcp( new TransPFactory() ); } else if (bEnergyMinimization == true) { // Petrov Galerkin PG-AMG smoothed aggregation (energy minimization in ML) PFact = rcp( new PgPFactory() ); RFact = rcp( new GenericRFactory() ); } RCP<RAPFactory> AcFact = rcp( new RAPFactory() ); AcFact->SetParameter("RepairMainDiagonal", Teuchos::ParameterEntry(bFixDiagonal)); for (size_t i = 0; i<TransferFacts_.size(); i++) { AcFact->AddTransferFactory(TransferFacts_[i]); } // // introduce rebalancing // #if defined(HAVE_MUELU_ISORROPIA) && defined(HAVE_MPI) Teuchos::RCP<Factory> RebalancedPFact = Teuchos::null; Teuchos::RCP<Factory> RebalancedRFact = Teuchos::null; Teuchos::RCP<Factory> RepartitionFact = Teuchos::null; Teuchos::RCP<RebalanceAcFactory> RebalancedAFact = Teuchos::null; MUELU_READ_PARAM(paramList, "repartition: enable", int, 0, bDoRepartition); if (bDoRepartition == 1) { // The Factory Manager will be configured to return the rebalanced versions of P, R, A by default. // Everytime we want to use the non-rebalanced versions, we need to explicitly define the generating factory. RFact->SetFactory("P", PFact); // AcFact->SetFactory("P", PFact); AcFact->SetFactory("R", RFact); MUELU_READ_PARAM(paramList, "repartition: max min ratio", double, 1.3, maxminratio); MUELU_READ_PARAM(paramList, "repartition: min per proc", int, 512, minperproc); // create "Partition" Teuchos::RCP<MueLu::IsorropiaInterface<LO, GO, NO, LMO> > isoInterface = Teuchos::rcp(new MueLu::IsorropiaInterface<LO, GO, NO, LMO>()); isoInterface->SetFactory("A", AcFact); // Repartitioning (creates "Importer" from "Partition") RepartitionFact = Teuchos::rcp(new RepartitionFactory()); { Teuchos::ParameterList paramListRepFact; paramListRepFact.set("repartition: min rows per proc", minperproc); paramListRepFact.set("repartition: max imbalance", maxminratio); RepartitionFact->SetParameterList(paramListRepFact); } RepartitionFact->SetFactory("A", AcFact); RepartitionFact->SetFactory("Partition", isoInterface); // Reordering of the transfer operators RebalancedPFact = Teuchos::rcp(new RebalanceTransferFactory()); RebalancedPFact->SetParameter("type", Teuchos::ParameterEntry(std::string("Interpolation"))); RebalancedPFact->SetFactory("P", PFact); RebalancedRFact = Teuchos::rcp(new RebalanceTransferFactory()); RebalancedRFact->SetParameter("type", Teuchos::ParameterEntry(std::string("Restriction"))); RebalancedRFact->SetFactory("R", RFact); RebalancedRFact->SetFactory("Nullspace", PtentFact); // Compute Ac from rebalanced P and R RebalancedAFact = Teuchos::rcp(new RebalanceAcFactory()); RebalancedAFact->SetFactory("A", AcFact); }