46 #ifndef MUELU_LEVEL_HPP 47 #define MUELU_LEVEL_HPP 55 #include <Teuchos_Describable.hpp> 56 #include <Teuchos_FancyOStream.hpp> 57 #include <Teuchos_RCPDecl.hpp> 58 #include <Teuchos_RCP.hpp> 59 #include <Teuchos_TestForException.hpp> 61 #include <Xpetra_Map.hpp> 68 #include "MueLu_Utilities.hpp" 168 map_[factory][ename]->SetData(entry);
171 GetOStream(
Warnings1) <<
"Level::Set: unable to store \"" << ename <<
"\" generated by factory " << factory->ShortClassName() <<
"["<<factory->GetID()<<
"]" 172 <<
"(" << factory <<
")" 173 <<
" on level " <<
toString(
GetLevelID()) <<
", as it has not been requested and no keep flags were set for it" << std::endl;
201 "\"" << ename <<
"\" has not been requested (counter = " <<
NumRequests(fac, ename) <<
", " 202 "KeepFlag = " <<
GetKeepFlag(ename, fac) <<
"). " << std::endl <<
203 "Generating factory:" << *fac <<
" NoFactory = " <<
NoFactory::get());
209 "MueLu::Level::Get(): factory did not produce expected output on level " <<
GetLevelID()
210 <<
". The data \"" << ename <<
"\" has not been generated by " << *fac);
212 return map_[fac][ename]->template GetData<T>();
218 rValue = Get<T>(ename, factory);
233 "\"" << ename <<
"\" generated by " << *fac <<
" is not available.");
235 return map_[fac][ename]->GetTypeName();
262 if (!
IsKey(factory, ename))
268 TEUCHOS_TEST_FOR_EXCEPTION(
IsRequested(ename, factory) ==
true,
Exceptions::RuntimeError,
"MueLu::Level::Delete(): IsRequested() == true. Ref counter != 0. You are not allowed to delete data that are still in use.");
275 TEUCHOS_TEST_FOR_EXCEPTION(
IsAvailable(ename, factory) ==
true,
Exceptions::RuntimeError,
"MueLu::Level::Delete(): Internal error (Post condition). Data have not been deleted.");
335 if (!
IsKey(factory, ename))
338 return Get(factory, ename)->IsAvailable();
346 if (!
IsKey(factory, ename))
367 #if defined(HAVE_MUELU_BOOST) && defined(HAVE_MUELU_BOOST_FOR_REAL) && defined(BOOST_VERSION) && (BOOST_VERSION >= 104400) 368 void UpdateGraph(std::map<const FactoryBase*, BoostVertex>& vindices,
369 std::map<std::pair<BoostVertex, BoostVertex>, std::string>& edges,
371 BoostGraph& graph)
const;
414 RCP<const Teuchos::Comm<int> >
comm_;
417 typedef const std::string
Key2;
418 typedef RCP<VariableContainer>
Value;
419 typedef Teuchos::map<Key2, Value>
SubMap;
432 TwoKeyMap::const_iterator it =
map_.find(factory);
433 return (it !=
map_.end()) ? (it->second).count(ename) :
false;
437 TwoKeyMap::const_iterator it =
map_.find(factory);
438 if (it ==
map_.end())
440 for (SubMap::const_iterator sit = it->second.begin(); sit != it->second.end(); sit++) {
441 if (sit->second->IsAvailable())
449 "Internal logic error: if counter == 0, the entry in countTable_ should have been deleted");
450 return v->IsRequested();
454 if (!
IsKey(factory, ename))
462 "Internal logic error: if counter == 0, the entry in countTable_ should have been deleted");
463 return v->IsRequested(requestedBy);
467 TwoKeyMap::const_iterator it =
map_.find(factory);
468 if (it ==
map_.end())
470 for (SubMap::const_iterator sit = it->second.begin(); sit != it->second.end(); sit++)
477 TwoKeyMap::const_iterator it =
map_.find(factory);
480 SubMap::const_iterator sit = it->second.find(ename);
481 TEUCHOS_TEST_FOR_EXCEPTION(sit == it->second.end(),
Exceptions::RuntimeError,
"Key (" << factory <<
", " << ename <<
") does not exist.");
488 const Teuchos::RCP<MueLu::VariableContainer>& v =
Get(factory, ename);
490 "NumRequests(): Internal logic error: if counter == 0, the entry in countTable_ should have been deleted");
491 return v->NumAllRequests();
495 TwoKeyMap::const_iterator it =
map_.find(factory);
496 if (it ==
map_.end())
500 for (SubMap::const_iterator sit = it->second.begin(); sit != it->second.end(); sit++)
501 cnt += sit->second->NumAllRequests();
514 #endif // MUELU_LEVEL_HPP void Keep(const std::string &ename, const FactoryBase *factory)
Request to keep variable 'ename' generated by 'factory' after the setup phase.
RCP< Level > & GetPreviousLevel()
Previous level.
RCP< const Teuchos::Comm< int > > comm_
bool IsRequestedBy(const Value &v, const FactoryBase *requestedBy) const
T & Get(const std::string &ename, const FactoryBase *factory=NoFactory::get())
Get data without decrementing associated storage counter (i.e., read-only access). Usage: Level->Get< RCP<Matrix> >("A", factory) if factory == NULL => use default factory.
virtual void CallBuild(Level &requestedLevel) const =0
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.
void DeclareDependencies(const FactoryBase *factory, bool bRequestOnly=false, bool bReleaseOnly=false)
Callback from FactoryBase::CallDeclareInput() and FactoryBase::DeclareInput() to declare factory depe...
void Release(const FactoryBase &factory)
Decrement the storage counter for all the inputs of a factory.
RequestMode GetRequestMode() const
Xpetra::UnderlyingLib lib_
const FactoryBase * GetFactory(const std::string &varname, const FactoryBase *factory) const
If input factory == NULL, returns the default factory. Else, return input factory.
RCP< Level > previousLevel_
User data are always kept. This flag is set automatically when Level::Set("data", data) is used...
Namespace for MueLu classes and methods.
void SetPreviousLevel(const RCP< Level > &previousLevel)
KeepType GetKeepFlag(const std::string &ename, const FactoryBase *factory) const
Get the flag combination set for variable 'ename' generated by 'factory'.
bool IsRequested(const Value &v) const
void SetFactoryManager(const RCP< const FactoryManagerBase > &factoryManager)
Set default factories (used internally by Hierarchy::SetLevel()).
static const NoFactory * get()
void setlib(Xpetra::UnderlyingLib lib2)
int GetLevelID() const
Return level number.
bool IsRequested(const std::string &ename, const FactoryBase *factory=NoFactory::get()) const
Test whether a need has been requested. Note: this tells nothing about whether the need's value exist...
const Value & Get(const FactoryBase *factory, const std::string &ename) const
Base class for factories (e.g., R, P, and A_coarse).
void Clear()
Delete all data that have been retained after the setup phase using Final flag.
std::string description() const
Return a simple one-line description of this object.
Class that holds all level-specific information.
Level(RCP< FactoryManagerBase > &factoryManager)
static RequestMode requestMode_
RCP< const Teuchos::Comm< int > > GetComm() const
void Delete(const std::string &ename, const FactoryBase *factory)
Delete data that have been retained after the setup phase (using Keep(), AddKeepFlag(), or internal MueLu logic).
int levelID_
Map of a map (Key1 -> SubMap)
std::string GetTypeName(const std::string &ename, const FactoryBase *factory=NoFactory::get())
GetTypeName returns type string of variable stored using ename and factory.
void print(std::ostream &out, const VerbLevel verbLevel=Default) const
Printing method.
void RemoveKeepFlag(const std::string &ename, const FactoryBase *factory, KeepType keep=MueLu::All)
Xpetra::UnderlyingLib lib()
Always keep data, even accross run. This flag is set by Level::Keep(). This flag is propagated to coa...
virtual ~Level()
Destructor.
bool IsKey(const FactoryBase *factory, const std::string &ename) const
Test whether some information about (ename, factory) are stored.
void AddKeepFlag(const std::string &ename, const FactoryBase *factory=NoFactory::get(), KeepType keep=MueLu::Keep)
bool IsKept(const std::string &ename, const FactoryBase *factory, KeepType keep) const
void Set(const std::string &ename, const T &entry, const FactoryBase *factory=NoFactory::get())
int CountRequestedFactory(const FactoryBase *factory) const
bool IsRequestedBy(const FactoryBase *factory, const std::string &ename, const FactoryBase *requestedBy) const
Base class for MueLu classes.
Teuchos::map< Key1, SubMap > TwoKeyMap
Sub-map container (Key2 -> Value)
void SetLevelID(int levelID)
Set level number.
RCP< const FactoryManagerBase > factoryManager_
Teuchos::map< Key2, Value > SubMap
bool IsRequestedFactory(const FactoryBase *factory) const
bool IsAvailableFactory(const FactoryBase *factory) const
const RCP< const FactoryManagerBase > GetFactoryManager()
returns the current factory manager
bool IsAvailable(const std::string &ename, const FactoryBase *factory=NoFactory::get()) const
Test whether a need's value has been saved.
Exception throws to report errors in the internal logical of the program.
void SetComm(RCP< const Teuchos::Comm< int > > const &comm)
void DeclareInput(const std::string &ename, const FactoryBase *factory, const FactoryBase *requestedBy=NoFactory::get())
Callback from FactoryBase::CallDeclareInput() and FactoryBase::DeclareInput()
void Get(const std::string &ename, T &rValue, const FactoryBase *factory=NoFactory::get())
Get data without decrementing associated storage counter (i.e., read-only access).
int NumRequests(const FactoryBase *factory, const std::string &ename) const
void Request(const FactoryBase &factory)
Increment the storage counter for all the inputs of a factory.
RCP< VariableContainer > Value