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";
435 fileName = 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) {
459 const std::string fileName = name +
"_" + Teuchos::toString(data[i]) +
".m";
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) {
485 const std::string fileName = ofname +
"_" + Teuchos::toString(data[i]) +
".m";
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
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...
void WriteFieldContainer(const std::string &fileName, T &fcont, const Map &colMap) const
Teuchos::RCP< Teuchos::ParameterList > matvecParams_
void ExportDataSetKeepFlagsNextLevel(Hierarchy &H, const Teuchos::Array< int > &data, const std::string &name) const
virtual void SetupHierarchy(Hierarchy &H) const
Setup Hierarchy object.
Array< RCP< FactoryManagerBase > > levelManagers_
Teuchos::Array< int > elementToNodeMapsToPrint_
virtual void SetupExtra(Hierarchy &) const
Setup extra data.
Teuchos::Array< int > nullspaceToPrint_
Lists of entities to be exported (or saved)
std::map< std::string, RCP< const FactoryBase > > FactoryMap
std::map< std::string, Teuchos::Array< int > > matricesToPrint_
void ExportDataSetKeepFlags(Hierarchy &H, const Teuchos::Array< int > &data, const std::string &name) const
std::map< int, std::vector< keep_pair > > keep_
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
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)
virtual RCP< Hierarchy > CreateHierarchy(const std::string &label) const
Create a labeled empty Hierarchy object.
Xpetra::global_size_t maxCoarseSize_
void ExportDataSetKeepFlagsAll(Hierarchy &H, const std::string &name) const
bool fuseProlongationAndUpdate_
virtual ~HierarchyManager()=default
Destructor.
Teuchos::Array< int > coordinatesToPrint_
virtual RCP< Hierarchy > CreateHierarchy() const
Create an empty Hierarchy object.
HierarchyManager(int numDesiredLevel=MasterList::getDefault< int >("max levels"))
Constructor.
Teuchos::Array< std::string > dataToSave_
Teuchos::RCP< FactoryManagerBase > LvlMngr(int levelID, int lastLevelID) const
Teuchos::Array< int > aggregatesToPrint_
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 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 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 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.
KokkosClassic::DefaultNode::DefaultNodeType DefaultNode
@ 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::Details::DefaultTypes::scalar_type DefaultScalar