10#ifndef MUELU_TRILINOSSMOOTHER_DEF_HPP
11#define MUELU_TRILINOSSMOOTHER_DEF_HPP
13#include <Xpetra_Map.hpp>
14#include <Xpetra_Matrix.hpp>
20#include "MueLu_Ifpack2Smoother.hpp"
21#include "MueLu_BelosSmoother.hpp"
22#include "MueLu_StratimikosSmoother.hpp"
27template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
46 ParameterList paramList = paramListIn;
51#if defined(HAVE_MUELU_IFPACK2)
56 else if (!
sTpetra_->constructionSuccessful()) {
64 }
catch (Teuchos::Exceptions::InvalidParameterName& e) {
69#if defined(HAVE_MUELU_EPETRA) && defined(HAVE_MUELU_IFPACK)
75 else if (!
sEpetra_->constructionSuccessful()) {
85#if defined(HAVE_MUELU_BELOS)
90 else if (!
sBelos_->constructionSuccessful()) {
101#if defined(HAVE_MUELU_STRATIMIKOS) && defined(HAVE_MUELU_THYRA)
119 "Unable to construct any smoother."
120 "Please enable (TPETRA and IFPACK2) or (EPETRA and IFPACK) or (BELOS) or (STRATIMIKOS)");
123 "Could not construct any smoother:\n"
124 << (
triedEpetra_ ?
"=> Failed to build an Epetra smoother due to the following exception:\n" :
"=> Epetra and/or Ifpack are not enabled.\n")
126 << (
triedTpetra_ ?
"=> Failed to build a Tpetra smoother due to the following exception:\n" :
"=> Tpetra and/or Ifpack2 are not enabled.\n")
128 << (
triedBelos_ ?
"=> Failed to build a Belos smoother due to the following exception:\n" :
"=> Belos not enabled.\n")
130 << (
triedStratimikos_ ?
"=> Failed to build a Stratimikos smoother due to the following exception:\n" :
"=> Stratimikos not enabled.\n")
136template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
139 if (!sEpetra_.is_null()) sEpetra_->SetFactory(varName, factory);
140 if (!sTpetra_.is_null()) sTpetra_->SetFactory(varName, factory);
141 if (!sBelos_.is_null()) sBelos_->SetFactory(varName, factory);
142 if (!sStratimikos_.is_null()) sStratimikos_->SetFactory(varName, factory);
145template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
147 if (!sBelos_.is_null())
149 else if (!sStratimikos_.is_null())
158 bool useTpetra = (currentLevel.
lib() == Xpetra::UseTpetra);
159 s_ = (useTpetra ? sTpetra_ : sEpetra_);
162#if not defined(HAVE_MUELU_IFPACK2)
164 "Error: running in Tpetra mode, but MueLu with Ifpack2 was disabled during the configure stage.\n"
165 "Please make sure that:\n"
166 " - Ifpack2 is enabled (Trilinos_ENABLE_Ifpack2=ON),\n"
167 " - Ifpack2 is available for MueLu to use (MueLu_ENABLE_Ifpack2=ON)\n");
170 this->GetOStream(
Errors) <<
"Tpetra mode was disabled due to an error:\n"
171 << errorTpetra_ << std::endl;
175#if not defined(HAVE_MUELU_IFPACK)
177 "Error: running in Epetra mode, but MueLu with Ifpack was disabled during the configure stage.\n"
178 "Please make sure that:\n"
179 " - Ifpack is enabled (you can do that with Trilinos_ENABLE_Ifpack=ON),\n"
180 " - Ifpack is available for MueLu to use (MueLu_ENABLE_Ifpack=ON)\n");
183 this->GetOStream(
Errors) <<
"Epetra mode was disabled due to an error:\n"
184 << errorEpetra_ << std::endl;
188 "Smoother for " << (useTpetra ?
"Tpetra" :
"Epetra") <<
" was not constructed");
192 s_->DeclareInput(currentLevel);
195template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
198 this->GetOStream(
Warnings0) <<
"MueLu::TrilinosSmoother::Setup(): Setup() has already been called" << std::endl;
200 int oldRank = s_->SetProcRankVerbose(this->GetProcRankVerbose());
202 s_->Setup(currentLevel);
204 s_->SetProcRankVerbose(oldRank);
208 this->SetParameterList(s_->GetParameterList());
211template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
215 s_->Apply(X, B, InitialGuessIsZero);
218template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
219RCP<MueLu::SmootherPrototype<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
221 RCP<TrilinosSmoother> newSmoo = rcp(
new TrilinosSmoother(type_, this->GetParameterList(), overlap_));
225 if (!sEpetra_.is_null())
226 newSmoo->sEpetra_ = sEpetra_->Copy();
227 if (!sTpetra_.is_null())
228 newSmoo->sTpetra_ = sTpetra_->Copy();
229 if (!sBelos_.is_null())
230 newSmoo->sBelos_ = sBelos_->Copy();
231 if (!sStratimikos_.is_null())
232 newSmoo->sStratimikos_ = sStratimikos_->Copy();
235 if (s_.get() == sBelos_.get())
236 newSmoo->s_ = newSmoo->sBelos_;
237 else if (s_.get() == sStratimikos_.get())
238 newSmoo->s_ = newSmoo->sStratimikos_;
239 else if (s_.get() == sTpetra_.get())
240 newSmoo->s_ = newSmoo->sTpetra_;
242 newSmoo->s_ = newSmoo->sEpetra_;
243 newSmoo->SetParameterList(this->GetParameterList());
248template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
250 if (type ==
"RELAXATION") {
251 return "point relaxation stand-alone";
253 if (type ==
"CHEBYSHEV") {
256 if (type ==
"ILUT") {
259 if (type ==
"RILUK") {
265 if (type ==
"Amesos") {
273 if (type ==
"LINESMOOTHING_BLOCKRELAXATION") {
274 return "LINESMOOTHING_BLOCKRELAXATION";
276 if (type ==
"LINESMOOTHING_BLOCK RELAXATION") {
277 return "LINESMOOTHING_BLOCKRELAXATION";
279 if (type ==
"LINESMOOTHING_BLOCK_RELAXATION") {
280 return "LINESMOOTHING_BLOCKRELAXATION";
282 if (type ==
"LINESMOOTHING_BANDEDRELAXATION") {
283 return "LINESMOOTHING_BLOCKRELAXATION";
285 if (type ==
"LINESMOOTHING_BANDED RELAXATION") {
286 return "LINESMOOTHING_BLOCKRELAXATION";
288 if (type ==
"LINESMOOTHING_BANDED_RELAXATION") {
289 return "LINESMOOTHING_BLOCKRELAXATION";
291 if (type ==
"LINESMOOTHING_TRIDIRELAXATION") {
292 return "LINESMOOTHING_BLOCKRELAXATION";
294 if (type ==
"LINESMOOTHING_TRIDI RELAXATION") {
295 return "LINESMOOTHING_BLOCKRELAXATION";
297 if (type ==
"LINESMOOTHING_TRIDI_RELAXATION") {
298 return "LINESMOOTHING_BLOCKRELAXATION";
300 if (type ==
"LINESMOOTHING_TRIDIAGONALRELAXATION") {
301 return "LINESMOOTHING_BLOCKRELAXATION";
303 if (type ==
"LINESMOOTHING_TRIDIAGONAL RELAXATION") {
304 return "LINESMOOTHING_BLOCKRELAXATION";
306 if (type ==
"LINESMOOTHING_TRIDIAGONAL_RELAXATION") {
307 return "LINESMOOTHING_BLOCKRELAXATION";
309 if (type ==
"AGGREGATE") {
312 if (type ==
"BLOCK_RELAXATION" ||
313 type ==
"BLOCK RELAXATION" ||
314 type ==
"BLOCKRELAXATION" ||
316 type ==
"BANDED_RELAXATION" ||
317 type ==
"BANDED RELAXATION" ||
318 type ==
"BANDEDRELAXATION" ||
320 type ==
"TRIDI_RELAXATION" ||
321 type ==
"TRIDI RELAXATION" ||
322 type ==
"TRIDIRELAXATION" ||
323 type ==
"TRIDIAGONAL_RELAXATION" ||
324 type ==
"TRIDIAGONAL RELAXATION" ||
325 type ==
"TRIDIAGONALRELAXATION") {
326 return "block relaxation stand-alone";
329 TEUCHOS_TEST_FOR_EXCEPTION(
true,
Exceptions::RuntimeError,
"Cannot convert Ifpack2 preconditioner name to Ifpack: unknown type: \"" + type +
"\"");
332template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
334 Teuchos::ParameterList ifpack1List = ifpack2List;
336 if (ifpack2List.isParameter(
"relaxation: type") && ifpack2List.get<std::string>(
"relaxation: type") ==
"Symmetric Gauss-Seidel")
337 ifpack1List.set(
"relaxation: type",
"symmetric Gauss-Seidel");
339 if (ifpack2List.isParameter(
"fact: iluk level-of-fill")) {
340 ifpack1List.remove(
"fact: iluk level-of-fill");
341 ifpack1List.set(
"fact: level-of-fill", ifpack2List.get<
int>(
"fact: iluk level-of-fill"));
347template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
349 std::ostringstream out;
350 if (s_ != Teuchos::null) {
351 out << s_->description();
354 out <<
"{type = " << type_ <<
"}";
359template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
364 out0 <<
"Prec. type: " << type_ << std::endl;
367 out0 <<
"PrecType: " << type_ << std::endl;
368 out0 <<
"Parameter list: " << std::endl;
369 Teuchos::OSTab tab2(out);
370 out << this->GetParameterList();
371 out0 <<
"Overlap: " << overlap_ << std::endl;
374 if (verbLevel &
Debug) {
377 <<
"Epetra PrecType: " << Ifpack2ToIfpack1Type(type_) << std::endl
378 <<
"Epetra Parameter list: " << std::endl;
379 Teuchos::OSTab tab2(out);
380 out << Ifpack2ToIfpack1Param(this->GetParameterList());
#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.
Xpetra::UnderlyingLib lib()
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.
RCP< SmootherPrototype > sEpetra_
Smoother.
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_
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)