46 #ifndef MUELU_HIERARCHYMANAGER_DECL_HPP 47 #define MUELU_HIERARCHYMANAGER_DECL_HPP 52 #include <Teuchos_Array.hpp> 54 #include <Xpetra_Operator.hpp> 55 #include <Xpetra_IO.hpp> 60 #include "MueLu_Aggregates.hpp" 61 #include "MueLu_Hierarchy.hpp" 65 #include "MueLu_PerfUtils.hpp" 67 #ifdef HAVE_MUELU_INTREPID2 68 #include "Kokkos_DynRankView.hpp" 83 #undef MUELU_HIERARCHYMANAGER_SHORT 85 typedef std::pair<std::string, const FactoryBase*>
keep_pair;
106 const int lastLevel = startLevel + numDesiredLevel - 1;
110 for (
int iLevel = startLevel; iLevel <= lastLevel; iLevel++)
146 RCP<Operator> Op = l0->Get<RCP<Operator>>(
"A");
149 if (l0->IsAvailable(
"Nullspace")) {
150 RCP<Matrix> A = Teuchos::rcp_dynamic_cast<Matrix>(Op);
151 if (A != Teuchos::null) {
152 RCP<MultiVector> nullspace = l0->Get<RCP<MultiVector>>(
"Nullspace");
154 if (static_cast<size_t>(A->GetFixedBlockSize()) > nullspace->getNumVectors())
156 std::stringstream msg;
157 msg <<
"User-provided nullspace has fewer vectors (" 158 << nullspace->getNumVectors() <<
") than number of PDE equations (" 159 << A->GetFixedBlockSize() <<
"). ";
163 msg <<
"It depends on the PDE, if this is a problem or not.";
168 msg <<
"Add the missing nullspace vectors! (You can suppress this check. See the MueLu user guide for details.)";
169 TEUCHOS_TEST_FOR_EXCEPTION(static_cast<size_t>(A->GetFixedBlockSize()) > nullspace->getNumVectors(),
Exceptions::RuntimeError, msg.str());
173 this->
GetOStream(
Warnings0) <<
"Skipping dimension check of user-supplied nullspace because user-supplied operator is not a matrix" << std::endl;
177 #ifdef HAVE_MUELU_DEBUG 187 Xpetra::UnderlyingLib lib = Op->getDomainMap()->lib();
200 RCP<Matrix> Amat = rcp_dynamic_cast<Matrix>(Op);
202 if (!Amat.is_null()) {
203 RCP<ParameterList> params = rcp(
new ParameterList());
204 params->set(
"printLoadBalancingInfo",
true);
205 params->set(
"printCommInfo",
true);
237 std::map<int, std::vector<keep_pair> >::const_iterator it =
keep_.find(i);
238 if (it !=
keep_.end()) {
240 const std::vector<keep_pair>& keeps = it->second;
241 for (
size_t j = 0; j < keeps.size(); j++)
242 l->Keep(keeps[j].first, keeps[j].second);
245 RCP<Level> newLevel = rcp(
new Level());
259 #ifdef HAVE_MUELU_INTREPID2 269 bool isLastLevel =
false;
271 while (!isLastLevel) {
272 bool r = H.
Setup(levelID,
273 LvlMngr(levelID-1, lastLevelID),
275 LvlMngr(levelID+1, lastLevelID));
279 isLastLevel = r || (levelID == lastLevelID);
303 WriteData<Matrix>(H,iter->second,iter->first);
313 #ifdef HAVE_MUELU_INTREPID2 314 typedef Kokkos::DynRankView<LocalOrdinal,typename Node::device_type> FCi;
323 typedef std::map<std::string, RCP<const FactoryBase> >
FactoryMap;
337 Teuchos::RCP<FactoryManagerBase>
LvlMngr(
int levelID,
int lastLevelID)
const {
340 return Teuchos::null;
342 if (levelID == lastLevelID+1)
343 return Teuchos::null;
347 static RCP<FactoryManagerBase> defaultMngr = rcp(
new FactoryManager());
393 std::map<int, std::vector<keep_pair> >
keep_;
399 for (
int i = 0; i < data.size(); ++i) {
403 L->AddKeepFlag(name, &*
levelManagers_[data[i]]->GetFactory(name));
409 for (
int i = 0; i < data.size(); ++i) {
413 L->AddKeepFlag(name, &*
levelManagers_[data[i]+1]->GetFactory(name));
430 for (
int i = 0; i < data.size(); ++i) {
431 std::string fileName;
432 if (H.getObjectLabel() !=
"")
433 fileName = H.getObjectLabel() +
"_" + name +
"_" +
Teuchos::toString(data[i]) +
".m";
441 RCP<T> M = L->template Get< RCP<T> >(name,&*
levelManagers_[data[i]]->GetFactory(name));
443 Xpetra::IO<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Write(fileName,* M);
446 else if (L->IsAvailable(name)) {
448 RCP<T> M = L->template Get< RCP<T> >(name);
450 Xpetra::IO<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Write(fileName,* M);
458 for (
int i = 0; i < data.size(); ++i) {
468 agg = L->template Get< RCP<Aggregates> >(name,&*
levelManagers_[data[i]+1]->GetFactory(name));
470 else if (L->IsAvailable(name)) {
471 agg = L->template Get<RCP<Aggregates> >(
"Aggregates");
474 std::ofstream ofs(fileName);
475 Teuchos::FancyOStream fofs(rcp(&ofs,
false));
476 agg->print(fofs,Teuchos::VERB_EXTREME);
483 void WriteDataFC(
Hierarchy& H,
const Teuchos::Array<int>& data,
const std::string& name,
const std::string & ofname)
const {
484 for (
int i = 0; i < data.size(); ++i) {
490 if (L->IsAvailable(name)) {
491 RCP<T> M = L->template Get< RCP<T> >(name);
493 RCP<Matrix> A = L->template Get<RCP<Matrix> >(
"A");
494 RCP<const CrsGraph> AG = A->getCrsGraph();
495 WriteFieldContainer<T>(fileName,*M,*AG->getColMap());
506 size_t num_els = (size_t) fcont.extent(0);
507 size_t num_vecs =(size_t) fcont.extent(1);
510 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());
513 RCP<GOMultiVector> vec = Xpetra::MultiVectorFactory<GO, LO, GO, NO>::Build(rowMap,num_vecs);
515 for(
size_t j=0; j<num_vecs; j++) {
516 Teuchos::ArrayRCP<GO> v = vec->getDataNonConst(j);
517 for(
size_t i=0; i<num_els; i++)
518 v[i] = colMap.getGlobalElement(fcont(i,j));
521 Xpetra::IO<GO,LO,GO,NO>::Write(fileName,*vec);
533 #define MUELU_HIERARCHYMANAGER_SHORT 534 #endif // MUELU_HIERARCHYMANAGER_HPP Important warning messages (one line)
void ExportDataSetKeepFlagsNextLevel(Hierarchy &H, const Teuchos::Array< int > &data, const std::string &name) const
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
KokkosClassic::DefaultNode::DefaultNodeType DefaultNode
virtual void SetupOperator(Operator &) const
Setup Matrix object.
RCP< Level > & GetLevel(const int levelID=0)
Retrieve a certain level from hierarchy.
std::string toString(const T &what)
Little helper function to convert non-string types to strings.
Teuchos::FancyOStream & GetOStream(MsgType type, int thisProcRankOnly=0) const
Get an output stream for outputting the input message type.
static void SetDefaultVerbLevel(const VerbLevel defaultVerbLevel)
Set the default (global) verbosity level.
void AddLevel(const RCP< Level > &level)
Add a level at the end of the hierarchy.
Teuchos::Array< std::string > dataToSave_
Teuchos::Array< int > elementToNodeMapsToPrint_
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 WriteData(Hierarchy &H, const Teuchos::Array< int > &data, const std::string &name) const
void Clear(int startLevel=0)
Clear impermanent data from previous setup.
void WriteDataAggregates(Hierarchy &H, const Teuchos::Array< int > &data, const std::string &name) const
void SetFuseProlongationAndUpdate(const bool &fuse)
Namespace for MueLu classes and methods.
RCP< FactoryManagerBase > GetFactoryManager(int levelID) const
bool IsPrint(MsgType type, int thisProcRankOnly=-1) const
Find out whether we need to print out information for a specific message type.
std::map< std::string, RCP< const FactoryBase > > FactoryMap
Static class that holds the complete list of valid MueLu parameters.
virtual void SetupHierarchy(Hierarchy &H) const
Setup Hierarchy object.
Print even more statistics.
Teuchos::RCP< FactoryManagerBase > LvlMngr(int levelID, int lastLevelID) const
Teuchos::RCP< Teuchos::ParameterList > matvecParams_
MueLu::DefaultScalar Scalar
Tpetra::Details::DefaultTypes::scalar_type DefaultScalar
MueLu::DefaultGlobalOrdinal GlobalOrdinal
Class that holds all level-specific information.
Teuchos::Array< int > nullspaceToPrint_
Lists of entities to be exported (or saved)
std::map< std::string, Teuchos::Array< int > > matricesToPrint_
Array< RCP< FactoryManagerBase > > levelManagers_
void ExportDataSetKeepFlags(Hierarchy &H, const Teuchos::Array< int > &data, const std::string &name) const
bool suppressNullspaceDimensionCheck_
Flag to indicate whether the check of the nullspace dimension is suppressed.
void describe(Teuchos::FancyOStream &out, const VerbLevel verbLevel=Default) const
Print the Hierarchy with some verbosity level to a FancyOStream object.
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)
virtual void SetupExtra(Hierarchy &) const
Setup extra data.
void SetPRrebalance(bool doPRrebalance)
int graphOutputLevel_
-2 = no output, -1 = all levels
void SetMatvecParams(RCP< ParameterList > matvecParams)
void ExportDataSetKeepFlagsAll(Hierarchy &H, const std::string &name) const
Teuchos::Array< int > aggregatesToPrint_
void SetImplicitTranspose(const bool &implicit)
void WriteDataFC(Hierarchy &H, const Teuchos::Array< int > &data, const std::string &name, const std::string &ofname) const
virtual RCP< Hierarchy > CreateHierarchy() const
Create an empty Hierarchy object.
virtual RCP< Hierarchy > CreateHierarchy(const std::string &label) const
Create a labeled empty Hierarchy object.
void WriteFieldContainer(const std::string &fileName, T &fcont, const Map &colMap) const
Teuchos::Array< int > coordinatesToPrint_
std::map< int, std::vector< keep_pair > > keep_
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
size_t getNumFactoryManagers() const
returns number of factory managers stored in levelManagers_ vector.
void setlib(Xpetra::UnderlyingLib inlib)
std::string description() const
Return a simple one-line description of this object.
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.
bool fuseProlongationAndUpdate_
void EnableGraphDumping(const std::string &filename, int levelID=1)
Provides methods to build a multigrid hierarchy and apply multigrid cycles.