46 #include <Teuchos_TabularOutputter.hpp>
58 for (TwoKeyMap::const_iterator kt =
map_.begin(); kt !=
map_.end(); kt++) {
61 for (SubMap::const_iterator it = kt->second.begin(); it != kt->second.end(); it++) {
62 const std::string& ename = it->first;
68 newLevel->Keep(ename, factory);
80 GetOStream(
Warnings1) <<
"Level::SetLevelID(): Changing an already defined LevelID (previousID=" <<
levelID_ <<
", newID=" << levelID <<
")" << std::endl;
87 GetOStream(
Warnings1) <<
"Level::SetPreviousLevel(): PreviousLevel was already defined" << std::endl;
101 if (!
IsKey(factory, ename)) {
104 map_[factory][ename] = newVar;
107 map_[factory][ename]->AddKeepFlag(keep);
112 if (!
IsKey(factory, ename))
123 map_[factory].erase(ename);
124 if (
map_.count(factory) == 0)
130 if (!
IsKey(factory,ename))
133 return Get(factory, ename)->GetKeepFlag();
153 Request(ename, factory, requestedBy);
156 std::ostringstream msg;
157 msg << requestedBy->
ShortClassName() <<
"::DeclareInput: (" << e.what() <<
") unable to find or generate requested data \""
158 << ename <<
"\" with generating factory \"" << ((factory != NULL) ? factory->
ShortClassName() :
"null") <<
"\" [" << factory <<
"]";
159 msg <<
"\n during request for data \"" << std::setw(15) << ename <<
"\" on level " <<
GetLevelID()
160 <<
" by factory " << std::setw(25) << requestedBy->
ShortClassName() <<
" [" << requestedBy <<
"]";
164 std::ostringstream msg;
165 msg << e.what() <<
"\n during request for data \"" << std::setw(15) << ename <<
"\" on level " <<
GetLevelID()
166 <<
" by factory " << std::setw(25) << requestedBy->
ShortClassName() <<
" [" << requestedBy <<
"]";
171 Release(ename, factory, requestedBy);
178 if (bRequestOnly && bReleaseOnly)
183 if (bReleaseOnly ==
false)
Request(*factory);
187 if (bRequestOnly ==
false)
Release(*factory);
221 if (!
IsKey(fac, ename)) {
223 map_[fac][ename] = newVar;
269 map_[fac].erase(ename);
270 if (
map_.count(fac) == 0)
282 for (TwoKeyMap::const_iterator kt =
map_.begin(); kt !=
map_.end(); kt++) {
285 for (SubMap::const_iterator it = kt->second.begin(); it != kt->second.end(); it++) {
288 const std::string ename = it->first;
300 if (
IsKey(factory, ename)) {
301 GetOStream(
Errors) <<
"Level::Clear found Internal data inconsistency" << std::endl;
316 }
while (wasRemoved ==
true);
320 TwoKeyMap::const_iterator kt =
map_.begin();
321 while (kt !=
map_.end()) {
324 SubMap::const_iterator it = kt->second.begin();
325 while ( it != kt->second.end()) {
326 const std::string& ename = it->first;
336 map_[factory].erase(ename);
337 if (
map_.count(factory) == 0) {
345 if (
map_.count(factory) == 0) {
353 std::ostringstream out;
355 out <<
"{ levelID = " <<
levelID_ <<
"}";
360 if (!(verbLevel &
Debug))
363 out <<
"LevelID = " <<
GetLevelID() << std::endl;
367 outputter.pushFieldSpec(
"data name",
TTO::STRING, TTO::LEFT, TTO::GENERAL, 20);
368 outputter.pushFieldSpec(
"gen. factory addr.",
TTO::STRING, TTO::LEFT, TTO::GENERAL, 18);
369 outputter.pushFieldSpec(
"req",
TTO::INT, TTO::LEFT, TTO::GENERAL, 3);
370 outputter.pushFieldSpec(
"keep",
TTO::STRING, TTO::LEFT, TTO::GENERAL, 5);
371 outputter.pushFieldSpec(
"type",
TTO::STRING, TTO::LEFT, TTO::GENERAL, 15);
372 outputter.pushFieldSpec(
"data",
TTO::STRING, TTO::LEFT, TTO::GENERAL, 14);
373 outputter.pushFieldSpec(
"req'd by",
TTO::STRING, TTO::LEFT, TTO::GENERAL, 20);
374 outputter.outputHeader();
376 for (TwoKeyMap::const_iterator kt =
map_.begin(); kt !=
map_.end(); kt++) {
379 for (SubMap::const_iterator it = kt->second.begin(); it != kt->second.end(); it++) {
380 const std::string& ename = it->first;
382 outputter.outputField(ename);
394 outputter.outputField(
"NoFactory");
396 outputter.outputField(factory);
400 outputter.outputField(reqcount);
404 std::stringstream ss;
408 outputter.outputField(ss.str());
410 outputter.outputField(
"No");
414 std::string strType = it->second->GetTypeName();
416 if (strType ==
"int") {
417 outputter.outputField(strType);
418 outputter.outputField(it->second->GetData<
int>());
419 }
else if (strType ==
"double") {
420 outputter.outputField(strType);
421 outputter.outputField(it->second->GetData<
double>());
422 }
else if (strType ==
"string") {
423 outputter.outputField(strType);
424 outputter.outputField(it->second->GetData<std::string>());
426 size_t npos = std::string::npos;
428 if (strType.find(
"MueLu::Aggregates") != npos) outputter.outputField(
"Aggregates");
429 else if (strType.find(
"MueLu::AmalgamationInfo") != npos) outputter.outputField(
"AmalgamationInfo");
430 else if (strType.find(
"MueLu::Constraint") != npos) outputter.outputField(
"Constraint");
431 else if (strType.find(
"MueLu::Graph") != npos) outputter.outputField(
"Graph");
432 else if (strType.find(
"MueLu::SmootherBase") != npos) outputter.outputField(
"SmootherBase");
433 else if (strType.find(
"MueLu::SmootherPrototype") != npos) outputter.outputField(
"SmootherPrototype");
434 else if (strType.find(
"Xpetra::Export") != npos) outputter.outputField(
"Export");
435 else if (strType.find(
"Xpetra::Import") != npos) outputter.outputField(
"Import");
436 else if (strType.find(
"Xpetra::Map") != npos) outputter.outputField(
"Map");
437 else if (strType.find(
"Xpetra::Matrix") != npos) outputter.outputField(
"Matrix" );
438 else if (strType.find(
"Xpetra::MultiVector") != npos) outputter.outputField(
"Vector");
439 else if (strType.find(
"Xpetra::Operator") != npos) outputter.outputField(
"Operator");
440 else outputter.outputField(strType);
442 outputter.outputField(
"available");
446 outputter.outputField(
"unknown");
447 outputter.outputField(
"not available");
451 const container_type& requestedBy = it->second->Requests();
452 std::ostringstream ss;
453 for (container_type::const_iterator ct = requestedBy.begin(); ct != requestedBy.end(); ct++) {
454 if (ct != requestedBy.begin()) ss <<
",";
456 if (ct->second > 1) ss <<
"(" << ct->second <<
")";
458 outputter.outputField(ss.str());
465 #if defined(HAVE_MUELU_BOOST) && defined(HAVE_MUELU_BOOST_FOR_REAL) && defined(BOOST_VERSION) && (BOOST_VERSION >= 104400)
466 void Level::UpdateGraph(std::map<const FactoryBase*, BoostVertex>& vindices,
467 std::map<std::pair<BoostVertex, BoostVertex>, std::string>& edges,
469 BoostGraph& graph)
const {
470 size_t vind = vindices.size();
472 for (TwoKeyMap::const_iterator it1 =
map_.begin(); it1 !=
map_.end(); it1++) {
473 if (vindices.find(it1->first) == vindices.end()) {
474 BoostVertex boost_vertex = boost::add_vertex(graph);
475 boost::put(
"label", dp, boost_vertex, it1->first->description());
476 vindices[it1->first] = vind++;
479 for (SubMap::const_iterator it2 = it1->second.begin(); it2 != it1->second.end(); it2++) {
481 for (VariableContainer::request_container::const_iterator rit = requests.begin(); rit != requests.end(); rit++) {
482 if (vindices.find(rit->first) == vindices.end()) {
484 BoostVertex boost_vertex = boost::add_vertex(graph);
485 boost::put(
"label", dp, boost_vertex, rit->first->description());
486 vindices[rit->first] = vind++;
489 edges[std::pair<BoostVertex,BoostVertex>(vindices[rit->first], vindices[it1->first])] = it2->first;
virtual void CallDeclareInput(Level &requestedLevel) const =0
KeepType GetKeepFlag(const std::string &ename, const FactoryBase *factory) const
Get the flag combination set for variable 'ename' generated by 'factory'.
Teuchos::FancyOStream & GetOStream(MsgType type, int thisProcRankOnly=0) const
Get an output stream for outputting the input message type.
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.
bool IsKept(const std::string &ename, const FactoryBase *factory, KeepType keep) const
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.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
KeepType GetKeepFlag() const
Returns the keep flag combination.
Print additional debugging information.
RCP< Level > previousLevel_
User data are always kept. This flag is set automatically when Level::Set("data", data) is used...
void RemoveKeepFlag(KeepType keep=UserData)
Removes a keep flag to the flag combination.
void SetPreviousLevel(const RCP< Level > &previousLevel)
void SetFactoryManager(const RCP< const FactoryManagerBase > &factoryManager)
Set default factories (used internally by Hierarchy::SetLevel()).
void Request(const FactoryBase *reqFactory)
Request data.
int CountRequestedFactory(const FactoryBase *factory) const
static const NoFactory * get()
virtual std::string ShortClassName() const
Return the class name of the object, without template parameters and without namespace.
std::map< const FactoryBase *, int > request_container
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.
bool IsRequestedBy(const FactoryBase *factory, const std::string &ename, const FactoryBase *requestedBy) const
const FactoryBase * GetFactory(const std::string &varname, const FactoryBase *factory) const
If input factory == NULL, returns the default factory. Else, return input factory.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
bool IsKept(KeepType keep) const
Returns true if at least one keep flag is set.
static RequestMode requestMode_
Keep data only for this run. Used to keep data useful for Hierarchy::Iterate(). Data will be deleted ...
int levelID_
Map of a map (Key1 -> SubMap)
void Release(const FactoryBase *reqFactory)
Release data.
void RemoveKeepFlag(const std::string &ename, const FactoryBase *factory, KeepType keep=MueLu::All)
std::string description() const
Return a simple one-line description of this object.
Always keep data, even accross run. This flag is set by Level::Keep(). This flag is propagated to coa...
int NumRequests(const FactoryBase *factory, const std::string &ename) const
void AddKeepFlag(const std::string &ename, const FactoryBase *factory=NoFactory::get(), KeepType keep=MueLu::Keep)
Both UserData and Keep flags force data to be kept and reused for the next run. Do not use MueLu::Nex...
bool IsAvailableFactory(const FactoryBase *factory) const
void print(std::ostream &out, const VerbLevel verbLevel=Default) const
Printing method.
void SetLevelID(int levelID)
Set level number.
RCP< const FactoryManagerBase > factoryManager_
bool IsRequestedFactory(const FactoryBase *factory) const
const RCP< const FactoryManagerBase > GetFactoryManager()
returns the current factory manager
int GetLevelID() const
Return level number.
Exception throws to report errors in the internal logical of the program.
Class that stores all relevant data for a variable.
bool IsKey(const FactoryBase *factory, const std::string &ename) const
Test whether some information about (ename, factory) are stored.
void DeclareInput(const std::string &ename, const FactoryBase *factory, const FactoryBase *requestedBy=NoFactory::get())
Callback from FactoryBase::CallDeclareInput() and FactoryBase::DeclareInput()
bool IsRequested(const FactoryBase *reqFactory) const
Returns true, if data is requested by reqFactory.
virtual std::string description() const
Return a simple one-line description of this object.
Exception throws to report data dependency problems between factories.
bool IsAvailable(const std::string &ename, const FactoryBase *factory=NoFactory::get()) const
Test whether a need's value has been saved.
void Request(const FactoryBase &factory)
Increment the storage counter for all the inputs of a factory.