MueLu Version of the Day
Loading...
Searching...
No Matches
MueLu_TopSmootherFactory_def.hpp
Go to the documentation of this file.
1/*
2 * MueLu_TopSmootherFactory_def.hpp
3 *
4 * Created on: Jan 25, 2016
5 * Author: tawiesn
6 */
7
8#ifndef PACKAGES_MUELU_SRC_MUECENTRAL_MUELU_TOPSMOOTHERFACTORY_DEF_HPP_
9#define PACKAGES_MUELU_SRC_MUECENTRAL_MUELU_TOPSMOOTHERFACTORY_DEF_HPP_
10
11#include "MueLu_ConfigDefs.hpp"
12
13//#include "MueLu_FactoryManager_fwd.hpp"
15//#include "MueLu_HierarchyHelpers_fwd.hpp"
17//#include "MueLu_SmootherBase_fwd.hpp"
18#include "MueLu_SmootherFactory.hpp"
19#include "MueLu_SmootherPrototype.hpp"
20//#include "MueLu_Hierarchy_fwd.hpp"
21//#include "MueLu_HierarchyManager_fwd.hpp"
22
23namespace MueLu {
24 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
25 TopSmootherFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::TopSmootherFactory(RCP<const FactoryManagerBase> parentFactoryManager, const std::string& varName) {
26 TEUCHOS_TEST_FOR_EXCEPTION(varName != "CoarseSolver" && varName != "Smoother", Exceptions::RuntimeError, "varName should be either \"CoarseSolver\" or \"Smoother\"");
27
28 if (varName == "CoarseSolver") {
29 // For coarsest level, we only need one smoother/solver
30 // If a user wants to do something weird there (like, solve coarsest system by using 2 forward
31 // GS and 1 backward GS), one can use MergedSmoother
32 RCP<const FactoryBase> coarseSolverFactory = parentFactoryManager->GetFactory("CoarseSolver");
33 RCP<const SmootherFactory> coarseSmootherFactory = Teuchos::rcp_dynamic_cast<const SmootherFactory>(coarseSolverFactory);
34 if (coarseSmootherFactory != Teuchos::null) {
35 RCP<SmootherPrototype> preProto;
36 RCP<SmootherPrototype> postProto;
37 coarseSmootherFactory->GetSmootherPrototypes(preProto, postProto);
38
39 if (preProto == postProto)
40 preSmootherFact_ = parentFactoryManager->GetFactory("CoarseSolver");
41 else {
42 // check whether pre- and/or post-smoothing is desired on coarsest level
43 if(preProto != Teuchos::null)
44 preSmootherFact_ = parentFactoryManager->GetFactory("CoarseSolver");
45 if(postProto != Teuchos::null)
46 postSmootherFact_ = parentFactoryManager->GetFactory("CoarseSolver");
47 }
48 }
49 else // default handling: get default direct solver as presmoother on coarsest level
50 preSmootherFact_ = parentFactoryManager->GetFactory("CoarseSolver");
51
52 } else {
53 preSmootherFact_ = parentFactoryManager->GetFactory("PreSmoother");
54 postSmootherFact_ = parentFactoryManager->GetFactory("PostSmoother");
55 }
56 }
57
58 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
60
61 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
63 if (preSmootherFact_ != Teuchos::null)
64 level.DeclareInput("PreSmoother", preSmootherFact_.get());
65 if (postSmootherFact_ != Teuchos::null)
66 level.DeclareInput("PostSmoother", postSmootherFact_.get());
67 }
68
69 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
71 if (preSmootherFact_.is_null() && postSmootherFact_.is_null())
72 return;
73
74 // NOTE 1: We need to set at least some keep flag for the smoothers, otherwise it is going to be removed as soon as all requests are released.
75 // We choose to set the Final flag for the data. In addition, we allow this data to be retrieved by only using the name by the means
76 // of using NoFactory. However, any data set with NoFactory gets UserData flag by default. We don't really want that flag, so we remove it.
77
78 // NOTE 2: some smoother factories are tricky (see comments in MueLu::SmootherFactory
79 // Sometimes, we don't know whether the factory is able to generate "PreSmoother" or "PostSmoother"
80 // For the SmootherFactory, however, we are able to check that.
81
82 if (!preSmootherFact_.is_null()) {
83 // Checking for null is not sufficient, as SmootherFactory(null, something) does not generate "PreSmoother"
84 bool isAble = true;
85 RCP<const SmootherFactory> s = rcp_dynamic_cast<const SmootherFactory>(preSmootherFact_);
86 if (!s.is_null()) {
87 RCP<SmootherPrototype> pre, post;
88 s->GetSmootherPrototypes(pre, post);
89 if (pre.is_null())
90 isAble = false;
91 } else {
92 // We assume that if presmoother factory is not SmootherFactory, it *is* able to generate "PreSmoother"
93 }
94
95 if (isAble) {
96 RCP<SmootherBase> Pre = level.Get<RCP<SmootherBase> >("PreSmoother", preSmootherFact_.get());
97
98 level.Set ("PreSmoother", Pre, NoFactory::get());
99
100 level.AddKeepFlag ("PreSmoother", NoFactory::get(), MueLu::Final);
101 level.RemoveKeepFlag("PreSmoother", NoFactory::get(), MueLu::UserData);
102 }
103 }
104
105 if (!postSmootherFact_.is_null()) {
106 // Checking for null is not sufficient, as SmootherFactory(something, null) does not generate "PostSmoother"
107 bool isAble = true;
108 RCP<const SmootherFactory> s = rcp_dynamic_cast<const SmootherFactory>(postSmootherFact_);
109 if (!s.is_null()) {
110 RCP<SmootherPrototype> pre, post;
111 s->GetSmootherPrototypes(pre, post);
112 if (post.is_null())
113 isAble = false;
114 } else {
115 // We assume that if presmoother factory is not SmootherFactory, it *is* able to generate "PreSmoother"
116 }
117
118 if (isAble) {
119 RCP<SmootherBase> Post = level.Get<RCP<SmootherBase> >("PostSmoother", postSmootherFact_.get());
120
121 level.Set ("PostSmoother", Post, NoFactory::get());
122
123 level.AddKeepFlag ("PostSmoother", NoFactory::get(), MueLu::Final);
124 level.RemoveKeepFlag("PostSmoother", NoFactory::get(), MueLu::UserData);
125 }
126 }
127 }
128}
129
130
131#endif /* PACKAGES_MUELU_SRC_MUECENTRAL_MUELU_TOPSMOOTHERFACTORY_DEF_HPP_ */
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 RemoveKeepFlag(const std::string &ename, const FactoryBase *factory, KeepType keep=MueLu::All)
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 Set(const std::string &ename, const T &entry, const FactoryBase *factory=NoFactory::get())
static const NoFactory * get()
TopSmootherFactory(RCP< const FactoryManagerBase > parentFactoryManager, const std::string &varName)
void Build(Level &level) const
Build an object with this factory.
void DeclareInput(Level &level) const
Specifies the data that this class needs, and the factories that generate that data.
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 ...
@ UserData
User data are always kept. This flag is set automatically when Level::Set("data", data) is used....