void AdaptiveSaMLParameterListInterpreter<Scalar, LocalOrdinal, GlobalOrdinal, Node>::SetupInitHierarchy(Hierarchy & H) const { TEUCHOS_TEST_FOR_EXCEPTION(!H.GetLevel(0)->IsAvailable("A"), Exceptions::RuntimeError, "No fine level operator"); RCP<Level> l = H.GetLevel(0); RCP<Operator> Op = l->Get<RCP<Operator> >("A"); SetupOperator(*Op); // use overloaded SetupMatrix routine this->SetupExtra(H); // Setup Hierarchy H.SetMaxCoarseSize(this->maxCoarseSize_); // TODO int levelID = 0; int lastLevelID = this->numDesiredLevel_ - 1; bool isLastLevel = false; while(!isLastLevel) { bool r = H.Setup(levelID, InitLvlMngr(levelID-1, lastLevelID), InitLvlMngr(levelID, lastLevelID), InitLvlMngr(levelID+1, lastLevelID)); isLastLevel = r || (levelID == lastLevelID); levelID++; } }
//! Setup Hierarchy object virtual void SetupHierarchy(Hierarchy& H) const { TEUCHOS_TEST_FOR_EXCEPTION(!H.GetLevel(0)->IsAvailable("A"), Exceptions::RuntimeError, "No fine level operator"); // Setup Matrix // TODO: I should certainly undo this somewhere... RCP<Level> l = H.GetLevel(0); RCP<Matrix> Op = l->Get<RCP<Matrix> >("A"); Xpetra::UnderlyingLib lib = Op->getRowMap()->lib(); H.setlib(lib); SetupMatrix(*Op); SetupExtra(H); // Setup Hierarchy H.SetMaxCoarseSize(maxCoarseSize_); H.SetDefaultVerbLevel(verbosity_); if (graphOutputLevel_ >= 0) H.EnableGraphDumping("dep_graph.dot", graphOutputLevel_); // TODO: coarsestLevelManager H.Clear(); int levelID = 0; int lastLevelID = numDesiredLevel_ - 1; bool isLastLevel = false; while (!isLastLevel) { bool r = H.Setup(levelID, LvlMngr(levelID-1, lastLevelID), LvlMngr(levelID, lastLevelID), LvlMngr(levelID+1, lastLevelID)); isLastLevel = r || (levelID == lastLevelID); levelID++; } RCP<Teuchos::FancyOStream> fos = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout)); fos->setOutputToRootOnly(0); H.print(*fos,verbosity_); // When we reuse hierarchy, it is necessary that we don't // change the number of levels. We also cannot make requests // for coarser levels, because we don't construct all the // data on previous levels. For instance, let's say our first // run constructed three levels. If we try to do requests during // next setup for the fourth level, it would need Aggregates // which we didn't construct for level 3 because we reused P. // To fix this situation, we change the number of desired levels // here. numDesiredLevel_ = levelID; WriteData<Matrix>(H, matricesToPrint_, "A"); WriteData<Matrix>(H, prolongatorsToPrint_, "P"); WriteData<Matrix>(H, restrictorsToPrint_, "R"); } //SetupHierarchy
void WriteData(Hierarchy & H, Teuchos::Array<int> const &data, std::string const &name) const { for (int i=0; i<data.size(); ++i) { std::ostringstream buf; buf << data[i]; std::string fileName = name + "_" + buf.str() + ".m"; if (data[i] < H.GetNumLevels()) { RCP<Level> L = H.GetLevel(data[i]); if (L->IsAvailable(name)) { RCP<T> M = L-> template Get< RCP<T> >(name); if ( !( M.is_null() ) ) Utils::Write(fileName,*M); } } } } //WriteData
//! Setup Hierarchy object virtual void SetupHierarchy(Hierarchy & H) const { TEUCHOS_TEST_FOR_EXCEPTION(!H.GetLevel(0)->IsAvailable("A"), Exceptions::RuntimeError, "No fine level operator"); // Setup Matrix // TODO: I should certainly undo this somewhere... RCP<Level> l = H.GetLevel(0); RCP<Matrix> Op = l->Get<RCP<Matrix> >("A"); SetupMatrix(*Op); SetupExtra(H); // Setup Hierarchy H.SetMaxCoarseSize(maxCoarseSize_); H.SetDefaultVerbLevel(verbosity_); if (graphOutputLevel_ >= 0) H.EnableGraphDumping("dep_graph.dot", graphOutputLevel_); // TODO: coarsestLevelManager int levelID = 0; int lastLevelID = numDesiredLevel_ - 1; bool isLastLevel = false; while (!isLastLevel) { bool r = H.Setup(levelID, LvlMngr(levelID-1, lastLevelID), LvlMngr(levelID, lastLevelID), LvlMngr(levelID+1, lastLevelID)); isLastLevel = r || (levelID == lastLevelID); levelID++; } WriteData<Matrix>(H, matricesToPrint_, "A"); WriteData<Matrix>(H, prolongatorsToPrint_, "P"); WriteData<Matrix>(H, restrictorsToPrint_, "R"); } //SetupHierarchy
void WriteData(Hierarchy& H, const Teuchos::Array<int>& data, const std::string& name) const { for (int i = 0; i < data.size(); ++i) { std::string fileName = name + "_" + toString(data[i]) + ".m"; if (data[i] < H.GetNumLevels()) { RCP<Level> L = H.GetLevel(data[i]); if (L->IsAvailable(name)) { RCP<T> M = L->template Get< RCP<T> >(name); if (!M.is_null()) Utils::Write(fileName,* M); } } } }
void HierarchyUtils<Scalar, LocalOrdinal, GlobalOrdinal, Node>::AddNonSerializableDataToHierarchy(HierarchyManager& HM, Hierarchy& H, const ParameterList& paramList) { for (ParameterList::ConstIterator it = paramList.begin(); it != paramList.end(); it++) { const std::string& levelName = it->first; // Check for mach of the form "level X" where X is a positive integer if (paramList.isSublist(levelName) && levelName.find("level ") == 0 && levelName.size() > 6) { int levelID = strtol(levelName.substr(6).c_str(), 0, 0); if (levelID > 0) { // Do enough level adding so we can be sure to add the data to the right place for (int i = H.GetNumLevels(); i <= levelID; i++) H.AddNewLevel(); } RCP<Level> level = H.GetLevel(levelID); RCP<FactoryManager> M = Teuchos::rcp_dynamic_cast<FactoryManager>(HM.GetFactoryManager(levelID)); TEUCHOS_TEST_FOR_EXCEPTION(M.is_null(), Exceptions::InvalidArgument, "MueLu::Utils::AddNonSerializableDataToHierarchy: cannot get FactoryManager"); // Grab the level sublist & loop over parameters const ParameterList& levelList = paramList.sublist(levelName); for (ParameterList::ConstIterator it2 = levelList.begin(); it2 != levelList.end(); it2++) { const std::string& name = it2->first; TEUCHOS_TEST_FOR_EXCEPTION(name != "A" && name != "P" && name != "R" && name != "Nullspace" && name != "Coordinates" && !IsParamMuemexVariable(name), Exceptions::InvalidArgument, "MueLu::Utils::AddNonSerializableDataToHierarchy: parameter list contains unknown data type"); if (name == "A") { level->Set(name, Teuchos::getValue<RCP<Matrix > > (it2->second),NoFactory::get()); M->SetFactory(name, NoFactory::getRCP()); // TAW: not sure about this: be aware that this affects all levels // However, A is accessible through NoFactory anyway, so it should // be fine here. } else if( name == "P" || name == "R") { level->AddKeepFlag(name,NoFactory::get(),MueLu::UserData); level->Set(name, Teuchos::getValue<RCP<Matrix > > (it2->second), M->GetFactory(name).get()); } else if (name == "Nullspace") { level->AddKeepFlag(name,NoFactory::get(),MueLu::UserData); level->Set(name, Teuchos::getValue<RCP<MultiVector > >(it2->second), NoFactory::get()); //M->SetFactory(name, NoFactory::getRCP()); // TAW: generally it is a bad idea to overwrite the factory manager data here // One should do this only in very special cases } else if(name == "Coordinates") //Scalar of Coordinates MV is always double { level->AddKeepFlag(name,NoFactory::get(),MueLu::UserData); level->Set(name, Teuchos::getValue<RCP<Xpetra::MultiVector<double, LocalOrdinal, GlobalOrdinal, Node> > >(it2->second), NoFactory::get()); //M->SetFactory(name, NoFactory::getRCP()); // TAW: generally it is a bad idea to overwrite the factory manager data here } #ifdef HAVE_MUELU_MATLAB else { //Custom variable for Muemex size_t typeNameStart = name.find_first_not_of(' '); size_t typeNameEnd = name.find(' ', typeNameStart); std::string typeName = name.substr(typeNameStart, typeNameEnd - typeNameStart); std::transform(typeName.begin(), typeName.end(), typeName.begin(), ::tolower); level->AddKeepFlag(name, NoFactory::get(), MueLu::UserData); if(typeName == "matrix") level->Set(name, Teuchos::getValue<RCP<Matrix> >(it2->second), NoFactory::get()); else if(typeName == "multivector") level->Set(name, Teuchos::getValue<RCP<MultiVector> >(it2->second), NoFactory::get()); else if(typeName == "map") level->Set(name, Teuchos::getValue<RCP<Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node> > >(it2->second), NoFactory::get()); else if(typeName == "ordinalvector") level->Set(name, Teuchos::getValue<RCP<Xpetra::Vector<LocalOrdinal, LocalOrdinal, GlobalOrdinal, Node> > >(it2->second), NoFactory::get()); else if(typeName == "scalar") level->Set(name, Teuchos::getValue<Scalar>(it2->second), NoFactory::get()); else if(typeName == "double") level->Set(name, Teuchos::getValue<double>(it2->second), NoFactory::get()); else if(typeName == "complex") level->Set(name, Teuchos::getValue<std::complex<double> >(it2->second), NoFactory::get()); else if(typeName == "int") level->Set(name, Teuchos::getValue<int>(it2->second), NoFactory::get()); else if(typeName == "string") level->Set(name, Teuchos::getValue<std::string>(it2->second), NoFactory::get()); } #endif } } } }
int main_(Teuchos::CommandLineProcessor &clp, Xpetra::UnderlyingLib lib, int argc, char *argv[]) { #include <MueLu_UseShortNames.hpp> using Teuchos::RCP; using Teuchos::rcp; // // MPI initialization // Teuchos::oblackholestream blackhole; bool success = false; bool verbose = true; try { RCP< const Teuchos::Comm<int> > comm = Teuchos::DefaultComm<int>::getComm(); // // Process command line arguments // Galeri::Xpetra::Parameters<GO> matrixParameters(clp, 81); // manage parameters of the test case Xpetra::Parameters xpetraParameters(clp); // manage parameters of xpetra switch (clp.parse(argc,argv)) { case Teuchos::CommandLineProcessor::PARSE_HELP_PRINTED: return EXIT_SUCCESS; case Teuchos::CommandLineProcessor::PARSE_ERROR: case Teuchos::CommandLineProcessor::PARSE_UNRECOGNIZED_OPTION: return EXIT_FAILURE; case Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL: break; default:; } if (comm->getRank() == 0) std::cout << xpetraParameters << matrixParameters; // // Setup test case (Ax = b) // // Distribution RCP<const Map> map = MapFactory::Build(lib, matrixParameters.GetNumGlobalElements(), 0, comm); // Matrix RCP<Galeri::Xpetra::Problem<Map,CrsMatrixWrap,MultiVector> > Pr = Galeri::Xpetra::BuildProblem<SC, LO, GO, Map, CrsMatrixWrap, MultiVector>(matrixParameters.GetMatrixType(), map, matrixParameters.GetParameterList()); RCP<Matrix> A = Pr->BuildMatrix(); // User defined nullspace RCP<MultiVector> nullSpace = VectorFactory::Build(map,1); nullSpace->putScalar((SC) 1.0); // Define B RCP<Vector> X = VectorFactory::Build(map,1); RCP<Vector> B = VectorFactory::Build(map,1); X->setSeed(846930886); X->randomize(); A->apply(*X, *B, Teuchos::NO_TRANS, (SC)1.0, (SC)0.0); // X = 0 X->putScalar((SC) 0.0); // // Create a multigrid configuration // // Transfer operators RCP<TentativePFactory> TentativePFact = rcp( new TentativePFactory() ); RCP<SaPFactory> SaPFact = rcp( new SaPFactory() ); RCP<TransPFactory> RFact = rcp( new TransPFactory()); FactoryManager M; M.SetFactory("Ptent", TentativePFact); M.SetFactory("P", SaPFact); M.SetFactory("R", RFact); M.SetFactory("Smoother", Teuchos::null); //skips smoother setup M.SetFactory("CoarseSolver", Teuchos::null); //skips coarsest solve setup // // Multigrid setup phase // int startLevel = 0; int maxLevels = 10; std::cout << "=============== Setup transfers only ====================" << std::endl; Hierarchy H; H.SetDefaultVerbLevel(MueLu::Medium); RCP<Level> finestLevel = H.GetLevel(); finestLevel->Set("A", A); finestLevel->Set("Nullspace", nullSpace); // Indicate which Hierarchy operators we want to keep H.Keep("P", SaPFact.get()); //SaPFact is the generating factory for P. H.Keep("R", RFact.get()); //RFact is the generating factory for R. H.Keep("Ptent", TentativePFact.get()); //SaPFact is the generating factory for P. H.Setup(M,startLevel,maxLevels); std::cout << "=============== Setup smoothers only ====================" << std::endl; // Create a new A. RCP<Matrix> newA = Pr->BuildMatrix(); finestLevel->Set("A", newA); // Create Gauss-Seidel smoother. std::string ifpackType = "RELAXATION"; Teuchos::ParameterList ifpackList; ifpackList.set("relaxation: sweeps", (LO) 3); ifpackList.set("relaxation: damping factor", (SC) 1.0); RCP<SmootherPrototype> smootherPrototype = rcp(new TrilinosSmoother(ifpackType, ifpackList)); M.SetFactory("Smoother", rcp(new SmootherFactory(smootherPrototype))); // Create coarsest solver. RCP<SmootherPrototype> coarseSolverPrototype = rcp( new DirectSolver() ); RCP<SmootherFactory> coarseSolverFact = rcp( new SmootherFactory(coarseSolverPrototype, Teuchos::null) ); M.SetFactory("CoarseSolver", coarseSolverFact); // Note that we pass the number of levels back in. H.Setup(M,startLevel, H.GetNumLevels()); std::cout << "=============== Solve ====================" << std::endl; // // Solve Ax = B // LO nIts = 9; H.Iterate(*B, *X, nIts); // // Print relative residual norm // typename Teuchos::ScalarTraits<SC>::magnitudeType residualNorms = Utilities::ResidualNorm(*A, *X, *B)[0]; if (comm->getRank() == 0) { std::ios::fmtflags f(std::cout.flags()); std::cout << "||Residual|| = " << std::setiosflags(std::ios::fixed) << std::setprecision(20) << residualNorms << std::endl; std::cout.flags(f); } success = true; } TEUCHOS_STANDARD_CATCH_STATEMENTS(verbose, std::cerr, success); return ( success ? EXIT_SUCCESS : EXIT_FAILURE ); }
void AdaptiveSaMLParameterListInterpreter<Scalar, LocalOrdinal, GlobalOrdinal, Node>::SetupHierarchy(Hierarchy & H) const { // set fine level null space // usually this null space is provided from outside (by the user) using // the ML parameter lists. if (this->nullspace_ != NULL) { RCP<Level> fineLevel = H.GetLevel(0); const RCP<const Map> rowMap = fineLevel->Get< RCP<Matrix> >("A")->getRowMap(); RCP<MultiVector> nullspace = MultiVectorFactory::Build(rowMap, nullspaceDim_, true); for ( size_t i=0; i < Teuchos::as<size_t>(nullspaceDim_); i++) { Teuchos::ArrayRCP<Scalar> nullspacei = nullspace->getDataNonConst(i); const size_t myLength = nullspace->getLocalLength(); for (size_t j = 0; j < myLength; j++) { nullspacei[j] = nullspace_[i*myLength + j]; } } fineLevel->Set("Nullspace", nullspace); } // keep aggregates H.Keep("Aggregates", HierarchyManager::GetFactoryManager(0)->GetFactory("Aggregates").get()); /////////////////////////////// // build hierarchy for initialization SetupInitHierarchy(H); { // do some iterations with the built hierarchy to improve the null space Teuchos::RCP<MueLu::Level> Finest = H.GetLevel(0); // get finest level,MueLu::NoFactory::get() Teuchos::RCP<MultiVector> nspVector2 = Finest->Get<Teuchos::RCP<MultiVector> >("Nullspace"); Xpetra::IO<Scalar,LocalOrdinal,GlobalOrdinal,Node>::Write("orig_nsp.vec", *nspVector2); RCP<Matrix> Op = Finest->Get<RCP<Matrix> >("A"); Xpetra::IO<Scalar,LocalOrdinal,GlobalOrdinal,Node>::Write("A.mat", *Op); Teuchos::RCP<MultiVector> homogRhsVec = MultiVectorFactory::Build(nspVector2->getMap(),nspVector2->getNumVectors(),true); homogRhsVec->putScalar(0.0); // do 1 multigrid cycle for improving the null space by "solving" // A B_f = 0 // where A is the system matrix and B_f the fine level null space vectors H.Iterate(*homogRhsVec, *nspVector2, 1, false); // store improved fine level null space Finest->Set("Nullspace",nspVector2); Xpetra::IO<Scalar,LocalOrdinal,GlobalOrdinal,Node>::Write("new_nsp.vec", *nspVector2); //H.Delete("CoarseSolver", init_levelManagers_[0]->GetFactory("CoarseSolver").get()); } { // do some clean up. // remove all old default factories. Build new ones for the second build. // this is a little bit tricky to understand for(size_t k=0; k < HierarchyManager::getNumFactoryManagers(); k++) { HierarchyManager::GetFactoryManager(k)->Clean(); //Teuchos::rcp_dynamic_cast<const SingleLevelFactoryBase>(HierarchyManager::GetFactoryManager(k)->GetFactory("Smoother"))->DisableMultipleCallCheck(); // after changing to MLParamterListInterpreter functions } // not sure about this. i only need it if Smoother is defined explicitely (not using default smoother) // need this: otherwise RAPFactory::Build is complaining on level 0 // and TentativePFactory::Build is complaining on level 1 Teuchos::rcp_dynamic_cast<const TwoLevelFactoryBase>(HierarchyManager::GetFactoryManager(0)->GetFactory("A"))->DisableMultipleCallCheck(); Teuchos::rcp_dynamic_cast<const TwoLevelFactoryBase>(HierarchyManager::GetFactoryManager(1)->GetFactory("P"))->DisableMultipleCallCheck(); Teuchos::rcp_dynamic_cast<const TwoLevelFactoryBase>(HierarchyManager::GetFactoryManager(1)->GetFactory("Ptent"))->DisableMultipleCallCheck(); HierarchyManager::SetupHierarchy(H); } }
int main(int argc, char *argv[]) { #include "MueLu_UseShortNames.hpp" using Teuchos::RCP; using Teuchos::rcp; using Teuchos::TimeMonitor; Teuchos::oblackholestream blackhole; Teuchos::GlobalMPISession mpiSession(&argc,&argv,&blackhole); bool success = false; bool verbose = true; try { RCP<const Teuchos::Comm<int> > comm = Teuchos::DefaultComm<int>::getComm(); RCP<Teuchos::FancyOStream> out = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout)); out->setOutputToRootOnly(0); *out << MueLu::MemUtils::PrintMemoryUsage() << std::endl; //#ifndef HAVE_XPETRA_INT_LONG_LONG *out << "Warning: scaling test was not compiled with long long int support" << std::endl; //#endif /**********************************************************************************/ /* SET TEST PARAMETERS */ /**********************************************************************************/ // Note: use --help to list available options. Teuchos::CommandLineProcessor clp(false); Xpetra::Parameters xpetraParameters(clp); // manage parameters of xpetra switch (clp.parse(argc,argv)) { case Teuchos::CommandLineProcessor::PARSE_HELP_PRINTED: return EXIT_SUCCESS; break; case Teuchos::CommandLineProcessor::PARSE_ERROR: case Teuchos::CommandLineProcessor::PARSE_UNRECOGNIZED_OPTION: return EXIT_FAILURE; break; case Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL: break; } //RCP<TimeMonitor> globalTimeMonitor = rcp (new TimeMonitor(*TimeMonitor::getNewTimer("ScalingTest: S - Global Time"))); xpetraParameters.check(); Xpetra::UnderlyingLib lib = xpetraParameters.GetLib(); if (comm->getRank() == 0) { std::cout << xpetraParameters; // TODO: print custom parameters // Or use paramList::print()! } /**********************************************************************************/ /* CREATE INITIAL MATRIX */ /**********************************************************************************/ RCP<const Map> bigMap; RCP<const Map> map1; RCP<const Map> map2; GO numElements = 500; GO numElements1 = 400; GO numElements2 = 100; //bigMap = MapFactory::Build(Xpetra::UseEpetra, numElements, 0, comm); // ok this is the problem :-) std::vector<size_t> stridingInfo; stridingInfo.push_back(1); map1 = StridedMapFactory::Build(lib, numElements1, 0, stridingInfo, comm, -1); map2 = StridedMapFactory::Build(lib, numElements2, numElements1, stridingInfo, comm, -1); std::vector<GlobalOrdinal> localGids; // vector with all local GIDs on cur proc Teuchos::ArrayView< const GlobalOrdinal > map1eleList = map1->getNodeElementList(); // append all local gids from map1 and map2 localGids.insert(localGids.end(), map1eleList.begin(), map1eleList.end()); Teuchos::ArrayView< const GlobalOrdinal > map2eleList = map2->getNodeElementList(); localGids.insert(localGids.end(), map2eleList.begin(), map2eleList.end()); Teuchos::ArrayView<GlobalOrdinal> eleList(&localGids[0],localGids.size()); bigMap = StridedMapFactory::Build(lib, numElements, eleList, 0, stridingInfo, comm); // create full big map (concatenation of map1 and map2) std::vector<Teuchos::RCP<const Map> > maps; maps.push_back(map1); maps.push_back(map2); Teuchos::RCP<const Xpetra::MapExtractor<Scalar, LO, GO, Node> > mapExtractor = Xpetra::MapExtractorFactory<Scalar,LO,GO,Node>::Build(bigMap, maps); RCP<CrsMatrixWrap> Op11 = MueLuTests::GenerateProblemMatrix(map1,2,-1,-1); RCP<CrsMatrixWrap> Op22 = MueLuTests::GenerateProblemMatrix(map2,3,-2,-1); /*Op11->describe(*out,Teuchos::VERB_EXTREME); Op22->describe(*out,Teuchos::VERB_EXTREME);*/ // build blocked operator Teuchos::RCP<Xpetra::BlockedCrsMatrix<Scalar,LO,GO,Node> > bOp = Teuchos::rcp(new Xpetra::BlockedCrsMatrix<Scalar,LO,GO>(mapExtractor,mapExtractor,10)); Teuchos::RCP<Xpetra::CrsMatrix<Scalar,LO,GO,Node> > crsMat11 = Op11->getCrsMatrix(); Teuchos::RCP<Xpetra::CrsMatrix<Scalar,LO,GO,Node> > crsMat22 = Op22->getCrsMatrix(); bOp->setMatrix(0,0,crsMat11); bOp->setMatrix(1,1,crsMat22); bOp->fillComplete(); // build hierarchy Hierarchy H; H.SetMaxCoarseSize(50); RCP<Level> levelOne = H.GetLevel(); levelOne->Set("A", Teuchos::rcp_dynamic_cast<Matrix>(bOp)); // set blocked operator RCP<SubBlockAFactory> A11Fact = Teuchos::rcp(new SubBlockAFactory()); A11Fact->SetFactory("A",MueLu::NoFactory::getRCP()); A11Fact->SetParameter("block row",Teuchos::ParameterEntry(0)); A11Fact->SetParameter("block col",Teuchos::ParameterEntry(0)); RCP<SubBlockAFactory> A22Fact = Teuchos::rcp(new SubBlockAFactory()); A22Fact->SetFactory("A",MueLu::NoFactory::getRCP()); A22Fact->SetParameter("block row",Teuchos::ParameterEntry(1)); A22Fact->SetParameter("block col",Teuchos::ParameterEntry(1)); RCP<TentativePFactory> P11Fact = rcp(new TentativePFactory()); RCP<TransPFactory> R11Fact = rcp(new TransPFactory()); RCP<TentativePFactory> P22TentFact = rcp(new TentativePFactory()); RCP<PgPFactory> P22Fact = rcp(new PgPFactory()); RCP<GenericRFactory> R22Fact = rcp(new GenericRFactory()); std::string ifpackType; Teuchos::ParameterList ifpackList; ifpackList.set("relaxation: sweeps", (LO) 5); ifpackList.set("relaxation: damping factor", (SC) 1.0); ifpackType = "RELAXATION"; ifpackList.set("relaxation: type", "Symmetric Gauss-Seidel"); RCP<SmootherPrototype> smoProto11 = rcp( new TrilinosSmoother(ifpackType, ifpackList, 0) ); smoProto11->SetFactory("A", A11Fact); RCP<SmootherPrototype> smoProto22 = rcp( new TrilinosSmoother(ifpackType, ifpackList, 0) ); smoProto22->SetFactory("A", A22Fact); //RCP<SmootherPrototype> smoProto11 = rcp( new DirectSolver("", Teuchos::ParameterList(), A11Fact) ); //RCP<SmootherPrototype> smoProto22 = rcp( new DirectSolver("", Teuchos::ParameterList(), A22Fact) ); RCP<SmootherFactory> Smoo11Fact = rcp( new SmootherFactory(smoProto11) ); RCP<SmootherFactory> Smoo22Fact = rcp( new SmootherFactory(smoProto22) ); RCP<FactoryManager> M11 = rcp(new FactoryManager()); M11->SetFactory("A", A11Fact); M11->SetFactory("P", P11Fact); M11->SetFactory("Ptent", P11Fact); //for Nullspace M11->SetFactory("R", R11Fact); M11->SetFactory("Smoother", Smoo11Fact); M11->SetIgnoreUserData(true); RCP<FactoryManager> M22 = rcp(new FactoryManager()); M22->SetFactory("A", A22Fact); M22->SetFactory("P", P22Fact); M22->SetFactory("R", R22Fact); M22->SetFactory("Ptent", P22TentFact); //for both P22 and Nullspace M22->SetFactory("Smoother", Smoo22Fact); M22->SetIgnoreUserData(true); RCP<BlockedPFactory> PFact = rcp(new BlockedPFactory()); PFact->AddFactoryManager(M11); PFact->AddFactoryManager(M22); RCP<GenericRFactory> RFact = rcp(new GenericRFactory()); RCP<Factory> AcFact = rcp(new BlockedRAPFactory()); // Smoothers RCP<BlockedGaussSeidelSmoother> smootherPrototype = rcp( new BlockedGaussSeidelSmoother() ); smootherPrototype->SetParameter("Sweeps", Teuchos::ParameterEntry(2)); smootherPrototype->SetParameter("Damping factor", Teuchos::ParameterEntry(1.0)); smootherPrototype->AddFactoryManager(M11,0); smootherPrototype->AddFactoryManager(M22,1); RCP<SmootherFactory> smootherFact = rcp( new SmootherFactory(smootherPrototype) ); // Coarse grid correction RCP<BlockedGaussSeidelSmoother> coarseSolverPrototype = rcp( new BlockedGaussSeidelSmoother() ); coarseSolverPrototype->AddFactoryManager(M11,0); coarseSolverPrototype->AddFactoryManager(M22,1); RCP<SmootherFactory> coarseSolverFact = rcp( new SmootherFactory(coarseSolverPrototype, Teuchos::null) ); // main factory manager FactoryManager M; M.SetFactory("A", AcFact); M.SetFactory("P", PFact); M.SetFactory("R", RFact); M.SetFactory("Smoother", smootherFact); // TODO fix me M.SetFactory("CoarseSolver", coarseSolverFact); H.SetVerbLevel(MueLu::Test); H.Setup(M); std::cout << "main AcFact = " << AcFact.get() << std::endl; RCP<Level> l0 = H.GetLevel(0); RCP<Level> l1 = H.GetLevel(1); RCP<Level> l2 = H.GetLevel(2); l0->print(*out,Teuchos::VERB_EXTREME); l1->print(*out,Teuchos::VERB_EXTREME); l2->print(*out,Teuchos::VERB_EXTREME); // Define B RCP<Vector> X = VectorFactory::Build(bigMap,1); RCP<Vector> B = VectorFactory::Build(bigMap,1); X->setSeed(846930886); X->randomize(); bOp->apply(*X, *B, Teuchos::NO_TRANS, (SC)1.0, (SC)0.0); // X = 0 X->putScalar((SC) 0.0); LO nIts = 9; H.Iterate(*B, *X, nIts); success = true; } TEUCHOS_STANDARD_CATCH_STATEMENTS(verbose, std::cerr, success); return ( success ? EXIT_SUCCESS : EXIT_FAILURE ); }