46 #ifndef MUELU_HIERARCHYHELPERS_DEF_HPP 47 #define MUELU_HIERARCHYHELPERS_DEF_HPP 49 #include <Xpetra_Matrix.hpp> 50 #include <Xpetra_Operator.hpp> 55 #include "MueLu_SmootherFactory.hpp" 56 #include "MueLu_FactoryManager.hpp" 62 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
64 PFact_ (parentFactoryManager->GetFactory(
"P")),
65 RFact_ (parentFactoryManager->GetFactory(
"R")),
66 AcFact_(parentFactoryManager->GetFactory(
"A"))
69 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
76 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
79 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
86 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
89 RCP<Operator> oP = coarseLevel.
Get<RCP<Operator> >(
"P",
PFact_.get());
90 RCP<Matrix> P = rcp_dynamic_cast<Matrix>(oP);
99 RCP<Operator> oR = coarseLevel.
Get<RCP<Operator> >(
"R",
RFact_.get());
100 RCP<Matrix> R = rcp_dynamic_cast<Matrix>(oR);
108 RCP<Operator> oA = coarseLevel.
Get<RCP<Operator> >(
"A",
AcFact_.get());
109 RCP<Matrix> A = rcp_dynamic_cast<Matrix>(oA);
121 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
123 TEUCHOS_TEST_FOR_EXCEPTION(varName !=
"CoarseSolver" && varName !=
"Smoother",
Exceptions::RuntimeError,
"varName should be either \"CoarseSolver\" or \"Smoother\"");
125 if (varName ==
"CoarseSolver") {
129 RCP<const FactoryBase> coarseSolverFactory = parentFactoryManager->GetFactory(
"CoarseSolver");
130 RCP<const SmootherFactory> coarseSmootherFactory = Teuchos::rcp_dynamic_cast<
const SmootherFactory>(coarseSolverFactory);
131 if (coarseSmootherFactory != Teuchos::null) {
132 RCP<SmootherPrototype> preProto;
133 RCP<SmootherPrototype> postProto;
136 if (preProto == postProto)
137 preSmootherFact_ = parentFactoryManager->GetFactory(
"CoarseSolver");
140 if(preProto != Teuchos::null)
141 preSmootherFact_ = parentFactoryManager->GetFactory(
"CoarseSolver");
142 if(postProto != Teuchos::null)
143 postSmootherFact_ = parentFactoryManager->GetFactory(
"CoarseSolver");
147 preSmootherFact_ = parentFactoryManager->GetFactory(
"CoarseSolver");
150 preSmootherFact_ = parentFactoryManager->GetFactory(
"PreSmoother");
151 postSmootherFact_ = parentFactoryManager->GetFactory(
"PostSmoother");
155 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
158 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
160 if (preSmootherFact_ != Teuchos::null)
161 level.
DeclareInput(
"PreSmoother", preSmootherFact_.get());
162 if (postSmootherFact_ != Teuchos::null)
163 level.
DeclareInput(
"PostSmoother", postSmootherFact_.get());
166 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
168 if (preSmootherFact_.is_null() && postSmootherFact_.is_null())
179 if (!preSmootherFact_.is_null()) {
182 RCP<const SmootherFactory> s = rcp_dynamic_cast<
const SmootherFactory>(preSmootherFact_);
184 RCP<SmootherPrototype> pre, post;
193 RCP<SmootherBase> Pre = level.
Get<RCP<SmootherBase> >(
"PreSmoother", preSmootherFact_.get());
202 if (!postSmootherFact_.is_null()) {
205 RCP<const SmootherFactory> s = rcp_dynamic_cast<
const SmootherFactory>(postSmootherFact_);
207 RCP<SmootherPrototype> pre, post;
216 RCP<SmootherBase> Post = level.
Get<RCP<SmootherBase> >(
"PostSmoother", postSmootherFact_.get());
229 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
231 for (ParameterList::ConstIterator it = paramList.begin(); it != paramList.end(); it++) {
232 const std::string& levelName = it->first;
235 if (paramList.isSublist(levelName) && levelName.find(
"level ") == 0 && levelName.size() > 6) {
236 int levelID = strtol(levelName.substr(6).c_str(), 0, 0);
243 RCP<Level> level = H.
GetLevel(levelID);
246 TEUCHOS_TEST_FOR_EXCEPTION(M.is_null(),
Exceptions::InvalidArgument,
"MueLu::Utils::AddNonSerializableDataToHierarchy: cannot get FactoryManager");
249 const ParameterList& levelList = paramList.sublist(levelName);
250 for (ParameterList::ConstIterator it2 = levelList.begin(); it2 != levelList.end(); it2++) {
251 const std::string& name = it2->first;
252 TEUCHOS_TEST_FOR_EXCEPTION(name !=
"A" && name !=
"P" && name !=
"R" &&
253 name !=
"Nullspace" && name !=
"Coordinates" &&
255 "MueLu::Utils::AddNonSerializableDataToHierarchy: parameter list contains unknown data type");
258 level->Set(name, Teuchos::getValue<RCP<Matrix > > (it2->second),
NoFactory::get());
263 else if( name ==
"P" || name ==
"R") {
265 level->Set(name, Teuchos::getValue<RCP<Matrix > > (it2->second), M->GetFactory(name).get());
267 else if (name ==
"Nullspace")
270 level->Set(name, Teuchos::getValue<RCP<MultiVector > >(it2->second),
NoFactory::get());
274 else if(name ==
"Coordinates")
277 level->Set(name, Teuchos::getValue<RCP<Xpetra::MultiVector<double, LocalOrdinal, GlobalOrdinal, Node> > >(it2->second),
NoFactory::get());
280 #ifdef HAVE_MUELU_MATLAB 284 size_t typeNameStart = name.find_first_not_of(
' ');
285 size_t typeNameEnd = name.find(
' ', typeNameStart);
286 std::string typeName = name.substr(typeNameStart, typeNameEnd - typeNameStart);
287 std::transform(typeName.begin(), typeName.end(), typeName.begin(), ::tolower);
289 if(typeName ==
"matrix")
290 level->Set(name, Teuchos::getValue<RCP<Matrix> >(it2->second),
NoFactory::get());
291 else if(typeName ==
"multivector")
292 level->Set(name, Teuchos::getValue<RCP<MultiVector> >(it2->second),
NoFactory::get());
293 else if(typeName ==
"map")
294 level->Set(name, Teuchos::getValue<RCP<Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node> > >(it2->second),
NoFactory::get());
295 else if(typeName ==
"ordinalvector")
296 level->Set(name, Teuchos::getValue<RCP<Xpetra::Vector<LocalOrdinal, LocalOrdinal, GlobalOrdinal, Node> > >(it2->second),
NoFactory::get());
297 else if(typeName ==
"scalar")
298 level->Set(name, Teuchos::getValue<Scalar>(it2->second),
NoFactory::get());
299 else if(typeName ==
"double")
300 level->Set(name, Teuchos::getValue<double>(it2->second),
NoFactory::get());
301 else if(typeName ==
"complex")
302 level->Set(name, Teuchos::getValue<std::complex<double> >(it2->second),
NoFactory::get());
303 else if(typeName ==
"int")
304 level->Set(name, Teuchos::getValue<int>(it2->second),
NoFactory::get());
305 else if(typeName ==
"string")
306 level->Set(name, Teuchos::getValue<std::string>(it2->second),
NoFactory::get());
316 #define MUELU_HIERARCHY_HELPERS_SHORT 317 #endif // MUELU_HIERARCHYHELPERS_DEF_HPP Generic Smoother Factory for generating the smoothers of the MG hierarchy.
TopRAPFactory(RCP< const FactoryManagerBase > parentFactoryManager)
void Build(Level &level) const
Build an object with this factory.
This class specifies the default factory that should generate some data on a Level if the data does n...
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.
RCP< Level > & GetLevel(const int levelID=0)
Retrieve a certain level from hierarchy.
static void AddNonSerializableDataToHierarchy(HierarchyManager &HM, Hierarchy &H, const ParameterList &nonSerialList)
void DeclareInput(Level &fineLevel, Level &coarseLevel) const
Input.
void AddNewLevel()
Add a new level at the end of the hierarchy.
User data are always kept. This flag is set automatically when Level::Set("data", data) is used...
Namespace for MueLu classes and methods.
bool IsParamMuemexVariable(const std::string &name)
static const NoFactory * get()
virtual ~TopSmootherFactory()
RCP< const FactoryBase > PFact_
Class that holds all level-specific information.
Keep data only for this run. Used to keep data useful for Hierarchy::Iterate(). Data will be deleted ...
void RemoveKeepFlag(const std::string &ename, const FactoryBase *factory, KeepType keep=MueLu::All)
RCP< FactoryManagerBase > GetFactoryManager(int levelID) const
void AddKeepFlag(const std::string &ename, const FactoryBase *factory=NoFactory::get(), KeepType keep=MueLu::Keep)
RCP< const FactoryBase > RFact_
void Set(const std::string &ename, const T &entry, const FactoryBase *factory=NoFactory::get())
RCP< const FactoryBase > AcFact_
void Build(Level &fineLevel, Level &coarseLevel) const
Build an object with this factory.
void GetSmootherPrototypes(RCP< SmootherPrototype > &preSmootherPrototype, RCP< SmootherPrototype > &postSmootherPrototype) const
Get smoother prototypes.
Exception throws to report errors in the internal logical of the program.
void DeclareInput(const std::string &ename, const FactoryBase *factory, const FactoryBase *requestedBy=NoFactory::get())
Callback from FactoryBase::CallDeclareInput() and FactoryBase::DeclareInput()
void DeclareInput(Level &level) const
Specifies the data that this class needs, and the factories that generate that data.
Provides methods to build a multigrid hierarchy and apply multigrid cycles.
TopSmootherFactory(RCP< const FactoryManagerBase > parentFactoryManager, const std::string &varName)
Exception throws to report invalid user entry.
static const RCP< const NoFactory > getRCP()
Static Get() functions.
const RCP< const FactoryBase > GetFactory(const std::string &varName) const
Default implementation of FactoryAcceptor::GetFactory()