10#ifndef MUELU_HIERARCHYMANAGER_DECL_HPP
11#define MUELU_HIERARCHYMANAGER_DECL_HPP
16#include <Teuchos_Array.hpp>
18#include <Xpetra_Operator.hpp>
19#include <Xpetra_IO.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;
69 void AddFactoryManager(
int startLevel,
int numDesiredLevel, RCP<FactoryManagerBase> manager) {
70 const int lastLevel = startLevel + numDesiredLevel - 1;
74 for (
int iLevel = startLevel; iLevel <= lastLevel; iLevel++)
110 RCP<Operator> Op = l0->Get<RCP<Operator>>(
"A");
113 if (l0->IsAvailable(
"Nullspace")) {
114 RCP<Matrix> A = Teuchos::rcp_dynamic_cast<Matrix>(Op);
115 if (A != Teuchos::null) {
116 RCP<MultiVector> nullspace = l0->Get<RCP<MultiVector>>(
"Nullspace");
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.)";
129 TEUCHOS_TEST_FOR_EXCEPTION(
static_cast<size_t>(A->GetFixedBlockSize()) > nullspace->getNumVectors(),
Exceptions::RuntimeError, msg.str());
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
147 Xpetra::UnderlyingLib lib = Op->getDomainMap()->lib();
160 RCP<Matrix> Amat = rcp_dynamic_cast<Matrix>(Op);
162 if (!Amat.is_null()) {
163 RCP<ParameterList> params = rcp(
new ParameterList());
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);
208 RCP<Level> newLevel = rcp(
new Level());
223#ifdef HAVE_MUELU_INTREPID2
233 bool isLastLevel =
false;
235 while (!isLastLevel) {
236 bool r = H.
Setup(levelID,
237 LvlMngr(levelID - 1, lastLevelID),
239 LvlMngr(levelID + 1, lastLevelID));
243 isLastLevel = r || (levelID == lastLevelID);
278#ifdef HAVE_MUELU_INTREPID2
279 typedef Kokkos::DynRankView<LocalOrdinal, typename Node::device_type> FCi;
293 typedef std::map<std::string, RCP<const FactoryBase>>
FactoryMap;
306 Teuchos::RCP<FactoryManagerBase>
LvlMngr(
int levelID,
int lastLevelID)
const {
309 return Teuchos::null;
311 if (levelID == lastLevelID + 1)
312 return Teuchos::null;
316 static RCP<FactoryManagerBase> defaultMngr = rcp(
new FactoryManager());
363 std::map<int, std::vector<keep_pair>>
keep_;
369 for (
int i = 0; i < data.size(); ++i) {
373 L->AddKeepFlag(name, &*
levelManagers_[data[i]]->GetFactory(name));
379 for (
int i = 0; i < data.size(); ++i) {
383 L->AddKeepFlag(name, &*
levelManagers_[data[i] + 1]->GetFactory(name));
399 for (
int i = 0; i < data.size(); ++i) {
400 std::string fileName;
401 if (H.getObjectLabel() !=
"")
402 fileName = H.getObjectLabel() +
"_" + name +
"_" + Teuchos::toString(data[i]) +
".m";
404 fileName = name +
"_" + Teuchos::toString(data[i]) +
".m";
410 RCP<T> M = L->template Get<RCP<T>>(name, &*
levelManagers_[data[i]]->GetFactory(name));
412 Xpetra::IO<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Write(fileName, *M);
414 }
else if (L->IsAvailable(name)) {
416 RCP<T> M = L->template Get<RCP<T>>(name);
418 Xpetra::IO<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Write(fileName, *M);
426 for (
int i = 0; i < data.size(); ++i) {
427 const std::string fileName = name +
"_" + Teuchos::toString(data[i]) +
".m";
436 agg = L->template Get<RCP<Aggregates>>(name, &*
levelManagers_[data[i] + 1]->GetFactory(name));
437 }
else if (L->IsAvailable(name)) {
438 agg = L->template Get<RCP<Aggregates>>(
"Aggregates");
440 if (!agg.is_null()) {
441 std::ofstream ofs(fileName);
442 Teuchos::FancyOStream fofs(rcp(&ofs,
false));
443 agg->print(fofs, Teuchos::VERB_EXTREME);
450 void WriteDataFC(
Hierarchy& H,
const Teuchos::Array<int>& data,
const std::string& name,
const std::string& ofname)
const {
451 for (
int i = 0; i < data.size(); ++i) {
452 const std::string fileName = ofname +
"_" + Teuchos::toString(data[i]) +
".m";
457 if (L->IsAvailable(name)) {
458 RCP<T> M = L->template Get<RCP<T>>(name);
460 RCP<Matrix> A = L->template Get<RCP<Matrix>>(
"A");
461 RCP<const CrsGraph> AG = A->getCrsGraph();
472 size_t num_els = (size_t)fcont.extent(0);
473 size_t num_vecs = (size_t)fcont.extent(1);
476 Teuchos::RCP<const Map> rowMap = Xpetra::MapFactory<LO, GO, NO>::Build(colMap.lib(), Teuchos::OrdinalTraits<Xpetra::global_size_t>::invalid(), fcont.extent(0), colMap.getIndexBase(), colMap.getComm());
479 RCP<GOMultiVector> vec = Xpetra::MultiVectorFactory<GO, LO, GO, NO>::Build(rowMap, num_vecs);
481 for (
size_t j = 0; j < num_vecs; j++) {
482 Teuchos::ArrayRCP<GO> v = vec->getDataNonConst(j);
483 for (
size_t i = 0; i < num_els; i++)
484 v[i] = colMap.getGlobalElement(fcont(i, j));
487 Xpetra::IO<SC, LO, GO, NO>::WriteGOMV(fileName, *vec);
497#define MUELU_HIERARCHYMANAGER_SHORT
MueLu::DefaultLocalOrdinal LocalOrdinal
MueLu::DefaultScalar Scalar
MueLu::DefaultGlobalOrdinal GlobalOrdinal
Exception throws to report errors in the internal logical of the program.
This class specifies the default factory that should generate some data on a Level if the data does n...
Teuchos::Array< int > elementToNodeMapsToPrint_
void WriteFieldContainer(const std::string &fileName, T &fcont, const Map &colMap) const
void ExportDataSetKeepFlagsNextLevel(Hierarchy &H, const Teuchos::Array< int > &data, const std::string &name) const
Teuchos::Array< int > coordinatesToPrint_
Teuchos::RCP< Teuchos::ParameterList > matvecParams_
virtual void SetupExtra(Hierarchy &) const
Setup extra data.
int GetNumDesiredLevel()
Get the number of desired levels.
Teuchos::Array< int > aggregatesToPrint_
std::map< std::string, RCP< const FactoryBase > > FactoryMap
void ExportDataSetKeepFlags(Hierarchy &H, const Teuchos::Array< int > &data, const std::string &name) const
bool doPRViaCopyrebalance_
void WriteDataFC(Hierarchy &H, const Teuchos::Array< int > &data, const std::string &name, const std::string &ofname) const
void WriteData(Hierarchy &H, const Teuchos::Array< int > &data, const std::string &name) const
std::map< int, std::vector< keep_pair > > keep_
bool suppressNullspaceDimensionCheck_
Flag to indicate whether the check of the nullspace dimension is suppressed.
virtual void SetupOperator(Operator &) const
Setup Matrix object.
RCP< FactoryManagerBase > GetFactoryManager(int levelID) const
std::pair< std::string, const FactoryBase * > keep_pair
void WriteDataAggregates(Hierarchy &H, const Teuchos::Array< int > &data, const std::string &name) const
int graphOutputLevel_
-2 = no output, -1 = all levels
void AddFactoryManager(int startLevel, int numDesiredLevel, RCP< FactoryManagerBase > manager)
void SetNumDesiredLevel(int numDesiredLevel)
Set the number of desired levels.
virtual void SetupHierarchy(Hierarchy &H) const
Setup Hierarchy object.
std::map< std::string, Teuchos::Array< int > > matricesToPrint_
Xpetra::global_size_t maxCoarseSize_
virtual RCP< Hierarchy > CreateHierarchy() const
Create an empty Hierarchy object.
void ExportDataSetKeepFlagsAll(Hierarchy &H, const std::string &name) const
Teuchos::Array< int > nullspaceToPrint_
Lists of entities to be exported (or saved).
Teuchos::Array< std::string > dataToKeep_
bool fuseProlongationAndUpdate_
virtual ~HierarchyManager()=default
Destructor.
Array< RCP< FactoryManagerBase > > levelManagers_
HierarchyManager(int numDesiredLevel=MasterList::getDefault< int >("max levels"))
Constructor.
Teuchos::Array< int > materialToPrint_
virtual RCP< Hierarchy > CreateHierarchy(const std::string &label) const
Teuchos::RCP< FactoryManagerBase > LvlMngr(int levelID, int lastLevelID) const
size_t getNumFactoryManagers() const
returns number of factory managers stored in levelManagers_ vector.
Provides methods to build a multigrid hierarchy and apply multigrid cycles.
void AddLevel(const RCP< Level > &level)
Add a level at the end of the hierarchy.
RCP< Level > & GetLevel(const int levelID=0)
Retrieve a certain level from hierarchy.
std::string description() const
Return a simple one-line description of this object.
void CheckForEmptySmoothersAndCoarseSolve()
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 SetFuseProlongationAndUpdate(const bool &fuse)
void describe(Teuchos::FancyOStream &out, const VerbLevel verbLevel=Default) const
Print the Hierarchy with some verbosity level to a FancyOStream object.
void SetPRrebalance(bool doPRrebalance)
void SetPRViaCopyrebalance(bool doPRViaCopyrebalance)
void SetMatvecParams(RCP< ParameterList > matvecParams)
void Clear(int startLevel=0)
Clear impermanent data from previous setup.
void EnableGraphDumping(const std::string &filename, int levelID=1)
void SetMaxCoarseSize(Xpetra::global_size_t maxCoarseSize)
void AllocateLevelMultiVectors(int numvecs, bool forceMapCheck=false)
void SetImplicitTranspose(const bool &implicit)
Class that holds all level-specific information.
Static class that holds the complete list of valid MueLu parameters.
static const T & getDefault(const std::string &name)
Returns default value on the "master" list for a parameter with the specified name and type.
static std::string PrintMatrixInfo(const Matrix &A, const std::string &msgTag, RCP< const Teuchos::ParameterList > params=Teuchos::null)
Teuchos::FancyOStream & GetOStream(MsgType type, int thisProcRankOnly=0) const
Get an output stream for outputting the input message type.
bool IsPrint(MsgType type, int thisProcRankOnly=-1) const
Find out whether we need to print out information for a specific message type.
static void SetDefaultVerbLevel(const VerbLevel defaultVerbLevel)
Set the default (global) verbosity level.
Namespace for MueLu classes and methods.
@ Warnings0
Important warning messages (one line).
@ Statistics2
Print even more statistics.
@ Developer
Print information primarily of interest to developers.
@ Runtime0
One-liner description of what is happening.
@ Warnings1
Additional warnings.
Tpetra::KokkosClassic::DefaultNode::DefaultNodeType DefaultNode
Tpetra::Details::DefaultTypes::scalar_type DefaultScalar