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 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");
148 if (l0->IsAvailable(
"Nullspace")) {
149 RCP<Matrix> A = Teuchos::rcp_dynamic_cast<Matrix>(Op);
150 if (A != Teuchos::null) {
151 Teuchos::RCP<MultiVector> nullspace = l0->Get<RCP<MultiVector> >(
"Nullspace");
152 TEUCHOS_TEST_FOR_EXCEPTION(static_cast<size_t>(A->GetFixedBlockSize()) > nullspace->getNumVectors(),
Exceptions::RuntimeError,
"user-provided nullspace has fewer vectors (" << nullspace->getNumVectors() <<
") than number of PDE equations (" << A->GetFixedBlockSize() <<
")");
154 this->
GetOStream(
Warnings0) <<
"Skipping dimension check of user-supplied nullspace because user-supplied operator is not a matrix" << std::endl;
158 #ifdef HAVE_MUELU_DEBUG 168 Xpetra::UnderlyingLib lib = Op->getDomainMap()->lib();
181 RCP<Matrix> Amat = rcp_dynamic_cast<Matrix>(Op);
183 if (!Amat.is_null()) {
184 RCP<ParameterList> params = rcp(
new ParameterList());
185 params->set(
"printLoadBalancingInfo",
true);
186 params->set(
"printCommInfo",
true);
218 std::map<int, std::vector<keep_pair> >::const_iterator it =
keep_.find(i);
219 if (it !=
keep_.end()) {
221 const std::vector<keep_pair>& keeps = it->second;
222 for (
size_t j = 0; j < keeps.size(); j++)
223 l->Keep(keeps[j].first, keeps[j].second);
226 RCP<Level> newLevel = rcp(
new Level());
237 #ifdef HAVE_MUELU_INTREPID2 243 bool isLastLevel =
false;
245 while (!isLastLevel) {
246 bool r = H.
Setup(levelID,
247 LvlMngr(levelID-1, lastLevelID),
249 LvlMngr(levelID+1, lastLevelID));
252 isLastLevel = r || (levelID == lastLevelID);
280 #ifdef HAVE_MUELU_INTREPID2 281 typedef Kokkos::DynRankView<LocalOrdinal,typename Node::device_type> FCi;
290 typedef std::map<std::string, RCP<const FactoryBase> >
FactoryMap;
304 Teuchos::RCP<FactoryManagerBase>
LvlMngr(
int levelID,
int lastLevelID)
const {
307 return Teuchos::null;
309 if (levelID == lastLevelID+1)
310 return Teuchos::null;
314 static RCP<FactoryManagerBase> defaultMngr = rcp(
new FactoryManager());
339 std::map<int, std::vector<keep_pair> >
keep_;
344 for (
int i = 0; i < data.size(); ++i) {
348 L->AddKeepFlag(name, &*
levelManagers_[data[i]]->GetFactory(name));
354 for (
int i = 0; i < data.size(); ++i) {
358 L->AddKeepFlag(name, &*
levelManagers_[data[i]+1]->GetFactory(name));
366 for (
int i = 0; i < data.size(); ++i) {
367 std::string fileName;
368 if (H.getObjectLabel() !=
"")
369 fileName = H.getObjectLabel() +
"_" + name +
"_" +
Teuchos::toString(data[i]) +
".m";
377 RCP<T> M = L->template Get< RCP<T> >(name,&*
levelManagers_[data[i]]->GetFactory(name));
379 Xpetra::IO<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Write(fileName,* M);
382 else if (L->IsAvailable(name)) {
384 RCP<T> M = L->template Get< RCP<T> >(name);
386 Xpetra::IO<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Write(fileName,* M);
396 for (
int i = 0; i < data.size(); ++i) {
406 agg = L->template Get< RCP<Aggregates> >(name,&*
levelManagers_[data[i]+1]->GetFactory(name));
408 else if (L->IsAvailable(name)) {
409 agg = L->template Get<RCP<Aggregates> >(
"Aggregates");
412 std::ofstream ofs(fileName);
413 Teuchos::FancyOStream fofs(rcp(&ofs,
false));
414 agg->print(fofs,Teuchos::VERB_EXTREME);
421 void WriteDataFC(
Hierarchy& H,
const Teuchos::Array<int>& data,
const std::string& name,
const std::string & ofname)
const {
422 for (
int i = 0; i < data.size(); ++i) {
428 if (L->IsAvailable(name)) {
429 RCP<T> M = L->template Get< RCP<T> >(name);
431 RCP<Matrix> A = L->template Get<RCP<Matrix> >(
"A");
432 RCP<const CrsGraph> AG = A->getCrsGraph();
433 WriteFieldContainer<T>(fileName,*M,*AG->getColMap());
444 size_t num_els = (size_t) fcont.extent(0);
445 size_t num_vecs =(size_t) fcont.extent(1);
448 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());
451 RCP<GOMultiVector> vec = Xpetra::MultiVectorFactory<GO, LO, GO, NO>::Build(rowMap,num_vecs);
453 for(
size_t j=0; j<num_vecs; j++) {
454 Teuchos::ArrayRCP<GO> v = vec->getDataNonConst(j);
455 for(
size_t i=0; i<num_els; i++)
456 v[i] = colMap.getGlobalElement(fcont(i,j));
459 Xpetra::IO<GO,LO,GO,NO>::Write(fileName,*vec);
471 #define MUELU_HIERARCHYMANAGER_SHORT 472 #endif // MUELU_HIERARCHYMANAGER_HPP Important warning messages (one line)
void ExportDataSetKeepFlagsNextLevel(Hierarchy &H, const Teuchos::Array< int > &data, const std::string &name) const
This class specifies the default factory that should generate some data on a Level if the data does n...
Teuchos::Array< int > matricesToPrint_
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< 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.
virtual ~HierarchyManager()
Print even more statistics.
Teuchos::RCP< FactoryManagerBase > LvlMngr(int levelID, int lastLevelID) const
Teuchos::RCP< Teuchos::ParameterList > matvecParams_
MueLu::DefaultScalar Scalar
MueLu::DefaultGlobalOrdinal GlobalOrdinal
Class that holds all level-specific information.
Teuchos::Array< int > nullspaceToPrint_
Array< RCP< FactoryManagerBase > > levelManagers_
void ExportDataSetKeepFlags(Hierarchy &H, const Teuchos::Array< int > &data, const std::string &name) const
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)
void SetMatvecParams(RCP< ParameterList > matvecParams)
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.
Teuchos::Array< int > prolongatorsToPrint_
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"))
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_
Teuchos::Array< int > restrictorsToPrint_
void EnableGraphDumping(const std::string &filename, int levelID=1)
Provides methods to build a multigrid hierarchy and apply multigrid cycles.