46 #ifndef MUELU_SMOOTHERFACTORY_DEF_HPP 47 #define MUELU_SMOOTHERFACTORY_DEF_HPP 53 #include "MueLu_SmootherPrototype.hpp" 54 #include "MueLu_Ifpack2Smoother.hpp" 59 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
61 SetSmootherPrototypes(preAndPostSmootherPrototype);
64 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
66 RCP<SmootherPrototype> postSmootherPrototype) {
67 SetSmootherPrototypes(preSmootherPrototype, postSmootherPrototype);
70 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
72 preSmootherPrototype_ = postSmootherPrototype_ = preAndPostSmootherPrototype;
76 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
78 RCP<SmootherPrototype> postSmootherPrototype) {
79 preSmootherPrototype_ = preSmootherPrototype;
80 postSmootherPrototype_ = postSmootherPrototype;
84 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
86 RCP<ParameterList> validParamList = rcp(
new ParameterList());
88 validParamList->set<
bool>(
"keep smoother data",
false,
"Keep constructed smoothers for later reuse");
90 validParamList->set< RCP<SmootherPrototype> >(
"PreSmoother data", null,
"Pre-smoother data for reuse");
91 validParamList->set< RCP<SmootherPrototype> >(
"PostSmoother data", null,
"Post-smoother data for reuse");
93 return validParamList;
96 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
98 TEUCHOS_TEST_FOR_EXCEPTION(preSmootherPrototype_ != Teuchos::null && preSmootherPrototype_->IsSetup() ==
true,
100 TEUCHOS_TEST_FOR_EXCEPTION(postSmootherPrototype_ != Teuchos::null && postSmootherPrototype_->IsSetup() ==
true,
104 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
106 RCP<SmootherPrototype>& postSmootherPrototype)
const {
107 preSmootherPrototype = preSmootherPrototype_;
108 postSmootherPrototype = postSmootherPrototype_;
111 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
113 if (preSmootherPrototype_ != Teuchos::null)
114 preSmootherPrototype_->DeclareInput(currentLevel);
116 if ((postSmootherPrototype_ != Teuchos::null) && (preSmootherPrototype_ != postSmootherPrototype_))
117 postSmootherPrototype_->DeclareInput(currentLevel);
120 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
122 return BuildSmoother(currentLevel,
BOTH);
125 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
147 const Teuchos::ParameterList& pL = GetParameterList();
149 RCP<SmootherPrototype> preSmoother, postSmoother;
150 ParameterList preSmootherParams, postSmootherParams;
152 if ((preOrPost &
PRE) && !preSmootherPrototype_.is_null()) {
154 if (currentLevel.
IsAvailable(
"PreSmoother data",
this))
155 preSmoother = currentLevel.
Get<RCP<SmootherPrototype> >(
"PreSmoother data",
this);
157 preSmoother = preSmootherPrototype_->Copy();
160 if (!currentLevel.
GetComm().is_null())
161 oldRank = preSmoother->SetProcRankVerbose(currentLevel.
GetComm()->getRank());
163 preSmoother->Setup(currentLevel);
164 preSmootherParams = preSmoother->GetParameterList();
167 preSmoother->SetProcRankVerbose(oldRank);
169 currentLevel.
Set<RCP<SmootherBase> >(
"PreSmoother", preSmoother,
this);
171 if (pL.get<
bool>(
"keep smoother data"))
172 Set(currentLevel,
"PreSmoother data", preSmoother);
175 if ((preOrPost &
POST) && !postSmootherPrototype_.is_null()) {
176 if (preOrPost ==
BOTH && preSmootherPrototype_ == postSmootherPrototype_) {
179 postSmoother = preSmoother;
207 if (currentLevel.
IsAvailable(
"PostSmoother data",
this)) {
208 postSmoother = currentLevel.
Get<RCP<SmootherPrototype> >(
"PostSmoother data",
this);
213 postSmoother = postSmootherPrototype_->Copy();
217 if (!currentLevel.
GetComm().is_null())
218 oldRank = postSmoother->SetProcRankVerbose(GetProcRankVerbose());
220 postSmoother->Setup(currentLevel);
221 postSmootherParams = postSmoother->GetParameterList();
224 postSmoother->SetProcRankVerbose(oldRank);
227 currentLevel.
Set<RCP<SmootherBase> >(
"PostSmoother", postSmoother,
this);
229 if (pL.get<
bool>(
"keep smoother data"))
230 Set(currentLevel,
"PostSmoother data", postSmoother);
233 ParameterList& paramList =
const_cast<ParameterList&
>(this->GetParameterList());
234 if (postSmoother == preSmoother && !preSmoother.is_null()) {
235 paramList.sublist(
"smoother",
false) = preSmoother->GetParameterList();
238 if (!preSmoother.is_null())
239 paramList.sublist(
"presmoother",
false) = preSmootherParams;
241 if (!postSmoother.is_null())
242 paramList.sublist(
"postsmoother",
false) = postSmootherParams;
247 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
249 std::ostringstream out;
251 std::string preStr = (preSmootherPrototype_ == Teuchos::null) ?
"null" : preSmootherPrototype_->description();
252 std::string postStr = (preSmootherPrototype_ == postSmootherPrototype_) ?
"pre" : ( (postSmootherPrototype_ == Teuchos::null) ?
"null" : postSmootherPrototype_->description() );
253 out <<
"{pre = " << preStr <<
", post = "<< postStr <<
"}";
257 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
262 out0 <<
"PreSmoother : ";
263 if (preSmootherPrototype_.is_null()) {
264 out0 <<
"null" << std::endl;
266 Teuchos::OSTab tab2(out);
267 preSmootherPrototype_->describe(out, verbLevel);
270 out0 <<
"PostSmoother: ";
271 if (postSmootherPrototype_ == preSmootherPrototype_) { out0 <<
"same as PreSmoother" << std::endl; }
272 else if (postSmootherPrototype_ == Teuchos::null) { out0 <<
"null" << std::endl; }
274 Teuchos::OSTab tab2(out);
275 postSmootherPrototype_->describe(out, verbLevel);
276 out0 <<
"PostSmoother is different than PreSmoother (not the same object)" << std::endl;
280 if (verbLevel &
Debug) {
281 if (preSmootherPrototype_ != Teuchos::null || postSmootherPrototype_ != Teuchos::null) { out0 <<
"-" << std::endl; }
282 if (preSmootherPrototype_ != Teuchos::null) { out0 <<
"RCP<preSmootherPrototype_> : " << preSmootherPrototype_ << std::endl; }
283 if (postSmootherPrototype_ != Teuchos::null) { out0 <<
"RCP<postSmootherPrototype_>: " << postSmootherPrototype_ << std::endl; }
296 #endif // MUELU_SMOOTHERFACTORY_DEF_HPP SmootherFactory(RCP< SmootherPrototype > preAndPostSmootherPrototype=Teuchos::null)
Constructor.
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.
Print additional debugging information.
void CheckPrototypes() const
Namespace for MueLu classes and methods.
void describe(Teuchos::FancyOStream &out, const VerbLevel verbLevel=Default) const
void DeclareInput(Level ¤tLevel) const
Specifies the data that this class needs, and the factories that generate that data.
void SetSmootherPrototypes(RCP< SmootherPrototype > preAndPostSmootherPrototype)
Set smoother prototypes.
Class that holds all level-specific information.
RCP< const Teuchos::Comm< int > > GetComm() const
#define MUELU_DESCRIBE
Helper macro for implementing Describable::describe() for BaseClass objects.
void Set(const std::string &ename, const T &entry, const FactoryBase *factory=NoFactory::get())
RCP< const ParameterList > GetValidParameterList() const
Input.
void Build(Level ¤tLevel) const
Creates pre and post smoothers.
void GetSmootherPrototypes(RCP< SmootherPrototype > &preSmootherPrototype, RCP< SmootherPrototype > &postSmootherPrototype) const
Get smoother prototypes.
bool IsAvailable(const std::string &ename, const FactoryBase *factory=NoFactory::get()) const
Test whether a need's value has been saved.
Exception throws to report errors in the internal logical of the program.
void BuildSmoother(Level ¤tLevel, const PreOrPost preOrPost=BOTH) const
std::string description() const
Return a simple one-line description of this object.
virtual std::string description() const
Return a simple one-line description of this object.