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;
107 const int lastLevel = startLevel + numDesiredLevel - 1;
111 for (
int iLevel = startLevel; iLevel <= lastLevel; iLevel++)
147 RCP<Operator> Op = l0->Get<RCP<Operator>>(
"A");
150 if (l0->IsAvailable(
"Nullspace")) {
151 RCP<Matrix> A = Teuchos::rcp_dynamic_cast<Matrix>(Op);
152 if (A != Teuchos::null) {
153 RCP<MultiVector> nullspace = l0->Get<RCP<MultiVector>>(
"Nullspace");
155 if (
static_cast<size_t>(A->GetFixedBlockSize()) > nullspace->getNumVectors())
157 std::stringstream msg;
158 msg <<
"User-provided nullspace has fewer vectors ("
159 << nullspace->getNumVectors() <<
") than number of PDE equations ("
160 << A->GetFixedBlockSize() <<
"). ";
164 msg <<
"It depends on the PDE, if this is a problem or not.";
169 msg <<
"Add the missing nullspace vectors! (You can suppress this check. See the MueLu user guide for details.)";
170 TEUCHOS_TEST_FOR_EXCEPTION(
static_cast<size_t>(A->GetFixedBlockSize()) > nullspace->getNumVectors(),
Exceptions::RuntimeError, msg.str());
174 this->
GetOStream(
Warnings0) <<
"Skipping dimension check of user-supplied nullspace because user-supplied operator is not a matrix" << std::endl;
178#ifdef HAVE_MUELU_DEBUG
188 Xpetra::UnderlyingLib lib = Op->getDomainMap()->lib();
201 RCP<Matrix> Amat = rcp_dynamic_cast<Matrix>(Op);
203 if (!Amat.is_null()) {
204 RCP<ParameterList> params = rcp(
new ParameterList());
205 params->set(
"printLoadBalancingInfo",
true);
206 params->set(
"printCommInfo",
true);
239 std::map<int, std::vector<keep_pair> >::const_iterator it =
keep_.find(i);
240 if (it !=
keep_.end()) {
242 const std::vector<keep_pair>& keeps = it->second;
243 for (
size_t j = 0; j < keeps.size(); j++)
244 l->Keep(keeps[j].first, keeps[j].second);
247 RCP<Level> newLevel = rcp(
new Level());
261#ifdef HAVE_MUELU_INTREPID2
271 bool isLastLevel =
false;
273 while (!isLastLevel) {
274 bool r = H.
Setup(levelID,
275 LvlMngr(levelID-1, lastLevelID),
277 LvlMngr(levelID+1, lastLevelID));
281 isLastLevel = r || (levelID == lastLevelID);
315#ifdef HAVE_MUELU_INTREPID2
316 typedef Kokkos::DynRankView<LocalOrdinal,typename Node::device_type> FCi;
325 typedef std::map<std::string, RCP<const FactoryBase> >
FactoryMap;
339 Teuchos::RCP<FactoryManagerBase>
LvlMngr(
int levelID,
int lastLevelID)
const {
342 return Teuchos::null;
344 if (levelID == lastLevelID+1)
345 return Teuchos::null;
349 static RCP<FactoryManagerBase> defaultMngr = rcp(
new FactoryManager());
396 std::map<int, std::vector<keep_pair> >
keep_;
402 for (
int i = 0; i < data.size(); ++i) {
406 L->AddKeepFlag(name, &*
levelManagers_[data[i]]->GetFactory(name));
412 for (
int i = 0; i < data.size(); ++i) {
416 L->AddKeepFlag(name, &*
levelManagers_[data[i]+1]->GetFactory(name));
433 for (
int i = 0; i < data.size(); ++i) {
434 std::string fileName;
435 if (H.getObjectLabel() !=
"")
436 fileName = H.getObjectLabel() +
"_" + name +
"_" + Teuchos::toString(data[i]) +
".m";
438 fileName = name +
"_" + Teuchos::toString(data[i]) +
".m";
444 RCP<T> M = L->template Get< RCP<T> >(name,&*
levelManagers_[data[i]]->GetFactory(name));
446 Xpetra::IO<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Write(fileName,* M);
449 else if (L->IsAvailable(name)) {
451 RCP<T> M = L->template Get< RCP<T> >(name);
453 Xpetra::IO<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Write(fileName,* M);
461 for (
int i = 0; i < data.size(); ++i) {
462 const std::string fileName = name +
"_" + Teuchos::toString(data[i]) +
".m";
471 agg = L->template Get< RCP<Aggregates> >(name,&*
levelManagers_[data[i]+1]->GetFactory(name));
473 else if (L->IsAvailable(name)) {
474 agg = L->template Get<RCP<Aggregates> >(
"Aggregates");
477 std::ofstream ofs(fileName);
478 Teuchos::FancyOStream fofs(rcp(&ofs,
false));
479 agg->print(fofs,Teuchos::VERB_EXTREME);
486 void WriteDataFC(
Hierarchy& H,
const Teuchos::Array<int>& data,
const std::string& name,
const std::string & ofname)
const {
487 for (
int i = 0; i < data.size(); ++i) {
488 const std::string fileName = ofname +
"_" + Teuchos::toString(data[i]) +
".m";
493 if (L->IsAvailable(name)) {
494 RCP<T> M = L->template Get< RCP<T> >(name);
496 RCP<Matrix> A = L->template Get<RCP<Matrix> >(
"A");
497 RCP<const CrsGraph> AG = A->getCrsGraph();
509 size_t num_els = (size_t) fcont.extent(0);
510 size_t num_vecs =(size_t) fcont.extent(1);
513 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());
516 RCP<GOMultiVector> vec = Xpetra::MultiVectorFactory<GO, LO, GO, NO>::Build(rowMap,num_vecs);
518 for(
size_t j=0; j<num_vecs; j++) {
519 Teuchos::ArrayRCP<GO> v = vec->getDataNonConst(j);
520 for(
size_t i=0; i<num_els; i++)
521 v[i] = colMap.getGlobalElement(fcont(i,j));
524 Xpetra::IO<GO,LO,GO,NO>::Write(fileName,*vec);
536#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.
MueLu::HierarchyFactory< Scalar, LocalOrdinal, GlobalOrdinal, Node > HierarchyFactory
Array< RCP< FactoryManagerBase > > levelManagers_
Teuchos::Array< int > elementToNodeMapsToPrint_
virtual void SetupExtra(Hierarchy &) const
Setup extra data.
Teuchos::Array< int > nullspaceToPrint_
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
bool doPRViaCopyrebalance_
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
MueLu::Hierarchy< Scalar, LocalOrdinal, GlobalOrdinal, Node > Hierarchy
bool suppressNullspaceDimensionCheck_
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
void AddFactoryManager(int startLevel, int numDesiredLevel, RCP< FactoryManagerBase > manager)
virtual RCP< Hierarchy > CreateHierarchy(const std::string &label) const
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.
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 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