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, 40);
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, 18);
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);
393 outputter.outputField(
"NoFactory");
397 #ifdef HAVE_MUELU_DEBUG
398 oss<<
"(" << factory <<
")";
400 outputter.outputField(oss.str());
404 outputter.outputField(reqcount);
408 std::stringstream ss;
412 outputter.outputField(ss.str());
414 outputter.outputField(
"No");
418 std::string strType = it->second->GetTypeName();
420 if (strType ==
"int") {
421 outputter.outputField(strType);
422 outputter.outputField(it->second->GetData<
int>());
423 }
else if (strType ==
"double") {
424 outputter.outputField(strType);
425 outputter.outputField(it->second->GetData<
double>());
426 }
else if (strType ==
"string") {
427 outputter.outputField(strType);
428 outputter.outputField(it->second->GetData<std::string>());
430 size_t npos = std::string::npos;
432 if (strType.find(
"MueLu::Aggregates") != npos) outputter.outputField(
"Aggregates");
433 else if (strType.find(
"MueLu::AmalgamationInfo") != npos) outputter.outputField(
"AmalgamationInfo");
434 else if (strType.find(
"MueLu::Constraint") != npos) outputter.outputField(
"Constraint");
435 else if (strType.find(
"MueLu::Graph") != npos) outputter.outputField(
"Graph");
436 else if (strType.find(
"MueLu::SmootherBase") != npos) outputter.outputField(
"SmootherBase");
437 else if (strType.find(
"MueLu::SmootherPrototype") != npos) outputter.outputField(
"SmootherPrototype");
438 else if (strType.find(
"Xpetra::Export") != npos) outputter.outputField(
"Export");
439 else if (strType.find(
"Xpetra::Import") != npos) outputter.outputField(
"Import");
440 else if (strType.find(
"Xpetra::Map") != npos) outputter.outputField(
"Map");
441 else if (strType.find(
"Xpetra::Matrix") != npos) outputter.outputField(
"Matrix" );
442 else if (strType.find(
"Xpetra::MultiVector") != npos) outputter.outputField(
"Vector");
443 else if (strType.find(
"Xpetra::Operator") != npos) outputter.outputField(
"Operator");
444 else outputter.outputField(strType);
446 outputter.outputField(
"available");
450 outputter.outputField(
"unknown");
451 outputter.outputField(
"not available");
455 const container_type& requestedBy = it->second->Requests();
456 std::ostringstream ss;
457 for (container_type::const_iterator ct = requestedBy.begin(); ct != requestedBy.end(); ct++) {
458 if (ct != requestedBy.begin()) ss <<
",";
459 ss << ct->first->ShortClassName() <<
"["<<ct->first->GetID()<<
"]";
460 #ifdef HAVE_MUELU_DEBUG
461 ss<<
"("<<ct->first<<
")";
464 if (ct->second > 1) ss <<
"x" << ct->second;
466 outputter.outputField(ss.str());
473 #if defined(HAVE_MUELU_BOOST) && defined(HAVE_MUELU_BOOST_FOR_REAL) && defined(BOOST_VERSION) && (BOOST_VERSION >= 104400)
474 void Level::UpdateGraph(std::map<const FactoryBase*, BoostVertex>& vindices,
475 std::map<std::pair<BoostVertex, BoostVertex>, std::string>& edges,
477 BoostGraph& graph)
const {
478 size_t vind = vindices.size();
480 for (TwoKeyMap::const_iterator it1 =
map_.begin(); it1 !=
map_.end(); it1++) {
481 if (vindices.find(it1->first) == vindices.end()) {
482 BoostVertex boost_vertex = boost::add_vertex(graph);
483 std::ostringstream oss; oss<<it1->first->ShortClassName() <<
"[" << it1->first->GetID() <<
"]";
484 boost::put(
"label", dp, boost_vertex, oss.str());
485 vindices[it1->first] = vind++;
488 for (SubMap::const_iterator it2 = it1->second.begin(); it2 != it1->second.end(); it2++) {
490 for (VariableContainer::request_container::const_iterator rit = requests.begin(); rit != requests.end(); rit++) {
491 if (vindices.find(rit->first) == vindices.end()) {
493 BoostVertex boost_vertex = boost::add_vertex(graph);
494 std::ostringstream oss; oss<<rit->first->ShortClassName() <<
"[" << rit->first->GetID() <<
"]";
495 boost::put(
"label", dp, boost_vertex, oss.str());
496 vindices[rit->first] = vind++;
499 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'.
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.
int GetID() const
return unique factory id
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
Teuchos::FancyOStream & GetOStream(MsgType type, int thisProcRankOnly=0) const
Get an output stream for outputting the input message type.
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.