46#include <Teuchos_TabularOutputter.hpp>
55 RCP<Level> newLevel = rcp(
new Level());
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))
116 Teuchos::RCP<MueLu::VariableContainer>& v =
map_[factory][ename];
117 v->RemoveKeepFlag(keep);
120 if ((v->IsRequested() ==
false) && (v->GetKeepFlag() == 0)) {
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);
174 TEUCHOS_TEST_FOR_EXCEPTION(
true,
Exceptions::RuntimeError,
"MueLu::Level::DeclareInput(): requestMode_ undefined.");
178 if (bRequestOnly && bReleaseOnly)
179 TEUCHOS_TEST_FOR_EXCEPTION(
true,
Exceptions::RuntimeError,
"MueLu::Level::DeclareDependencies(): Both bRequestOnly and bReleaseOnly set to true makes no sense.");
183 if (bReleaseOnly ==
false)
Request(*factory);
187 if (bRequestOnly ==
false)
Release(*factory);
189 }
else TEUCHOS_TEST_FOR_EXCEPTION(
true,
Exceptions::RuntimeError,
"MueLu::Level::DeclareDependencies(): requestMode_ undefined.");
221 if (!
IsKey(fac, ename)) {
223 map_[fac][ename] = newVar;
226 Teuchos::RCP<MueLu::VariableContainer>& v =
map_[fac][ename];
227 v->Request(requestedBy);
262 Teuchos::RCP<MueLu::VariableContainer>& v =
map_[fac][ename];
263 v->Release(requestedBy);
266 if ((v->IsRequested() ==
false) && (v->GetKeepFlag() == 0)) {
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;
329 Teuchos::RCP<MueLu::VariableContainer>& v =
map_[factory][ename];
331 if (v->GetKeepFlag() == 0 ||
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;
365 typedef Teuchos::TabularOutputter TTO;
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);
392 outputter.outputField(
"Null");
395 outputter.outputField(
"NoFactory");
399#ifdef HAVE_MUELU_DEBUG
400 oss<<
"(" << factory <<
")";
402 outputter.outputField(oss.str());
406 outputter.outputField(reqcount);
410 std::stringstream ss;
414 outputter.outputField(ss.str());
416 outputter.outputField(
"No");
420 std::string strType = it->second->GetTypeName();
422 if (strType ==
"int") {
423 outputter.outputField(strType);
424 outputter.outputField(it->second->GetData<
int>());
425 }
else if (strType ==
"double") {
426 outputter.outputField(strType);
427 outputter.outputField(it->second->GetData<
double>());
428 }
else if (strType ==
"string") {
429 outputter.outputField(strType);
430 outputter.outputField(it->second->GetData<std::string>());
432 size_t npos = std::string::npos;
434 if (strType.find(
"MueLu::Aggregates") != npos) outputter.outputField(
"Aggregates");
435 else if (strType.find(
"MueLu::AmalgamationInfo") != npos) outputter.outputField(
"AmalgamationInfo");
436 else if (strType.find(
"MueLu::Constraint") != npos) outputter.outputField(
"Constraint");
437 else if (strType.find(
"MueLu::Graph") != npos) outputter.outputField(
"Graph");
438 else if (strType.find(
"MueLu::SmootherBase") != npos) outputter.outputField(
"SmootherBase");
439 else if (strType.find(
"MueLu::SmootherPrototype") != npos) outputter.outputField(
"SmootherPrototype");
440 else if (strType.find(
"Xpetra::Export") != npos) outputter.outputField(
"Export");
441 else if (strType.find(
"Xpetra::Import") != npos) outputter.outputField(
"Import");
442 else if (strType.find(
"Xpetra::Map") != npos) outputter.outputField(
"Map");
443 else if (strType.find(
"Xpetra::Matrix") != npos) outputter.outputField(
"Matrix" );
444 else if (strType.find(
"Xpetra::MultiVector") != npos) outputter.outputField(
"Vector");
445 else if (strType.find(
"Xpetra::Operator") != npos) outputter.outputField(
"Operator");
446 else outputter.outputField(strType);
448 outputter.outputField(
"available");
452 outputter.outputField(
"unknown");
453 outputter.outputField(
"not available");
457 const container_type& requestedBy = it->second->Requests();
458 std::ostringstream ss;
459 for (container_type::const_iterator ct = requestedBy.begin(); ct != requestedBy.end(); ct++) {
460 if (ct != requestedBy.begin()) ss <<
",";
461 ss << ct->first->ShortClassName() <<
"["<<ct->first->GetID()<<
"]";
462#ifdef HAVE_MUELU_DEBUG
463 ss<<
"("<<ct->first<<
")";
466 if (ct->second > 1) ss <<
"x" << ct->second;
468 outputter.outputField(ss.str());
475#if defined(HAVE_MUELU_BOOST) && defined(HAVE_MUELU_BOOST_FOR_REAL) && defined(BOOST_VERSION) && (BOOST_VERSION >= 104400)
476 void Level::UpdateGraph(std::map<const FactoryBase*, BoostVertex>& vindices,
477 std::map<std::pair<BoostVertex, BoostVertex>, std::string>& edges,
479 BoostGraph& graph)
const {
480 size_t vind = vindices.size();
482 for (TwoKeyMap::const_iterator it1 =
map_.begin(); it1 !=
map_.end(); it1++) {
483 if (vindices.find(it1->first) == vindices.end()) {
484 BoostVertex boost_vertex = boost::add_vertex(graph);
485 std::ostringstream oss; oss<<it1->first->ShortClassName() <<
"[" << it1->first->GetID() <<
"]";
486 boost::put(
"label", dp, boost_vertex, oss.str());
487 vindices[it1->first] = vind++;
490 for (SubMap::const_iterator it2 = it1->second.begin(); it2 != it1->second.end(); it2++) {
492 for (VariableContainer::request_container::const_iterator rit = requests.begin(); rit != requests.end(); rit++) {
493 if (vindices.find(rit->first) == vindices.end()) {
495 BoostVertex boost_vertex = boost::add_vertex(graph);
496 std::ostringstream oss; oss<<rit->first->ShortClassName() <<
"[" << rit->first->GetID() <<
"]";
497 boost::put(
"label", dp, boost_vertex, oss.str());
498 vindices[rit->first] = vind++;
501 edges[std::pair<BoostVertex,BoostVertex>(vindices[rit->first], vindices[it1->first])] = it2->first;
524 TEUCHOS_TEST_FOR_EXCEPTION(fac == NULL,
Exceptions::RuntimeError,
"MueLu::Level("<<
levelID_ <<
")::GetFactory(" << ename <<
", " << factory <<
"): Default factory returned by FactoryManager cannot be NULL");
virtual std::string ShortClassName() const
Return the class name of the object, without template parameters and without namespace.
virtual std::string description() const
Return a simple one-line description of this object.
Exception throws to report data dependency problems between factories.
Exception throws to report errors in the internal logical of the program.
Base class for factories (e.g., R, P, and A_coarse).
virtual void CallDeclareInput(Level &requestedLevel) const =0
int GetID() const
return unique factory id
bool IsAvailable(const std::string &ename, const FactoryBase *factory=NoFactory::get()) const
Test whether a need's value has been saved.
const FactoryBase * GetFactory(const std::string &varname, const FactoryBase *factory) const
If input factory == NULL, returns the default factory. Else, return input factory.
void DeclareInput(const std::string &ename, const FactoryBase *factory, const FactoryBase *requestedBy=NoFactory::get())
Callback from FactoryBase::CallDeclareInput() and FactoryBase::DeclareInput()
std::string description() const
Return a simple one-line description of this object.
static RequestMode requestMode_
void Release(const FactoryBase &factory)
Decrement the storage counter for all the inputs of a factory.
int CountRequestedFactory(const FactoryBase *factory) const
const RCP< const FactoryManagerBase > GetFactoryManager()
returns the current factory manager
void SetLevelID(int levelID)
Set level number.
void print(std::ostream &out, const VerbLevel verbLevel=Default) const
Printing method.
RCP< Level > previousLevel_
void RemoveKeepFlag(const std::string &ename, const FactoryBase *factory, KeepType keep=MueLu::All)
int GetLevelID() const
Return level number.
void Clear()
Delete all data that have been retained after the setup phase using Final flag.
void AddKeepFlag(const std::string &ename, const FactoryBase *factory=NoFactory::get(), KeepType keep=MueLu::Keep)
T & Get(const std::string &ename, const FactoryBase *factory=NoFactory::get())
Get data without decrementing associated storage counter (i.e., read-only access)....
void DeclareDependencies(const FactoryBase *factory, bool bRequestOnly=false, bool bReleaseOnly=false)
Callback from FactoryBase::CallDeclareInput() and FactoryBase::DeclareInput() to declare factory depe...
bool IsRequestedFactory(const FactoryBase *factory) const
KeepType GetKeepFlag(const std::string &ename, const FactoryBase *factory) const
Get the flag combination set for variable 'ename' generated by 'factory'.
RCP< const FactoryManagerBase > factoryManager_
bool IsKept(const std::string &ename, const FactoryBase *factory, KeepType keep) const
bool IsAvailableFactory(const FactoryBase *factory) const
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.
bool IsRequestedBy(const FactoryBase *factory, const std::string &ename, const FactoryBase *requestedBy) const
void SetPreviousLevel(const RCP< Level > &previousLevel)
void SetFactoryManager(const RCP< const FactoryManagerBase > &factoryManager)
Set default factories (used internally by Hierarchy::SetLevel()).
int levelID_
Map of a map (Key1 -> SubMap)
bool IsKey(const FactoryBase *factory, const std::string &ename) const
Test whether some information about (ename, factory) are stored.
static const NoFactory * get()
Class that stores all relevant data for a variable.
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.
Namespace for MueLu classes and methods.
@ Final
Keep data only for this run. Used to keep data useful for Hierarchy::Iterate(). Data will be deleted ...
@ Keep
Always keep data, even accross run. This flag is set by Level::Keep(). This flag is propagated to coa...
@ NextRun
Both UserData and Keep flags force data to be kept and reused for the next run. Do not use MueLu::Nex...
@ UserData
User data are always kept. This flag is set automatically when Level::Set("data", data) is used....
@ Debug
Print additional debugging information.
@ Warnings1
Additional warnings.