// @HEADER // ***************************************************************************** // MueLu: A package for multigrid based preconditioning // // Copyright 2012 NTESS and the MueLu contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER #ifndef MUELU_HIERARCHY_DEF_HPP #define MUELU_HIERARCHY_DEF_HPP #include #include #include #include #include #include #include #include "MueLu_Hierarchy_decl.hpp" #include "MueLu_FactoryManager.hpp" #include "MueLu_HierarchyUtils.hpp" #include "MueLu_TopRAPFactory.hpp" #include "MueLu_TopSmootherFactory.hpp" #include "MueLu_Level.hpp" #include "MueLu_Monitor.hpp" #include "MueLu_PerfUtils.hpp" #include "MueLu_PFactory.hpp" #include "MueLu_SmootherFactory.hpp" #include "MueLu_SmootherBase.hpp" #include "Teuchos_TimeMonitor.hpp" namespace MueLu { template Hierarchy::Hierarchy() : maxCoarseSize_(GetDefaultMaxCoarseSize()) , implicitTranspose_(GetDefaultImplicitTranspose()) , fuseProlongationAndUpdate_(GetDefaultFuseProlongationAndUpdate()) , doPRrebalance_(GetDefaultPRrebalance()) , doPRViaCopyrebalance_(false) , isPreconditioner_(true) , Cycle_(GetDefaultCycle()) , WCycleStartLevel_(0) , scalingFactor_(Teuchos::ScalarTraits::one()) , lib_(Xpetra::UseTpetra) , isDumpingEnabled_(false) , dumpLevel_(-2) , rate_(-1) , sizeOfAllocatedLevelMultiVectors_(0) { AddLevel(rcp(new Level)); } template Hierarchy::Hierarchy(const std::string& label) : Hierarchy() { setObjectLabel(label); Levels_[0]->setObjectLabel(label); } template Hierarchy::Hierarchy(const RCP& A) : maxCoarseSize_(GetDefaultMaxCoarseSize()) , implicitTranspose_(GetDefaultImplicitTranspose()) , fuseProlongationAndUpdate_(GetDefaultFuseProlongationAndUpdate()) , doPRrebalance_(GetDefaultPRrebalance()) , doPRViaCopyrebalance_(false) , isPreconditioner_(true) , Cycle_(GetDefaultCycle()) , WCycleStartLevel_(0) , scalingFactor_(Teuchos::ScalarTraits::one()) , isDumpingEnabled_(false) , dumpLevel_(-2) , rate_(-1) , sizeOfAllocatedLevelMultiVectors_(0) { lib_ = A->getDomainMap()->lib(); RCP Finest = rcp(new Level); AddLevel(Finest); Finest->Set("A", A); } template Hierarchy::Hierarchy(const RCP& A, const std::string& label) : Hierarchy(A) { setObjectLabel(label); Levels_[0]->setObjectLabel(label); } template Hierarchy::~Hierarchy() = default; template void Hierarchy::AddLevel(const RCP& level) { int levelID = LastLevelID() + 1; // ID of the inserted level if (level->GetLevelID() != -1 && (level->GetLevelID() != levelID)) GetOStream(Warnings1) << "Hierarchy::AddLevel(): Level with ID=" << level->GetLevelID() << " have been added at the end of the hierarchy\n but its ID have been redefined" << " because last level ID of the hierarchy was " << LastLevelID() << "." << std::endl; Levels_.push_back(level); level->SetLevelID(levelID); level->setlib(lib_); level->SetPreviousLevel((levelID == 0) ? Teuchos::null : Levels_[LastLevelID() - 1]); level->setObjectLabel(this->getObjectLabel()); } template void Hierarchy::AddNewLevel() { RCP newLevel = Levels_[LastLevelID()]->Build(); // new coarse level, using copy constructor newLevel->setlib(lib_); this->AddLevel(newLevel); // add to hierarchy } template RCP& Hierarchy::GetLevel(const int levelID) { TEUCHOS_TEST_FOR_EXCEPTION(levelID < 0 || levelID > LastLevelID(), Exceptions::RuntimeError, "MueLu::Hierarchy::GetLevel(): invalid input parameter value: LevelID = " << levelID); return Levels_[levelID]; } template int Hierarchy::GetNumLevels() const { return Levels_.size(); } template int Hierarchy::GetGlobalNumLevels() const { RCP A = Levels_[0]->template Get>("A"); RCP> comm = A->getDomainMap()->getComm(); int numLevels = GetNumLevels(); int numGlobalLevels; Teuchos::reduceAll(*comm, Teuchos::REDUCE_MAX, numLevels, Teuchos::ptr(&numGlobalLevels)); return numGlobalLevels; } template double Hierarchy::GetOperatorComplexity() const { double totalNnz = 0, lev0Nnz = 1; for (int i = 0; i < GetNumLevels(); ++i) { TEUCHOS_TEST_FOR_EXCEPTION(!(Levels_[i]->IsAvailable("A")), Exceptions::RuntimeError, "Operator complexity cannot be calculated because A is unavailable on level " << i); RCP A = Levels_[i]->template Get>("A"); if (A.is_null()) break; RCP Am = rcp_dynamic_cast(A); if (Am.is_null()) { GetOStream(Warnings0) << "Some level operators are not matrices, operator complexity calculation aborted" << std::endl; return 0.0; } totalNnz += as(Am->getGlobalNumEntries()); if (i == 0) lev0Nnz = totalNnz; } return totalNnz / lev0Nnz; } template double Hierarchy::GetSmootherComplexity() const { double node_sc = 0, global_sc = 0; double a0_nnz = 0; const size_t INVALID = Teuchos::OrdinalTraits::invalid(); // Get cost of fine matvec if (GetNumLevels() <= 0) return -1.0; if (!Levels_[0]->IsAvailable("A")) return -1.0; RCP A = Levels_[0]->template Get>("A"); if (A.is_null()) return -1.0; RCP Am = rcp_dynamic_cast(A); if (Am.is_null()) return -1.0; a0_nnz = as(Am->getGlobalNumEntries()); // Get smoother complexity at each level for (int i = 0; i < GetNumLevels(); ++i) { size_t level_sc = 0; if (!Levels_[i]->IsAvailable("PreSmoother")) continue; RCP S = Levels_[i]->template Get>("PreSmoother"); if (S.is_null()) continue; level_sc = S->getNodeSmootherComplexity(); if (level_sc == INVALID) { global_sc = -1.0; break; } node_sc += as(level_sc); } double min_sc = 0.0; RCP> comm = A->getDomainMap()->getComm(); Teuchos::reduceAll(*comm, Teuchos::REDUCE_SUM, node_sc, Teuchos::ptr(&global_sc)); Teuchos::reduceAll(*comm, Teuchos::REDUCE_MIN, node_sc, Teuchos::ptr(&min_sc)); if (min_sc < 0.0) return -1.0; else return global_sc / a0_nnz; } // Coherence checks todo in Setup() (using an helper function): template void Hierarchy::CheckLevel(Level& level, int levelID) { TEUCHOS_TEST_FOR_EXCEPTION(level.lib() != lib_, Exceptions::RuntimeError, "MueLu::Hierarchy::CheckLevel(): wrong underlying linear algebra library."); TEUCHOS_TEST_FOR_EXCEPTION(level.GetLevelID() != levelID, Exceptions::RuntimeError, "MueLu::Hierarchy::CheckLevel(): wrong level ID"); TEUCHOS_TEST_FOR_EXCEPTION(levelID != 0 && level.GetPreviousLevel() != Levels_[levelID - 1], Exceptions::RuntimeError, "MueLu::Hierarchy::Setup(): wrong level parent"); } template void Hierarchy::SetMatvecParams(RCP matvecParams) { for (int i = 0; i < GetNumLevels(); ++i) { RCP level = Levels_[i]; if (level->IsAvailable("A")) { RCP Aop = level->Get>("A"); RCP A = rcp_dynamic_cast(Aop); if (!A.is_null()) { RCP xpImporter = A->getCrsGraph()->getImporter(); if (!xpImporter.is_null()) xpImporter->setDistributorParameters(matvecParams); RCP xpExporter = A->getCrsGraph()->getExporter(); if (!xpExporter.is_null()) xpExporter->setDistributorParameters(matvecParams); } } if (level->IsAvailable("P")) { RCP P = level->Get>("P"); RCP xpImporter = P->getCrsGraph()->getImporter(); if (!xpImporter.is_null()) xpImporter->setDistributorParameters(matvecParams); RCP xpExporter = P->getCrsGraph()->getExporter(); if (!xpExporter.is_null()) xpExporter->setDistributorParameters(matvecParams); } if (level->IsAvailable("R")) { RCP R = level->Get>("R"); RCP xpImporter = R->getCrsGraph()->getImporter(); if (!xpImporter.is_null()) xpImporter->setDistributorParameters(matvecParams); RCP xpExporter = R->getCrsGraph()->getExporter(); if (!xpExporter.is_null()) xpExporter->setDistributorParameters(matvecParams); } if (level->IsAvailable("Importer")) { RCP xpImporter = level->Get>("Importer"); if (!xpImporter.is_null()) xpImporter->setDistributorParameters(matvecParams); } } } // The function uses three managers: fine, coarse and next coarse // We construct the data for the coarse level, and do requests for the next coarse template bool Hierarchy::Setup(int coarseLevelID, const RCP fineLevelManager, const RCP coarseLevelManager, const RCP nextLevelManager) { // Use PrintMonitor/TimerMonitor instead of just a FactoryMonitor to print "Level 0" instead of Hierarchy(0) // Print is done after the requests for next coarse level TEUCHOS_TEST_FOR_EXCEPTION(LastLevelID() < coarseLevelID, Exceptions::RuntimeError, "MueLu::Hierarchy:Setup(): level " << coarseLevelID << " (specified by coarseLevelID argument) " "must be built before calling this function."); Level& level = *Levels_[coarseLevelID]; std::string label = FormattingHelper::getColonLabel(level.getObjectLabel()); TimeMonitor m1(*this, label + this->ShortClassName() + ": " + "Setup (total)"); TimeMonitor m2(*this, label + this->ShortClassName() + ": " + "Setup" + " (total, level=" + Teuchos::toString(coarseLevelID) + ")"); // TODO: pass coarseLevelManager by reference TEUCHOS_TEST_FOR_EXCEPTION(coarseLevelManager == Teuchos::null, Exceptions::RuntimeError, "MueLu::Hierarchy::Setup(): argument coarseLevelManager cannot be null"); typedef MueLu::TopRAPFactory TopRAPFactory; typedef MueLu::TopSmootherFactory TopSmootherFactory; if (levelManagers_.size() < coarseLevelID + 1) levelManagers_.resize(coarseLevelID + 1); levelManagers_[coarseLevelID] = coarseLevelManager; bool isFinestLevel = (fineLevelManager.is_null()); bool isLastLevel = (nextLevelManager.is_null()); int oldRank = -1; if (isFinestLevel) { RCP A = level.Get>("A"); RCP domainMap = A->getDomainMap(); RCP> comm = domainMap->getComm(); // Initialize random seed for reproducibility Utilities::SetRandomSeed(*comm); // Record the communicator on the level (used for timers sync) level.SetComm(comm); oldRank = SetProcRankVerbose(comm->getRank()); // Set the Hierarchy library to match that of the finest level matrix, // even if it was already set lib_ = domainMap->lib(); level.setlib(lib_); } else { // Permeate library to a coarser level level.setlib(lib_); Level& prevLevel = *Levels_[coarseLevelID - 1]; oldRank = SetProcRankVerbose(prevLevel.GetComm()->getRank()); } CheckLevel(level, coarseLevelID); // Attach FactoryManager to the fine level RCP SFMFine; if (!isFinestLevel) SFMFine = rcp(new SetFactoryManager(Levels_[coarseLevelID - 1], fineLevelManager)); if (isFinestLevel && Levels_[coarseLevelID]->IsAvailable("Coordinates")) ReplaceCoordinateMap(*Levels_[coarseLevelID]); // Attach FactoryManager to the coarse level SetFactoryManager SFMCoarse(Levels_[coarseLevelID], coarseLevelManager); if (isDumpingEnabled_ && (dumpLevel_ == 0 || dumpLevel_ == -1) && coarseLevelID == 1) DumpCurrentGraph(0); RCP coarseFact; RCP smootherFact = rcp(new TopSmootherFactory(coarseLevelManager, "Smoother")); int nextLevelID = coarseLevelID + 1; RCP SFMNext; if (isLastLevel == false) { // We are not at the coarsest level, so there is going to be another level ("next coarse") after this one ("coarse") if (nextLevelID > LastLevelID()) AddNewLevel(); CheckLevel(*Levels_[nextLevelID], nextLevelID); // Attach FactoryManager to the next level (level after coarse) SFMNext = rcp(new SetFactoryManager(Levels_[nextLevelID], nextLevelManager)); Levels_[nextLevelID]->Request(TopRAPFactory(coarseLevelManager, nextLevelManager)); // Do smoother requests here. We don't know whether this is going to be // the coarsest level or not, but we need to DeclareInput before we call // coarseRAPFactory.Build(), otherwise some stuff may be erased after // level releases level.Request(*smootherFact); } else { // Similar to smoother above, do the coarse solver request here. We don't // know whether this is going to be the coarsest level or not, but we // need to DeclareInput before we call coarseRAPFactory.Build(), // otherwise some stuff may be erased after level releases. This is // actually evident on ProjectorSmoother. It requires both "A" and // "Nullspace". However, "Nullspace" is erased after all releases, so if // we call the coarse factory request after RAP build we would not have // any data, and cannot get it as we don't have previous managers. The // typical trace looks like this: // // MueLu::Level(0)::GetFactory(Aggregates, 0): No FactoryManager // during request for data " Aggregates" on level 0 by factory TentativePFactory // during request for data " P" on level 1 by factory EminPFactory // during request for data " P" on level 1 by factory TransPFactory // during request for data " R" on level 1 by factory RAPFactory // during request for data " A" on level 1 by factory TentativePFactory // during request for data " Nullspace" on level 2 by factory NullspaceFactory // during request for data " Nullspace" on level 2 by factory NullspacePresmoothFactory // during request for data " Nullspace" on level 2 by factory ProjectorSmoother // during request for data " PreSmoother" on level 2 by factory NoFactory if (coarseFact.is_null()) coarseFact = rcp(new TopSmootherFactory(coarseLevelManager, "CoarseSolver")); level.Request(*coarseFact); } GetOStream(Runtime0) << std::endl; PrintMonitor m0(*this, "Level " + Teuchos::toString(coarseLevelID), static_cast(Runtime0 | Test)); // Build coarse level hierarchy RCP Ac = Teuchos::null; TopRAPFactory coarseRAPFactory(fineLevelManager, coarseLevelManager); if (level.IsAvailable("A")) { Ac = level.Get>("A"); } else if (!isFinestLevel) { // We only build here, the release is done later coarseRAPFactory.Build(*level.GetPreviousLevel(), level); } bool setLastLevelviaMaxCoarseSize = false; if (level.IsAvailable("A")) Ac = level.Get>("A"); RCP Acm = rcp_dynamic_cast(Ac); // Record the communicator on the level if (!Ac.is_null()) level.SetComm(Ac->getDomainMap()->getComm()); // Test if we reach the end of the hierarchy bool isOrigLastLevel = isLastLevel; if (isLastLevel) { // Last level as we have achieved the max limit isLastLevel = true; } else if (Ac.is_null()) { // Last level for this processor, as it does not belong to the next // subcommunicator. Other processors may continue working on the // hierarchy isLastLevel = true; } else { if (!Acm.is_null() && Acm->getGlobalNumRows() <= maxCoarseSize_) { // Last level as the size of the coarse matrix became too small GetOStream(Runtime0) << "Max coarse size (<= " << maxCoarseSize_ << ") achieved" << std::endl; isLastLevel = true; if (Acm->getGlobalNumRows() != 0) setLastLevelviaMaxCoarseSize = true; } } if (!Ac.is_null() && !isFinestLevel) { RCP A = Levels_[coarseLevelID - 1]->template Get>("A"); RCP Am = rcp_dynamic_cast(A); const double maxCoarse2FineRatio = 0.8; if (!Acm.is_null() && !Am.is_null() && Acm->getGlobalNumRows() > maxCoarse2FineRatio * Am->getGlobalNumRows()) { // We could abort here, but for now we simply notify user. // Couple of additional points: // - if repartitioning is delayed until level K, but the aggregation // procedure stagnates between levels K-1 and K. In this case, // repartitioning could enable faster coarsening once again, but the // hierarchy construction will abort due to the stagnation check. // - if the matrix is small enough, we could move it to one processor. GetOStream(Warnings0) << "Aggregation stagnated. Please check your matrix and/or adjust your configuration file." << "Possible fixes:\n" << " - reduce the maximum number of levels\n" << " - enable repartitioning\n" << " - increase the minimum coarse size." << std::endl; } } if (isLastLevel) { if (!isOrigLastLevel) { // We did not expect to finish this early so we did request a smoother. // We need a coarse solver instead. Do the magic. level.Release(*smootherFact); if (coarseFact.is_null()) coarseFact = rcp(new TopSmootherFactory(coarseLevelManager, "CoarseSolver")); level.Request(*coarseFact); } // Do the actual build, if we have any data. // NOTE: this is not a great check, we may want to call Build() regardless. if (!Ac.is_null()) coarseFact->Build(level); // Once the dirty deed is done, release stuff. The smoother has already // been released. level.Release(*coarseFact); } else { // isLastLevel = false => isOrigLastLevel = false, meaning that we have // requested the smoother. Now we need to build it and to release it. // We don't need to worry about the coarse solver, as we didn't request it. if (!Ac.is_null()) smootherFact->Build(level); level.Release(*smootherFact); } if (isLastLevel == true) { int actualNumLevels = nextLevelID; if (isOrigLastLevel == false) { // Earlier in the function, we constructed the next coarse level, and requested data for the that level, // assuming that we are not at the coarsest level. Now, we changed our mind, so we have to release those. Levels_[nextLevelID]->Release(TopRAPFactory(coarseLevelManager, nextLevelManager)); // We truncate/resize the hierarchy and possibly remove the last created level if there is // something wrong with it as indicated by its P not being valid. This might happen // if the global number of aggregates turns out to be zero if (!setLastLevelviaMaxCoarseSize) { if (Levels_[nextLevelID - 1]->IsAvailable("P")) { if (Levels_[nextLevelID - 1]->template Get>("P") == Teuchos::null) actualNumLevels = nextLevelID - 1; } else actualNumLevels = nextLevelID - 1; } } if (actualNumLevels == nextLevelID - 1) { // Didn't expect to finish early so we requested smoother but need coarse solver instead. Levels_[nextLevelID - 2]->Release(*smootherFact); if (Levels_[nextLevelID - 2]->IsAvailable("PreSmoother")) Levels_[nextLevelID - 2]->RemoveKeepFlag("PreSmoother", NoFactory::get()); if (Levels_[nextLevelID - 2]->IsAvailable("PostSmoother")) Levels_[nextLevelID - 2]->RemoveKeepFlag("PostSmoother", NoFactory::get()); if (coarseFact.is_null()) coarseFact = rcp(new TopSmootherFactory(coarseLevelManager, "CoarseSolver")); Levels_[nextLevelID - 2]->Request(*coarseFact); if (!(Levels_[nextLevelID - 2]->template Get>("A").is_null())) coarseFact->Build(*(Levels_[nextLevelID - 2])); Levels_[nextLevelID - 2]->Release(*coarseFact); } Levels_.resize(actualNumLevels); } // I think this is the proper place for graph so that it shows every dependence if (isDumpingEnabled_ && ((dumpLevel_ > 0 && coarseLevelID == dumpLevel_) || dumpLevel_ == -1)) DumpCurrentGraph(coarseLevelID); if (!isFinestLevel) { // Release the hierarchy data // We release so late to help blocked solvers, as the smoothers for them need A blocks // which we construct in RAPFactory level.Release(coarseRAPFactory); } if (oldRank != -1) SetProcRankVerbose(oldRank); return isLastLevel; } template void Hierarchy::SetupRe() { int numLevels = Levels_.size(); TEUCHOS_TEST_FOR_EXCEPTION(levelManagers_.size() != numLevels, Exceptions::RuntimeError, "Hierarchy::SetupRe: " << Levels_.size() << " levels, but " << levelManagers_.size() << " level factory managers"); const int startLevel = 0; Clear(startLevel); #ifdef HAVE_MUELU_DEBUG // Reset factories' data used for debugging for (int i = 0; i < numLevels; i++) levelManagers_[i]->ResetDebugData(); #endif int levelID; for (levelID = startLevel; levelID < numLevels;) { bool r = Setup(levelID, (levelID != 0 ? levelManagers_[levelID - 1] : Teuchos::null), levelManagers_[levelID], (levelID + 1 != numLevels ? levelManagers_[levelID + 1] : Teuchos::null)); levelID++; if (r) break; } // We may construct fewer levels for some reason, make sure we continue // doing that in the future Levels_.resize(levelID); levelManagers_.resize(levelID); int sizeOfVecs = sizeOfAllocatedLevelMultiVectors_; AllocateLevelMultiVectors(sizeOfVecs, true); // since the # of levels, etc. may have changed, force re-determination of description during next call to description() ResetDescription(); describe(GetOStream(Statistics0), GetVerbLevel()); CheckForEmptySmoothersAndCoarseSolve(); } template void Hierarchy::Setup(const FactoryManagerBase& manager, int startLevel, int numDesiredLevels) { // Use MueLu::BaseClass::description() to avoid printing "{numLevels = 1}" (numLevels is increasing...) PrintMonitor m0(*this, "Setup (" + this->MueLu::BaseClass::description() + ")", Runtime0); Clear(startLevel); // Check Levels_[startLevel] exists. TEUCHOS_TEST_FOR_EXCEPTION(Levels_.size() <= startLevel, Exceptions::RuntimeError, "MueLu::Hierarchy::Setup(): fine level (" << startLevel << ") does not exist"); TEUCHOS_TEST_FOR_EXCEPTION(numDesiredLevels <= 0, Exceptions::RuntimeError, "Constructing non-positive (" << numDesiredLevels << ") number of levels does not make sense."); // Check for fine level matrix A TEUCHOS_TEST_FOR_EXCEPTION(!Levels_[startLevel]->IsAvailable("A"), Exceptions::RuntimeError, "MueLu::Hierarchy::Setup(): fine level (" << startLevel << ") has no matrix A! " "Set fine level matrix A using Level.Set()"); RCP A = Levels_[startLevel]->template Get>("A"); lib_ = A->getDomainMap()->lib(); if (IsPrint(Statistics2)) { RCP Amat = rcp_dynamic_cast(A); if (!Amat.is_null()) { RCP params = rcp(new ParameterList()); params->set("printLoadBalancingInfo", true); params->set("printCommInfo", true); GetOStream(Statistics2) << PerfUtils::PrintMatrixInfo(*Amat, "A0", params); } else { GetOStream(Warnings1) << "Fine level operator is not a matrix, statistics are not available" << std::endl; } } RCP rcpmanager = rcpFromRef(manager); const int lastLevel = startLevel + numDesiredLevels - 1; GetOStream(Runtime0) << "Setup loop: startLevel = " << startLevel << ", lastLevel = " << lastLevel << " (stop if numLevels = " << numDesiredLevels << " or Ac.size() < " << maxCoarseSize_ << ")" << std::endl; // Setup multigrid levels int iLevel = 0; if (numDesiredLevels == 1) { iLevel = 0; Setup(startLevel, Teuchos::null, rcpmanager, Teuchos::null); // setup finest==coarsest level (first and last managers are Teuchos::null) } else { bool bIsLastLevel = Setup(startLevel, Teuchos::null, rcpmanager, rcpmanager); // setup finest level (level 0) (first manager is Teuchos::null) if (bIsLastLevel == false) { for (iLevel = startLevel + 1; iLevel < lastLevel; iLevel++) { bIsLastLevel = Setup(iLevel, rcpmanager, rcpmanager, rcpmanager); // setup intermediate levels if (bIsLastLevel == true) break; } if (bIsLastLevel == false) Setup(lastLevel, rcpmanager, rcpmanager, Teuchos::null); // setup coarsest level (last manager is Teuchos::null) } } // TODO: some check like this should be done at the beginning of the routine TEUCHOS_TEST_FOR_EXCEPTION(iLevel != Levels_.size() - 1, Exceptions::RuntimeError, "MueLu::Hierarchy::Setup(): number of level"); // TODO: this is not exception safe: manager will still hold default // factories if you exit this function with an exception manager.Clean(); describe(GetOStream(Statistics0), GetVerbLevel()); CheckForEmptySmoothersAndCoarseSolve(); } template void Hierarchy::CheckForEmptySmoothersAndCoarseSolve() { for (LO levelNo = 0; levelNo < GetNumLevels(); ++levelNo) { auto level = Levels_[levelNo]; if ((level->IsAvailable("A") && !level->template Get>("A").is_null()) && (!level->IsAvailable("PreSmoother")) && (!level->IsAvailable("PostSmoother"))) { GetOStream(Warnings1) << "No " << (levelNo == as(Levels_.size()) - 1 ? "coarse grid solver" : "smoother") << " on level " << level->GetLevelID() << std::endl; } } } template void Hierarchy::Clear(int startLevel) { if (startLevel < GetNumLevels()) GetOStream(Runtime0) << "Clearing old data (if any)" << std::endl; for (int iLevel = startLevel; iLevel < GetNumLevels(); iLevel++) Levels_[iLevel]->Clear(); } template void Hierarchy::ExpertClear() { GetOStream(Runtime0) << "Clearing old data (expert)" << std::endl; for (int iLevel = 0; iLevel < GetNumLevels(); iLevel++) Levels_[iLevel]->ExpertClear(); } #if defined(HAVE_MUELU_EXPERIMENTAL) && defined(HAVE_MUELU_ADDITIVE_VARIANT) template ConvergenceStatus Hierarchy::Iterate(const MultiVector& B, MultiVector& X, ConvData conv, bool InitialGuessIsZero, LO startLevel) { LO nIts = conv.maxIts_; MagnitudeType tol = conv.tol_; std::string prefix = this->ShortClassName() + ": "; std::string levelSuffix = " (level=" + toString(startLevel) + ")"; std::string levelSuffix1 = " (level=" + toString(startLevel + 1) + ")"; using namespace Teuchos; RCP