10 #ifndef MUELU_HIERARCHYMANAGER_DECL_HPP
11 #define MUELU_HIERARCHYMANAGER_DECL_HPP
24 #include "MueLu_Aggregates.hpp"
25 #include "MueLu_Hierarchy.hpp"
29 #include "MueLu_PerfUtils.hpp"
31 #ifdef HAVE_MUELU_INTREPID2
32 #include "Kokkos_DynRankView.hpp"
47 #undef MUELU_HIERARCHYMANAGER_SHORT
49 typedef std::pair<std::string, const FactoryBase*>
keep_pair;
53 HierarchyManager(
int numDesiredLevel = MasterList::getDefault<int>(
"max levels"))
70 const int lastLevel = startLevel + numDesiredLevel - 1;
74 for (
int iLevel = startLevel; iLevel <= lastLevel; iLevel++)
113 if (l0->IsAvailable(
"Nullspace")) {
114 RCP<Matrix> A = Teuchos::rcp_dynamic_cast<Matrix>(Op);
115 if (A != Teuchos::null) {
118 if (static_cast<size_t>(A->GetFixedBlockSize()) > nullspace->getNumVectors()) {
119 std::stringstream msg;
120 msg <<
"User-provided nullspace has fewer vectors ("
121 << nullspace->getNumVectors() <<
") than number of PDE equations ("
122 << A->GetFixedBlockSize() <<
"). ";
125 msg <<
"It depends on the PDE, if this is a problem or not.";
128 msg <<
"Add the missing nullspace vectors! (You can suppress this check. See the MueLu user guide for details.)";
133 this->
GetOStream(
Warnings0) <<
"Skipping dimension check of user-supplied nullspace because user-supplied operator is not a matrix" << std::endl;
137 #ifdef HAVE_MUELU_DEBUG
164 params->set(
"printLoadBalancingInfo",
true);
165 params->set(
"printCommInfo",
true);
200 std::map<int, std::vector<keep_pair>>::const_iterator it =
keep_.find(i);
201 if (it !=
keep_.end()) {
203 const std::vector<keep_pair>& keeps = it->second;
204 for (
size_t j = 0; j < keeps.size(); j++)
205 l->Keep(keeps[j].first, keeps[j].second);
207 if (i < numDesiredLevel_ - 1) {
222 #ifdef HAVE_MUELU_INTREPID2
231 int lastLevelID = numDesiredLevel_ - 1;
232 bool isLastLevel =
false;
234 while (!isLastLevel) {
235 bool r = H.
Setup(levelID,
236 LvlMngr(levelID - 1, lastLevelID),
238 LvlMngr(levelID + 1, lastLevelID));
242 isLastLevel = r || (levelID == lastLevelID);
264 numDesiredLevel_ = levelID;
268 WriteData<Matrix>(H,
iter->second,
iter->first);
276 #ifdef HAVE_MUELU_INTREPID2
277 typedef Kokkos::DynRankView<LocalOrdinal, typename Node::device_type> FCi;
291 typedef std::map<std::string, RCP<const FactoryBase>>
FactoryMap;
307 return Teuchos::null;
309 if (levelID == lastLevelID + 1)
310 return Teuchos::null;
360 std::map<int, std::vector<keep_pair>>
keep_;
366 for (
int i = 0; i < data.
size(); ++i) {
370 L->AddKeepFlag(name, &*
levelManagers_[data[i]]->GetFactory(name));
376 for (
int i = 0; i < data.
size(); ++i) {
380 L->AddKeepFlag(name, &*
levelManagers_[data[i] + 1]->GetFactory(name));
396 for (
int i = 0; i < data.
size(); ++i) {
397 std::string fileName;
411 }
else if (L->IsAvailable(name)) {
413 RCP<T> M = L->template Get<RCP<T>>(name);
423 for (
int i = 0; i < data.
size(); ++i) {
433 agg = L->template Get<RCP<Aggregates>>(name, &*
levelManagers_[data[i] + 1]->GetFactory(name));
434 }
else if (L->IsAvailable(name)) {
435 agg = L->template Get<RCP<Aggregates>>(
"Aggregates");
438 std::ofstream ofs(fileName);
448 for (
int i = 0; i < data.
size(); ++i) {
454 if (L->IsAvailable(name)) {
455 RCP<T> M = L->template Get<RCP<T>>(name);
459 WriteFieldContainer<T>(fileName, *M, *AG->getColMap());
469 size_t num_els = (size_t)fcont.extent(0);
470 size_t num_vecs = (size_t)fcont.extent(1);
478 for (
size_t j = 0; j < num_vecs; j++) {
480 for (
size_t i = 0; i < num_els; i++)
481 v[i] = colMap.getGlobalElement(fcont(i, j));
494 #define MUELU_HIERARCHYMANAGER_SHORT
495 #endif // MUELU_HIERARCHYMANAGER_HPP
virtual void SetupExtra(Hierarchy &) const
Setup extra data.
Important warning messages (one line)
virtual ~HierarchyManager()=default
Destructor.
This class specifies the default factory that should generate some data on a Level if the data does n...
MueLu::DefaultLocalOrdinal LocalOrdinal
Teuchos::FancyOStream & GetOStream(MsgType type, int thisProcRankOnly=0) const
Get an output stream for outputting the input message type.
virtual std::string getObjectLabel() const
void SetNumDesiredLevel(int numDesiredLevel)
Set the number of desired levels.
RCP< Level > & GetLevel(const int levelID=0)
Retrieve a certain level from hierarchy.
Tpetra::KokkosClassic::DefaultNode::DefaultNodeType DefaultNode
static Teuchos::RCP< MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Build(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node >> &map, size_t NumVectors, bool zeroOut=true)
void WriteDataAggregates(Hierarchy &H, const Teuchos::Array< int > &data, const std::string &name) const
void ExportDataSetKeepFlags(Hierarchy &H, const Teuchos::Array< int > &data, const std::string &name) const
RCP< FactoryManagerBase > GetFactoryManager(int levelID) const
void AddLevel(const RCP< Level > &level)
Add a level at the end of the hierarchy.
void CheckForEmptySmoothersAndCoarseSolve()
virtual RCP< Hierarchy > CreateHierarchy(const std::string &label) const
Create a labeled empty Hierarchy object.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
static void Write(const std::string &fileName, const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &M)
void SetMaxCoarseSize(Xpetra::global_size_t maxCoarseSize)
Print information primarily of interest to developers.
void AddFactoryManager(int startLevel, int numDesiredLevel, RCP< FactoryManagerBase > manager)
One-liner description of what is happening.
Teuchos::Array< int > elementToNodeMapsToPrint_
void Clear(int startLevel=0)
Clear impermanent data from previous setup.
void SetFuseProlongationAndUpdate(const bool &fuse)
Teuchos::RCP< FactoryManagerBase > LvlMngr(int levelID, int lastLevelID) const
std::map< std::string, RCP< const FactoryBase > > FactoryMap
Static class that holds the complete list of valid MueLu parameters.
Teuchos::Array< int > coordinatesToPrint_
Print even more statistics.
virtual RCP< Hierarchy > CreateHierarchy() const
Create an empty Hierarchy object.
Teuchos::Array< int > nullspaceToPrint_
Lists of entities to be exported (or saved)
void WriteData(Hierarchy &H, const Teuchos::Array< int > &data, const std::string &name) const
static void SetDefaultVerbLevel(const VerbLevel defaultVerbLevel)
Set the default (global) verbosity level.
size_t getNumFactoryManagers() const
returns number of factory managers stored in levelManagers_ vector.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
MueLu::DefaultScalar Scalar
Tpetra::Details::DefaultTypes::scalar_type DefaultScalar
MueLu::DefaultGlobalOrdinal GlobalOrdinal
Class that holds all level-specific information.
static Teuchos::RCP< Map< LocalOrdinal, GlobalOrdinal, Node > > Build(UnderlyingLib lib, global_size_t numGlobalElements, GlobalOrdinal indexBase, const Teuchos::RCP< const Teuchos::Comm< int >> &comm, LocalGlobal lg=Xpetra::GloballyDistributed)
std::string description() const
Return a simple one-line description of this object.
bool IsPrint(MsgType type, int thisProcRankOnly=-1) const
Find out whether we need to print out information for a specific message type.
Teuchos::Array< int > aggregatesToPrint_
bool suppressNullspaceDimensionCheck_
Flag to indicate whether the check of the nullspace dimension is suppressed.
void ExportDataSetKeepFlagsAll(Hierarchy &H, const std::string &name) const
void AllocateLevelMultiVectors(int numvecs, bool forceMapCheck=false)
Teuchos::Array< std::string > dataToKeep_
static std::string PrintMatrixInfo(const Matrix &A, const std::string &msgTag, RCP< const Teuchos::ParameterList > params=Teuchos::null)
void SetPRrebalance(bool doPRrebalance)
int graphOutputLevel_
-2 = no output, -1 = all levels
std::map< std::string, Teuchos::Array< int > > matricesToPrint_
virtual void SetupHierarchy(Hierarchy &H) const
Setup Hierarchy object.
void SetMatvecParams(RCP< ParameterList > matvecParams)
void SetPRViaCopyrebalance(bool doPRViaCopyrebalance)
virtual void SetupOperator(Operator &) const
Setup Matrix object.
void SetImplicitTranspose(const bool &implicit)
HierarchyManager(int numDesiredLevel=MasterList::getDefault< int >("max levels"))
Constructor.
Exception throws to report errors in the internal logical of the program.
std::pair< std::string, const FactoryBase * > keep_pair
void describe(Teuchos::FancyOStream &out, const VerbLevel verbLevel=Default) const
Print the Hierarchy with some verbosity level to a FancyOStream object.
int GetNumDesiredLevel()
Get the number of desired levels.
void WriteDataFC(Hierarchy &H, const Teuchos::Array< int > &data, const std::string &name, const std::string &ofname) const
void setlib(Xpetra::UnderlyingLib inlib)
bool doPRViaCopyrebalance_
Xpetra::global_size_t maxCoarseSize_
bool Setup(int coarseLevelID, const RCP< const FactoryManagerBase > fineLevelManager, const RCP< const FactoryManagerBase > coarseLevelManager, const RCP< const FactoryManagerBase > nextLevelManager=Teuchos::null)
Multi-level setup phase: build a new level of the hierarchy.
void WriteFieldContainer(const std::string &fileName, T &fcont, const Map &colMap) const
Teuchos::RCP< Teuchos::ParameterList > matvecParams_
bool fuseProlongationAndUpdate_
void EnableGraphDumping(const std::string &filename, int levelID=1)
std::map< int, std::vector< keep_pair > > keep_
Provides methods to build a multigrid hierarchy and apply multigrid cycles.
std::string toString(const T &t)
Array< RCP< FactoryManagerBase > > levelManagers_
void ExportDataSetKeepFlagsNextLevel(Hierarchy &H, const Teuchos::Array< int > &data, const std::string &name) const