10#ifndef MUELU_VARIABLECONTAINER_HPP
11#define MUELU_VARIABLECONTAINER_HPP
15#include <Teuchos_TypeNameTraits.hpp>
17#include <Xpetra_Matrix.hpp>
18#include <Xpetra_Operator.hpp>
43 virtual const std::type_info&
type()
const = 0;
52 const std::type_info&
type()
const {
return typeid(T); }
53 std::string
typeName()
const {
return Teuchos::TypeNameTraits<T>::name(); }
62 const std::string typeName = Teuchos::TypeNameTraits<T>::name();
63 TEUCHOS_TEST_FOR_EXCEPTION(
data_ == NULL, Teuchos::bad_any_cast,
64 "Error, cast to type Data<" << typeName <<
"> failed since the content is NULL");
66 TEUCHOS_TEST_FOR_EXCEPTION(
data_->
type() !=
typeid(T), Teuchos::bad_any_cast,
67 "Error, cast to type Data<" << typeName <<
"> failed since the actual underlying type is "
75 const std::string typeName = Teuchos::TypeNameTraits<T>::name();
76 TEUCHOS_TEST_FOR_EXCEPTION(!data, std::logic_error,
77 "Error, cast to type Data<" << typeName <<
"> failed but should not have and the actual underlying type is "
79 <<
data_->
typeName() <<
"! The problem might be related to incompatible RTTI systems in static and shared libraries!");
139 template <
typename T>
150 template <
typename T>
157 template <
typename T>
164 template <
typename T>
171 return std::string(
"");
186 request_container::iterator it =
requests_.find(reqFactory);
196 request_container::iterator it =
requests_.find(reqFactory);
198 "MueLu::VariableContainer::Release(): "
199 "cannot call Release if factory has not been requested before by factory "
201 if (--(it->second) == 0)
208 request_container::const_iterator it =
requests_.find(reqFactory);
209 return (it !=
requests_.end()) ? it->second : 0;
242template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
244 typedef Xpetra::Operator<Scalar, LocalOrdinal, GlobalOrdinal, Node>
Operator;
245 typedef Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>
Matrix;
248 typedef Teuchos::RCP<Operator> TO;
249 typedef Teuchos::RCP<Matrix> TM;
253 TEUCHOS_TEST_FOR_EXCEPTION(
data_ == NULL, Teuchos::bad_any_cast,
254 "Error, cast to type Data<" << Teuchos::TypeNameTraits<TO>::name() <<
"> failed since the content is NULL");
260 TEUCHOS_TEST_FOR_EXCEPTION(!data, std::logic_error,
261 "Error, cast to type Data<" << Teuchos::TypeNameTraits<TO>::name() <<
"> failed but should not have and the actual underlying type is "
263 <<
data_->
typeName() <<
"! The problem might be related to incompatible RTTI systems in static and shared libraries!");
270 TEUCHOS_TEST_FOR_EXCEPTION(
data_->
type() !=
typeid(TM), Teuchos::bad_any_cast,
271 "Error, cast to type Data<" << Teuchos::TypeNameTraits<TM>::name() <<
"> failed since the actual underlying type is "
278 TEUCHOS_TEST_FOR_EXCEPTION(!data, std::logic_error,
279 "Error, cast to type Data<" << Teuchos::TypeNameTraits<TM>::name() <<
"> failed but should not have and the actual underlying type is "
281 <<
data_->
typeName() <<
"! The problem might be related to incompatible RTTI systems in static and shared libraries!");
289 TEUCHOS_TEST_FOR_EXCEPTION(!datah, std::logic_error,
290 "Error, cast to type Data<" << Teuchos::TypeNameTraits<TO>::name() <<
"> failed but should not have and the actual underlying type is "
292 <<
datah_->
typeName() <<
"! The problem might be related to incompatible RTTI systems in static and shared libraries!");
Base class for MueLu classes.
Exception throws to report errors in the internal logical of the program.
Base class for factories (e.g., R, P, and A_coarse).
virtual ~DataBase()=default
virtual std::string typeName() const =0
virtual const std::type_info & type() const =0
const std::type_info & type() const
std::string typeName() const
Class that stores all relevant data for a variable.
bool IsRequested() const
Returns true, if data is requested by at least one factory.
DataBase * data_
the data itself
void RemoveKeepFlag(KeepType keep=UserData)
Removes a keep flag to the flag combination.
bool IsRequested(const FactoryBase *reqFactory) const
Returns true, if data is requested by reqFactory.
std::string GetTypeName()
void AddKeepFlag(KeepType keep=UserData)
Adds a keep flag to the flag combination.
bool IsAvailable() const
Returns true if data is available, i.e.
void Request(const FactoryBase *reqFactory)
Request data.
KeepType GetKeepFlag() const
Returns the keep flag combination.
const T & GetData() const
void SetData(const T &entry)
Store data in container class and set the "Available" status true.
bool IsKept(KeepType keep) const
Returns true if at least one keep flag is set.
std::map< const FactoryBase *, int > request_container
const request_container & Requests() const
request_container requests_
requesting factories
bool available_
is data available?
int count_
number of requests by all factories
int NumAllRequests() const
Returns the number of times the data has been requested.
VariableContainer()
Default constructor.
void Release(const FactoryBase *reqFactory)
Release data.
int NumRequests(const FactoryBase *reqFactory) const
Return the number of times the data has been requested by a specific factory.
Namespace for MueLu classes and methods.
@ UserData
User data are always kept. This flag is set automatically when Level::Set("data", data) is used....
static bool check(DataBase *data_, DataBase *&)
static Teuchos::RCP< Operator > & get(DataBase *data_, DataBase *&datah_)
Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > Matrix
Xpetra::Operator< Scalar, LocalOrdinal, GlobalOrdinal, Node > Operator
static T & get(DataBase *data_, DataBase *&)