46 #ifndef MUELU_VARIABLECONTAINER_HPP 47 #define MUELU_VARIABLECONTAINER_HPP 51 #include <Teuchos_TypeNameTraits.hpp> 53 #include <Xpetra_Matrix.hpp> 54 #include <Xpetra_Operator.hpp> 79 virtual const std::type_info&
type()
const = 0;
80 virtual std::string
typeName()
const = 0;
87 const std::type_info&
type()
const {
return typeid(T); }
88 std::string
typeName()
const {
return Teuchos::TypeNameTraits<T>::name(); }
95 const std::string typeName = Teuchos::TypeNameTraits<T>::name();
96 TEUCHOS_TEST_FOR_EXCEPTION(
data_ == NULL, Teuchos::bad_any_cast,
97 "Error, cast to type Data<" << typeName <<
"> failed since the content is NULL");
98 TEUCHOS_TEST_FOR_EXCEPTION(
data_->
type() !=
typeid(T), Teuchos::bad_any_cast,
99 "Error, cast to type Data<" << typeName <<
"> failed since the actual underlying type is " 103 TEUCHOS_TEST_FOR_EXCEPTION(!data, std::logic_error,
104 "Error, cast to type Data<" << typeName <<
"> failed but should not have and the actual underlying type is " 105 "\'" <<
data_->
typeName() <<
"! The problem might be related to incompatible RTTI systems in static and shared libraries!");
167 return std::string(
"");
182 request_container::iterator it =
requests_.find(reqFactory);
192 request_container::iterator it =
requests_.find(reqFactory);
194 "cannot call Release if factory has not been requested before by factory " << reqFactory);
195 if (--(it->second) == 0)
202 request_container::const_iterator it =
requests_.find(reqFactory);
203 return (it !=
requests_.end()) ? it->second : 0;
237 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
239 typedef Xpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node>
Operator;
240 typedef Xpetra::Matrix <Scalar,LocalOrdinal,GlobalOrdinal,Node>
Matrix;
243 typedef Teuchos::RCP<Operator> TO;
244 typedef Teuchos::RCP<Matrix> TM;
246 const std::string typeTOName = Teuchos::TypeNameTraits<TO>::name();
247 const std::string typeTMName = Teuchos::TypeNameTraits<TM>::name();
248 TEUCHOS_TEST_FOR_EXCEPTION(
data_ == NULL, Teuchos::bad_any_cast,
249 "Error, cast to type Data<" << typeTOName <<
"> failed since the content is NULL");
252 TEUCHOS_TEST_FOR_EXCEPTION(!data, std::logic_error,
253 "Error, cast to type Data<" << typeTOName <<
"> failed but should not have and the actual underlying type is " 254 "\'" <<
data_->
typeName() <<
"! The problem might be related to incompatible RTTI systems in static and shared libraries!");
258 TEUCHOS_TEST_FOR_EXCEPTION(
data_->
type() !=
typeid(TM), Teuchos::bad_any_cast,
259 "Error, cast to type Data<" << typeTMName <<
"> failed since the actual underlying type is " 262 TEUCHOS_TEST_FOR_EXCEPTION(!data, std::logic_error,
263 "Error, cast to type Data<" << typeTMName <<
"> failed but should not have and the actual underlying type is " 264 "\'" <<
data_->
typeName() <<
"! The problem might be related to incompatible RTTI systems in static and shared libraries!");
268 TEUCHOS_TEST_FOR_EXCEPTION(!datah, std::logic_error,
269 "Error, cast to type Data<" << typeTOName <<
"> failed but should not have and the actual underlying type is " 270 "\'" <<
datah_->
typeName() <<
"! The problem might be related to incompatible RTTI systems in static and shared libraries!");
virtual std::string typeName() const =0
VariableContainer()
Default constructor.
void AddKeepFlag(KeepType keep=UserData)
Adds a keep flag to the flag combination.
int NumRequests(const FactoryBase *reqFactory) const
Return the number of times the data has been requested by a specific factory.
void SetData(const T &entry)
Store data in container class and set the "Available" status true.
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.
Namespace for MueLu classes and methods.
int count_
number of requests by all factories
bool IsKept(KeepType keep) const
Returns true if at least one keep flag is set.
Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > Matrix
void Request(const FactoryBase *reqFactory)
Request data.
bool IsRequested(const FactoryBase *reqFactory) const
Returns true, if data is requested by reqFactory.
bool available_
is data available?
std::map< const FactoryBase *, int > request_container
const std::type_info & type() const
std::string typeName() const
Base class for factories (e.g., R, P, and A_coarse).
request_container requests_
requesting factories
const request_container & Requests() const
int NumAllRequests() const
Returns the number of times the data has been requested.
void Release(const FactoryBase *reqFactory)
Release data.
KeepType GetKeepFlag() const
Returns the keep flag combination.
std::string GetTypeName()
Xpetra::Operator< Scalar, LocalOrdinal, GlobalOrdinal, Node > Operator
bool IsAvailable() const
Returns true if data is available, i.e.
static T & get(DataBase *data_, DataBase *&datah_)
Base class for MueLu classes.
virtual const std::type_info & type() const =0
const T & GetData() const
DataBase * data_
the data itself
Exception throws to report errors in the internal logical of the program.
Class that stores all relevant data for a variable.
bool IsRequested() const
Returns true, if data is requested by at least one factory.