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)
182 if (bReleaseOnly ==
false)
Request(*factory);
185 if (bRequestOnly ==
false)
Release(*factory);
220 if (!
IsKey(fac, ename)) {
222 map_[fac][ename] = newVar;
267 map_[fac].erase(ename);
268 if (
map_.count(fac) == 0)
280 for (TwoKeyMap::const_iterator kt =
map_.begin(); kt !=
map_.end(); kt++) {
283 for (SubMap::const_iterator it = kt->second.begin(); it != kt->second.end(); it++) {
286 const std::string ename = it->first;
298 if (
IsKey(factory, ename)) {
299 GetOStream(
Errors) <<
"Level::Clear found Internal data inconsistency" << std::endl;
314 }
while (wasRemoved ==
true);
318 TwoKeyMap::const_iterator kt =
map_.begin();
319 while (kt !=
map_.end()) {
322 SubMap::const_iterator it = kt->second.begin();
323 while (it != kt->second.end()) {
324 const std::string& ename = it->first;
334 map_[factory].erase(ename);
335 if (
map_.count(factory) == 0) {
342 if (
map_.count(factory) == 0) {
351 std::ostringstream out;
353 out <<
"{ levelID = " <<
levelID_ <<
"}";
358 if (!(verbLevel &
Debug))
361 out <<
"LevelID = " <<
GetLevelID() << std::endl;
365 outputter.pushFieldSpec(
"data name",
TTO::STRING, TTO::LEFT, TTO::GENERAL, 20);
366 outputter.pushFieldSpec(
"gen. factory addr.",
TTO::STRING, TTO::LEFT, TTO::GENERAL, 40);
367 outputter.pushFieldSpec(
"req",
TTO::INT, TTO::LEFT, TTO::GENERAL, 3);
368 outputter.pushFieldSpec(
"keep",
TTO::STRING, TTO::LEFT, TTO::GENERAL, 5);
369 outputter.pushFieldSpec(
"type",
TTO::STRING, TTO::LEFT, TTO::GENERAL, 18);
370 outputter.pushFieldSpec(
"data",
TTO::STRING, TTO::LEFT, TTO::GENERAL, 14);
371 outputter.pushFieldSpec(
"req'd by",
TTO::STRING, TTO::LEFT, TTO::GENERAL, 20);
372 outputter.outputHeader();
374 for (TwoKeyMap::const_iterator kt =
map_.begin(); kt !=
map_.end(); kt++) {
377 for (SubMap::const_iterator it = kt->second.begin(); it != kt->second.end(); it++) {
378 const std::string& ename = it->first;
380 outputter.outputField(ename);
390 outputter.outputField(
"Null");
392 outputter.outputField(
"NoFactory");
394 std::ostringstream oss;
396 #ifdef HAVE_MUELU_DEBUG
397 oss <<
"(" << factory <<
")";
399 outputter.outputField(oss.str());
403 outputter.outputField(reqcount);
407 std::stringstream ss;
417 outputter.outputField(ss.str());
419 outputter.outputField(
"No");
423 std::string strType = it->second->GetTypeName();
425 if (strType ==
"int") {
426 outputter.outputField(strType);
427 outputter.outputField(it->second->GetData<
int>());
428 }
else if (strType ==
"double") {
429 outputter.outputField(strType);
430 outputter.outputField(it->second->GetData<
double>());
431 }
else if (strType ==
"string") {
432 outputter.outputField(strType);
433 outputter.outputField(it->second->GetData<std::string>());
435 size_t npos = std::string::npos;
437 if (strType.find(
"MueLu::Aggregates") != npos)
438 outputter.outputField(
"Aggregates");
439 else if (strType.find(
"MueLu::AmalgamationInfo") != npos)
440 outputter.outputField(
"AmalgamationInfo");
441 else if (strType.find(
"MueLu::Constraint") != npos)
442 outputter.outputField(
"Constraint");
443 else if (strType.find(
"MueLu::SmootherBase") != npos)
444 outputter.outputField(
"SmootherBase");
445 else if (strType.find(
"MueLu::SmootherPrototype") != npos)
446 outputter.outputField(
"SmootherPrototype");
447 else if (strType.find(
"Xpetra::Export") != npos)
448 outputter.outputField(
"Export");
449 else if (strType.find(
"Xpetra::Import") != npos)
450 outputter.outputField(
"Import");
451 else if (strType.find(
"Xpetra::Map") != npos)
452 outputter.outputField(
"Map");
453 else if (strType.find(
"Xpetra::Matrix") != npos)
454 outputter.outputField(
"Matrix");
455 else if (strType.find(
"Xpetra::MultiVector") != npos)
456 outputter.outputField(
"Vector");
457 else if (strType.find(
"Xpetra::Operator") != npos)
458 outputter.outputField(
"Operator");
460 outputter.outputField(strType);
462 outputter.outputField(
"available");
466 outputter.outputField(
"unknown");
467 outputter.outputField(
"not available");
471 const container_type& requestedBy = it->second->Requests();
472 std::ostringstream ss;
473 for (container_type::const_iterator ct = requestedBy.begin(); ct != requestedBy.end(); ct++) {
474 if (ct != requestedBy.begin()) ss <<
",";
475 ss << ct->first->ShortClassName() <<
"[" << ct->first->GetID() <<
"]";
476 #ifdef HAVE_MUELU_DEBUG
477 ss <<
"(" << ct->first <<
")";
480 if (ct->second > 1) ss <<
"x" << ct->second;
482 outputter.outputField(ss.str());
489 #if defined(HAVE_MUELU_BOOST) && defined(HAVE_MUELU_BOOST_FOR_REAL) && defined(BOOST_VERSION) && (BOOST_VERSION >= 104400)
490 void Level::UpdateGraph(std::map<const FactoryBase*, BoostVertex>& vindices,
491 std::map<std::pair<BoostVertex, BoostVertex>, std::string>& edges,
493 BoostGraph& graph)
const {
494 size_t vind = vindices.size();
496 for (TwoKeyMap::const_iterator it1 =
map_.begin(); it1 !=
map_.end(); it1++) {
497 if (vindices.find(it1->first) == vindices.end()) {
498 BoostVertex boost_vertex = boost::add_vertex(graph);
499 std::ostringstream oss;
500 oss << it1->first->ShortClassName() <<
"[" << it1->first->GetID() <<
"]";
501 boost::put(
"label", dp, boost_vertex, oss.str());
502 vindices[it1->first] = vind++;
505 for (SubMap::const_iterator it2 = it1->second.begin(); it2 != it1->second.end(); it2++) {
507 for (VariableContainer::request_container::const_iterator rit = requests.begin(); rit != requests.end(); rit++) {
508 if (vindices.find(rit->first) == vindices.end()) {
510 BoostVertex boost_vertex = boost::add_vertex(graph);
511 std::ostringstream oss;
512 oss << rit->first->ShortClassName() <<
"[" << rit->first->GetID() <<
"]";
513 boost::put(
"label", dp, boost_vertex, oss.str());
514 vindices[rit->first] = vind++;
517 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'.
std::map< const FactoryBase *, int > request_container
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.
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.
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.