10 #ifndef MUELU_HIERARCHYMANAGER_DEF_HPP
11 #define MUELU_HIERARCHYMANAGER_DEF_HPP
25 #include "MueLu_Aggregates.hpp"
26 #include "MueLu_Hierarchy.hpp"
30 #include "MueLu_PerfUtils.hpp"
32 #ifdef HAVE_MUELU_INTREPID2
33 #include "Kokkos_DynRankView.hpp"
38 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
40 : numDesiredLevel_(numDesiredLevel)
41 , maxCoarseSize_(
MasterList::getDefault<int>(
"coarse: max size"))
43 , doPRrebalance_(
MasterList::getDefault<bool>(
"repartition: rebalance P and R"))
44 , doPRViaCopyrebalance_(
MasterList::getDefault<bool>(
"repartition: explicit via new copy rebalance P and R"))
45 , implicitTranspose_(
MasterList::getDefault<bool>(
"transpose: use implicit"))
46 , fuseProlongationAndUpdate_(
MasterList::getDefault<bool>(
"fuse prolongation and update"))
47 , suppressNullspaceDimensionCheck_(
MasterList::getDefault<bool>(
"nullspace: suppress dimension check"))
48 , sizeOfMultiVectors_(
MasterList::getDefault<int>(
"number of vectors"))
49 , graphOutputLevel_(-2) {}
51 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
53 const int lastLevel = startLevel + numDesiredLevel - 1;
54 if (levelManagers_.size() < lastLevel + 1)
55 levelManagers_.resize(lastLevel + 1);
57 for (
int iLevel = startLevel; iLevel <= lastLevel; iLevel++)
58 levelManagers_[iLevel] = manager;
61 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
64 return (levelID >= levelManagers_.size() ? levelManagers_[levelManagers_.size() - 1] : levelManagers_[levelID]);
67 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
69 return levelManagers_.size();
72 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
74 for (
int i = 0; i < levelManagers_.size(); i++)
78 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
83 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
88 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
96 if (l0->IsAvailable(
"Nullspace")) {
97 RCP<Matrix> A = Teuchos::rcp_dynamic_cast<Matrix>(Op);
98 if (A != Teuchos::null) {
101 if (static_cast<size_t>(A->GetFixedBlockSize()) > nullspace->getNumVectors()) {
102 std::stringstream msg;
103 msg <<
"User-provided nullspace has fewer vectors ("
104 << nullspace->getNumVectors() <<
") than number of PDE equations ("
105 << A->GetFixedBlockSize() <<
"). ";
107 if (suppressNullspaceDimensionCheck_) {
108 msg <<
"It depends on the PDE, if this is a problem or not.";
109 this->GetOStream(
Warnings0) << msg.str() << std::endl;
111 msg <<
"Add the missing nullspace vectors! (You can suppress this check. See the MueLu user guide for details.)";
116 this->GetOStream(
Warnings0) <<
"Skipping dimension check of user-supplied nullspace because user-supplied operator is not a matrix" << std::endl;
120 #ifdef HAVE_MUELU_DEBUG
122 for (
int i = 0; i < levelManagers_.size(); i++)
123 levelManagers_[i]->ResetDebugData();
139 if (graphOutputLevel_ >= 0 || graphOutputLevel_ == -1)
147 params->
set(
"printLoadBalancingInfo",
true);
148 params->
set(
"printCommInfo",
true);
180 for (
int i = 0; i < numDesiredLevel_; i++) {
181 std::map<int, std::vector<keep_pair>>::const_iterator it = keep_.find(i);
182 if (it != keep_.end()) {
184 const std::vector<keep_pair>& keeps = it->second;
185 for (
size_t j = 0; j < keeps.size(); j++)
186 l->
Keep(keeps[j].first, keeps[j].second);
188 if (i < numDesiredLevel_ - 1) {
195 for (
auto iter = matricesToPrint_.begin();
iter != matricesToPrint_.end();
iter++)
196 ExportDataSetKeepFlags(H,
iter->second,
iter->first);
199 ExportDataSetKeepFlags(H, nullspaceToPrint_,
"Nullspace");
200 ExportDataSetKeepFlags(H, coordinatesToPrint_,
"Coordinates");
201 ExportDataSetKeepFlags(H, materialToPrint_,
"Material");
203 ExportDataSetKeepFlagsNextLevel(H, aggregatesToPrint_,
"Aggregates");
204 #ifdef HAVE_MUELU_INTREPID2
205 ExportDataSetKeepFlags(H, elementToNodeMapsToPrint_,
"pcoarsen: element to node map");
209 for (
int i = 0; i < dataToKeep_.size(); i++)
210 ExportDataSetKeepFlagsAll(H, dataToKeep_[i]);
213 int lastLevelID = numDesiredLevel_ - 1;
214 bool isLastLevel =
false;
216 while (!isLastLevel) {
217 bool r = H.
Setup(levelID,
218 LvlMngr(levelID - 1, lastLevelID),
219 LvlMngr(levelID, lastLevelID),
220 LvlMngr(levelID + 1, lastLevelID));
224 isLastLevel = r || (levelID == lastLevelID);
227 if (!matvecParams_.is_null())
245 numDesiredLevel_ = levelID;
248 for (
auto iter = matricesToPrint_.begin();
iter != matricesToPrint_.end();
iter++) {
249 WriteData<Matrix>(H,
iter->second,
iter->first);
253 WriteData<MultiVector>(H, nullspaceToPrint_,
"Nullspace");
254 WriteData<MultiVector>(H, coordinatesToPrint_,
"Coordinates");
255 WriteData<MultiVector>(H, materialToPrint_,
"Material");
256 WriteDataAggregates(H, aggregatesToPrint_,
"Aggregates");
258 #ifdef HAVE_MUELU_INTREPID2
259 typedef Kokkos::DynRankView<LocalOrdinal, typename Node::device_type> FCi;
260 WriteDataFC<FCi>(H, elementToNodeMapsToPrint_,
"pcoarsen: element to node map",
"el2node");
265 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
269 return Teuchos::null;
271 if (levelID == lastLevelID + 1)
272 return Teuchos::null;
274 if (levelManagers_.size() == 0) {
280 return GetFactoryManager(levelID);
283 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
285 for (
int i = 0; i < data.
size(); ++i) {
288 if (!L.
is_null() && data[i] < levelManagers_.
size())
289 L->
AddKeepFlag(name, &*levelManagers_[data[i]]->GetFactory(name));
294 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
296 for (
int i = 0; i < data.
size(); ++i) {
299 if (!L.
is_null() && data[i] + 1 < levelManagers_.
size())
300 L->
AddKeepFlag(name, &*levelManagers_[data[i] + 1]->GetFactory(name));
305 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
309 if (!L.
is_null() && i < levelManagers_.size())
310 L->
AddKeepFlag(name, &*levelManagers_[i]->GetFactory(name));
314 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
317 for (
int i = 0; i < data.
size(); ++i) {
318 std::string fileName;
326 if (data[i] < levelManagers_.
size() && L->
IsAvailable(name, &*levelManagers_[data[i]]->GetFactory(name))) {
328 RCP<T> M = L->template Get<RCP<T>>(name, &*levelManagers_[data[i]]->GetFactory(name));
334 RCP<T> M = L->template Get<RCP<T>>(name);
343 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
345 for (
int i = 0; i < data.
size(); ++i) {
355 agg = L->template Get<RCP<Aggregates>>(name, &*levelManagers_[data[i] + 1]->GetFactory(name));
357 agg = L->template Get<RCP<Aggregates>>(
"Aggregates");
360 std::ofstream ofs(fileName);
368 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
371 for (
int i = 0; i < data.
size(); ++i) {
378 RCP<T> M = L->template Get<RCP<T>>(name);
382 WriteFieldContainer<T>(fileName, *M, *AG->getColMap());
389 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
392 size_t num_els = (size_t)fcont.extent(0);
393 size_t num_vecs = (size_t)fcont.extent(1);
401 for (
size_t j = 0; j < num_vecs; j++) {
403 for (
size_t i = 0; i < num_els; i++)
404 v[i] = colMap.getGlobalElement(fcont(i, j));
Important warning messages (one line)
void Keep(const std::string &ename, const FactoryBase *factory)
Request to keep variable 'ename' generated by 'factory' after the setup phase.
This class specifies the default factory that should generate some data on a Level if the data does n...
Teuchos::FancyOStream & GetOStream(MsgType type, int thisProcRankOnly=0) const
Get an output stream for outputting the input message type.
virtual std::string getObjectLabel() const
RCP< Level > & GetLevel(const int levelID=0)
Retrieve a certain level from hierarchy.
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()
#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.
void Clear(int startLevel=0)
Clear impermanent data from previous setup.
void SetFuseProlongationAndUpdate(const bool &fuse)
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Teuchos::RCP< FactoryManagerBase > LvlMngr(int levelID, int lastLevelID) const
Static class that holds the complete list of valid MueLu parameters.
Print even more statistics.
virtual RCP< Hierarchy > CreateHierarchy() const
Create an empty Hierarchy object.
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)
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.
void ExportDataSetKeepFlagsAll(Hierarchy &H, const std::string &name) const
void AddKeepFlag(const std::string &ename, const FactoryBase *factory=NoFactory::get(), KeepType keep=MueLu::Keep)
void AllocateLevelMultiVectors(int numvecs, bool forceMapCheck=false)
static std::string PrintMatrixInfo(const Matrix &A, const std::string &msgTag, RCP< const Teuchos::ParameterList > params=Teuchos::null)
void SetPRrebalance(bool doPRrebalance)
virtual void SetupHierarchy(Hierarchy &H) const
Setup Hierarchy object.
void SetMatvecParams(RCP< ParameterList > matvecParams)
void SetPRViaCopyrebalance(bool doPRViaCopyrebalance)
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.
void describe(Teuchos::FancyOStream &out, const VerbLevel verbLevel=Default) const
Print the Hierarchy with some verbosity level to a FancyOStream object.
void print(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=verbLevel_default) const
Print the object with some verbosity level to an FancyOStream object.
void WriteDataFC(Hierarchy &H, const Teuchos::Array< int > &data, const std::string &name, const std::string &ofname) const
void setlib(Xpetra::UnderlyingLib inlib)
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
void EnableGraphDumping(const std::string &filename, int levelID=1)
Provides methods to build a multigrid hierarchy and apply multigrid cycles.
std::string toString(const T &t)
bool IsAvailable(const std::string &ename, const FactoryBase *factory=NoFactory::get()) const
Test whether a need's value has been saved.
void ExportDataSetKeepFlagsNextLevel(Hierarchy &H, const Teuchos::Array< int > &data, const std::string &name) const