10#ifndef MUELU_TRILINOSSMOOTHER_DEF_HPP
11#define MUELU_TRILINOSSMOOTHER_DEF_HPP
13#include <Xpetra_Map.hpp>
14#include <Xpetra_Matrix.hpp>
19#include "MueLu_Ifpack2Smoother.hpp"
20#include "MueLu_BelosSmoother.hpp"
21#include "MueLu_StratimikosSmoother.hpp"
26template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
44 ParameterList paramList = paramListIn;
53 else if (!
sTpetra_->constructionSuccessful()) {
61 }
catch (Teuchos::Exceptions::InvalidParameterName& e) {
65#if defined(HAVE_MUELU_BELOS)
70 else if (!
sBelos_->constructionSuccessful()) {
81#if defined(HAVE_MUELU_STRATIMIKOS) && defined(HAVE_MUELU_THYRA)
99 "Unable to construct any smoother.");
102 "Could not construct any smoother:\n"
103 << (
triedTpetra_ ?
"=> Failed to build a Tpetra smoother due to the following exception:\n" :
"=> Tpetra and/or Ifpack2 are not enabled.\n")
105 << (
triedBelos_ ?
"=> Failed to build a Belos smoother due to the following exception:\n" :
"=> Belos not enabled.\n")
107 << (
triedStratimikos_ ?
"=> Failed to build a Stratimikos smoother due to the following exception:\n" :
"=> Stratimikos not enabled.\n")
113template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
116 if (!sTpetra_.is_null()) sTpetra_->SetFactory(varName, factory);
117 if (!sBelos_.is_null()) sBelos_->SetFactory(varName, factory);
118 if (!sStratimikos_.is_null()) sStratimikos_->SetFactory(varName, factory);
121template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
123 if (!sBelos_.is_null())
125 else if (!sStratimikos_.is_null())
132 this->GetOStream(
Errors) <<
"Belos was disabled due to an error:\n"
133 << errorBelos_ << std::endl;
134 if (triedStratimikos_)
135 this->GetOStream(
Errors) <<
"Stratimikos was disabled due to an error:\n"
136 << errorStratimikos_ << std::endl;
138 this->GetOStream(
Errors) <<
"Tpetra mode was disabled due to an error:\n"
139 << errorTpetra_ << std::endl;
141 "Smoother was not constructed");
144 s_->DeclareInput(currentLevel);
147template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
150 this->GetOStream(
Warnings0) <<
"MueLu::TrilinosSmoother::Setup(): Setup() has already been called" << std::endl;
152 int oldRank = s_->SetProcRankVerbose(this->GetProcRankVerbose());
154 s_->Setup(currentLevel);
156 s_->SetProcRankVerbose(oldRank);
160 this->SetParameterList(s_->GetParameterList());
163template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
167 s_->Apply(X, B, InitialGuessIsZero);
170template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
171RCP<MueLu::SmootherPrototype<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
173 RCP<TrilinosSmoother> newSmoo = rcp(
new TrilinosSmoother(type_, this->GetParameterList(), overlap_));
177 if (!sTpetra_.is_null())
178 newSmoo->sTpetra_ = sTpetra_->Copy();
179 if (!sBelos_.is_null())
180 newSmoo->sBelos_ = sBelos_->Copy();
181 if (!sStratimikos_.is_null())
182 newSmoo->sStratimikos_ = sStratimikos_->Copy();
185 if (s_.get() == sBelos_.get())
186 newSmoo->s_ = newSmoo->sBelos_;
187 else if (s_.get() == sStratimikos_.get())
188 newSmoo->s_ = newSmoo->sStratimikos_;
190 newSmoo->s_ = newSmoo->sTpetra_;
192 newSmoo->SetParameterList(this->GetParameterList());
197template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
199 if (type ==
"RELAXATION") {
200 return "point relaxation stand-alone";
202 if (type ==
"CHEBYSHEV") {
205 if (type ==
"ILUT") {
208 if (type ==
"RILUK") {
214 if (type ==
"Amesos") {
222 if (type ==
"LINESMOOTHING_BLOCKRELAXATION") {
223 return "LINESMOOTHING_BLOCKRELAXATION";
225 if (type ==
"LINESMOOTHING_BLOCK RELAXATION") {
226 return "LINESMOOTHING_BLOCKRELAXATION";
228 if (type ==
"LINESMOOTHING_BLOCK_RELAXATION") {
229 return "LINESMOOTHING_BLOCKRELAXATION";
231 if (type ==
"LINESMOOTHING_BANDEDRELAXATION") {
232 return "LINESMOOTHING_BLOCKRELAXATION";
234 if (type ==
"LINESMOOTHING_BANDED RELAXATION") {
235 return "LINESMOOTHING_BLOCKRELAXATION";
237 if (type ==
"LINESMOOTHING_BANDED_RELAXATION") {
238 return "LINESMOOTHING_BLOCKRELAXATION";
240 if (type ==
"LINESMOOTHING_TRIDIRELAXATION") {
241 return "LINESMOOTHING_BLOCKRELAXATION";
243 if (type ==
"LINESMOOTHING_TRIDI RELAXATION") {
244 return "LINESMOOTHING_BLOCKRELAXATION";
246 if (type ==
"LINESMOOTHING_TRIDI_RELAXATION") {
247 return "LINESMOOTHING_BLOCKRELAXATION";
249 if (type ==
"LINESMOOTHING_TRIDIAGONALRELAXATION") {
250 return "LINESMOOTHING_BLOCKRELAXATION";
252 if (type ==
"LINESMOOTHING_TRIDIAGONAL RELAXATION") {
253 return "LINESMOOTHING_BLOCKRELAXATION";
255 if (type ==
"LINESMOOTHING_TRIDIAGONAL_RELAXATION") {
256 return "LINESMOOTHING_BLOCKRELAXATION";
258 if (type ==
"AGGREGATE") {
261 if (type ==
"BLOCK_RELAXATION" ||
262 type ==
"BLOCK RELAXATION" ||
263 type ==
"BLOCKRELAXATION" ||
265 type ==
"BANDED_RELAXATION" ||
266 type ==
"BANDED RELAXATION" ||
267 type ==
"BANDEDRELAXATION" ||
269 type ==
"TRIDI_RELAXATION" ||
270 type ==
"TRIDI RELAXATION" ||
271 type ==
"TRIDIRELAXATION" ||
272 type ==
"TRIDIAGONAL_RELAXATION" ||
273 type ==
"TRIDIAGONAL RELAXATION" ||
274 type ==
"TRIDIAGONALRELAXATION") {
275 return "block relaxation stand-alone";
278 TEUCHOS_TEST_FOR_EXCEPTION(
true,
Exceptions::RuntimeError,
"Cannot convert Ifpack2 preconditioner name to Ifpack: unknown type: \"" + type +
"\"");
281template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
283 Teuchos::ParameterList ifpack1List = ifpack2List;
285 if (ifpack2List.isParameter(
"relaxation: type") && ifpack2List.get<std::string>(
"relaxation: type") ==
"Symmetric Gauss-Seidel")
286 ifpack1List.set(
"relaxation: type",
"symmetric Gauss-Seidel");
288 if (ifpack2List.isParameter(
"fact: iluk level-of-fill")) {
289 ifpack1List.remove(
"fact: iluk level-of-fill");
290 ifpack1List.set(
"fact: level-of-fill", ifpack2List.get<
int>(
"fact: iluk level-of-fill"));
296template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
298 std::ostringstream out;
299 if (s_ != Teuchos::null) {
300 out << s_->description();
303 out <<
"{type = " << type_ <<
"}";
308template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
313 out0 <<
"Prec. type: " << type_ << std::endl;
316 out0 <<
"PrecType: " << type_ << std::endl;
317 out0 <<
"Parameter list: " << std::endl;
318 Teuchos::OSTab tab2(out);
319 out << this->GetParameterList();
320 out0 <<
"Overlap: " << overlap_ << std::endl;
323 if (verbLevel &
Debug) {
#define MUELU_DESCRIBE
Helper macro for implementing Describable::describe() for BaseClass objects.
Class that encapsulates Belos smoothers.
virtual std::string description() const
Return a simple one-line description of this object.
Exception indicating invalid cast attempted.
Exception throws to report errors in the internal logical of the program.
Class that encapsulates Ifpack2 smoothers.
Class that holds all level-specific information.
virtual void SetParameterList(const Teuchos::ParameterList ¶mList)
Set parameters from a parameter list and return with default values.
bool IsSetup() const
Get the state of a smoother prototype.
Class that encapsulates external library smoothers.
RCP< SmootherPrototype > Copy() const
When this prototype is cloned using Copy(), the clone is an Ifpack or an Ifpack2 smoother.
void Setup(Level ¤tLevel)
TrilinosSmoother cannot be turned into a smoother using Setup(). Setup() always returns a RuntimeErro...
LO overlap_
overlap when using the smoother in additive Schwarz mode
static Teuchos::ParameterList Ifpack2ToIfpack1Param(const Teuchos::ParameterList &ifpack2List)
Convert an Ifpack2 parameter list to Ifpack.
static std::string Ifpack2ToIfpack1Type(const std::string &type)
Convert an Ifpack2 preconditioner name to Ifpack.
std::string type_
ifpack1/2-specific key phrase that denote smoother type
RCP< SmootherPrototype > sBelos_
friend class TrilinosSmoother
Friend declaration required for clone() functionality.
std::string errorStratimikos_
void DeclareInput(Level ¤tLevel) const
Input.
void SetFactory(const std::string &varName, const RCP< const FactoryBase > &factory)
Custom SetFactory.
RCP< SmootherPrototype > sStratimikos_
void Apply(MultiVector &X, const MultiVector &B, bool InitialGuessIsZero=false) const
TrilinosSmoother cannot be applied. Apply() always returns a RuntimeError exception.
void print(Teuchos::FancyOStream &out, const VerbLevel verbLevel=Default) const
Print the object with some verbosity level to an FancyOStream object.
std::string description() const
Return a simple one-line description of this object.
RCP< SmootherPrototype > sTpetra_
Smoother.
Namespace for MueLu classes and methods.
@ Warnings0
Important warning messages (one line)
@ Debug
Print additional debugging information.
@ Parameters0
Print class parameters.
@ Parameters1
Print class parameters (more parameters, more verbose)