46 #ifndef MUELU_TRILINOSSMOOTHER_DEF_HPP 47 #define MUELU_TRILINOSSMOOTHER_DEF_HPP 49 #include <Xpetra_Map.hpp> 50 #include <Xpetra_Matrix.hpp> 56 #include "MueLu_Ifpack2Smoother.hpp" 57 #include "MueLu_BelosSmoother.hpp" 58 #include "MueLu_StratimikosSmoother.hpp" 63 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
65 : type_(type), overlap_(overlap)
82 ParameterList paramList = paramListIn;
88 #if defined(HAVE_MUELU_TPETRA) && defined(HAVE_MUELU_IFPACK2) 93 else if (!
sTpetra_->constructionSuccessful()) {
101 }
catch (Teuchos::Exceptions::InvalidParameterName& e) {
106 #if defined(HAVE_MUELU_EPETRA) && defined(HAVE_MUELU_IFPACK) 112 else if (!
sEpetra_->constructionSuccessful()) {
122 #if defined(HAVE_MUELU_BELOS) 126 errorBelos_ =
"Unable to construct Belos smoother";
127 else if (!
sBelos_->constructionSuccessful()) {
138 #if defined(HAVE_MUELU_STRATIMIKOS) && defined(HAVE_MUELU_TPETRA) && defined(HAVE_MUELU_THYRA) 156 "Please enable (TPETRA and IFPACK2) or (EPETRA and IFPACK) or (BELOS) or (STRATIMIKOS)");
159 "Could not construct any smoother:\n" 160 << (
triedEpetra_ ?
"=> Failed to build an Epetra smoother due to the following exception:\n" :
"=> Epetra and/or Ifpack are not enabled.\n")
162 << (
triedTpetra_ ?
"=> Failed to build a Tpetra smoother due to the following exception:\n" :
"=> Tpetra and/or Ifpack2 are not enabled.\n")
164 << (
triedBelos_ ?
"=> Failed to build a Belos smoother due to the following exception:\n" :
"=> Belos not enabled.\n")
166 << (
triedStratimikos_ ?
"=> Failed to build a Stratimikos smoother due to the following exception:\n" :
"=> Stratimikos not enabled.\n")
172 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
175 if (!sEpetra_.is_null()) sEpetra_->SetFactory(varName, factory);
176 if (!sTpetra_.is_null()) sTpetra_->SetFactory(varName, factory);
177 if (!sBelos_.is_null()) sBelos_->SetFactory(varName, factory);
178 if (!sStratimikos_.is_null()) sStratimikos_->SetFactory(varName, factory);
181 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
183 if (!sBelos_.is_null())
185 else if (!sStratimikos_.is_null())
194 bool useTpetra = (currentLevel.
lib() == Xpetra::UseTpetra);
195 s_ = (useTpetra ? sTpetra_ : sEpetra_);
198 #if not defined(HAVE_MUELU_IFPACK2) 200 "Error: running in Tpetra mode, but MueLu with Ifpack2 was disabled during the configure stage.\n" 201 "Please make sure that:\n" 202 " - Ifpack2 is enabled (Trilinos_ENABLE_Ifpack2=ON),\n" 203 " - Ifpack2 is available for MueLu to use (MueLu_ENABLE_Ifpack2=ON)\n");
206 this->GetOStream(
Errors) <<
"Tpetra mode was disabled due to an error:\n" << errorTpetra_ << std::endl;
210 #if not defined(HAVE_MUELU_IFPACK) 212 "Error: running in Epetra mode, but MueLu with Ifpack was disabled during the configure stage.\n" 213 "Please make sure that:\n" 214 " - Ifpack is enabled (you can do that with Trilinos_ENABLE_Ifpack=ON),\n" 215 " - Ifpack is available for MueLu to use (MueLu_ENABLE_Ifpack=ON)\n");
218 this->GetOStream(
Errors) <<
"Epetra mode was disabled due to an error:\n" << errorEpetra_ << std::endl;
222 "Smoother for " << (useTpetra ?
"Tpetra" :
"Epetra") <<
" was not constructed");
226 s_->DeclareInput(currentLevel);
229 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
232 this->GetOStream(
Warnings0) <<
"MueLu::TrilinosSmoother::Setup(): Setup() has already been called" << std::endl;
234 int oldRank = s_->SetProcRankVerbose(this->GetProcRankVerbose());
236 s_->Setup(currentLevel);
238 s_->SetProcRankVerbose(oldRank);
242 this->SetParameterList(s_->GetParameterList());
245 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
249 s_->Apply(X, B, InitialGuessIsZero);
252 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
253 RCP<MueLu::SmootherPrototype<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
255 RCP<TrilinosSmoother> newSmoo = rcp(
new TrilinosSmoother(type_, this->GetParameterList(), overlap_));
259 if (!sEpetra_.is_null())
260 newSmoo->sEpetra_ = sEpetra_->Copy();
261 if (!sTpetra_.is_null())
262 newSmoo->sTpetra_ = sTpetra_->Copy();
263 if (!sBelos_.is_null())
264 newSmoo->sBelos_ = sBelos_->Copy();
265 if (!sStratimikos_.is_null())
266 newSmoo->sStratimikos_ = sStratimikos_->Copy();
269 if (s_.get() == sBelos_.get())
270 newSmoo->s_ = newSmoo->sBelos_;
271 else if (s_.get() == sStratimikos_.get())
272 newSmoo->s_ = newSmoo->sStratimikos_;
273 else if (s_.get() == sTpetra_.get())
274 newSmoo->s_ = newSmoo->sTpetra_;
276 newSmoo->s_ = newSmoo->sEpetra_;
277 newSmoo->SetParameterList(this->GetParameterList());
282 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
284 if (type ==
"RELAXATION") {
return "point relaxation stand-alone"; }
285 if (type ==
"CHEBYSHEV") {
return "Chebyshev"; }
286 if (type ==
"ILUT") {
return "ILUT"; }
287 if (type ==
"RILUK") {
return "ILU"; }
288 if (type ==
"ILU") {
return "ILU"; }
289 if (type ==
"Amesos") {
return "Amesos"; }
295 if (type ==
"LINESMOOTHING_BLOCKRELAXATION") {
return "LINESMOOTHING_BLOCKRELAXATION"; }
296 if (type ==
"LINESMOOTHING_BLOCK RELAXATION") {
return "LINESMOOTHING_BLOCKRELAXATION"; }
297 if (type ==
"LINESMOOTHING_BLOCK_RELAXATION") {
return "LINESMOOTHING_BLOCKRELAXATION"; }
298 if (type ==
"LINESMOOTHING_BANDEDRELAXATION") {
return "LINESMOOTHING_BLOCKRELAXATION"; }
299 if (type ==
"LINESMOOTHING_BANDED RELAXATION") {
return "LINESMOOTHING_BLOCKRELAXATION"; }
300 if (type ==
"LINESMOOTHING_BANDED_RELAXATION") {
return "LINESMOOTHING_BLOCKRELAXATION"; }
301 if (type ==
"LINESMOOTHING_TRIDIRELAXATION") {
return "LINESMOOTHING_BLOCKRELAXATION"; }
302 if (type ==
"LINESMOOTHING_TRIDI RELAXATION") {
return "LINESMOOTHING_BLOCKRELAXATION"; }
303 if (type ==
"LINESMOOTHING_TRIDI_RELAXATION") {
return "LINESMOOTHING_BLOCKRELAXATION"; }
304 if (type ==
"LINESMOOTHING_TRIDIAGONALRELAXATION") {
return "LINESMOOTHING_BLOCKRELAXATION"; }
305 if (type ==
"LINESMOOTHING_TRIDIAGONAL RELAXATION") {
return "LINESMOOTHING_BLOCKRELAXATION"; }
306 if (type ==
"LINESMOOTHING_TRIDIAGONAL_RELAXATION") {
return "LINESMOOTHING_BLOCKRELAXATION"; }
307 if (type ==
"AGGREGATE") {
return "AGGREGATE"; }
308 if(type ==
"BLOCK_RELAXATION" ||
309 type ==
"BLOCK RELAXATION" ||
310 type ==
"BLOCKRELAXATION" ||
312 type ==
"BANDED_RELAXATION" ||
313 type ==
"BANDED RELAXATION" ||
314 type ==
"BANDEDRELAXATION" ||
316 type ==
"TRIDI_RELAXATION" ||
317 type ==
"TRIDI RELAXATION" ||
318 type ==
"TRIDIRELAXATION" ||
319 type ==
"TRIDIAGONAL_RELAXATION" ||
320 type ==
"TRIDIAGONAL RELAXATION" ||
321 type ==
"TRIDIAGONALRELAXATION") {
322 return "block relaxation stand-alone";
325 TEUCHOS_TEST_FOR_EXCEPTION(
true,
Exceptions::RuntimeError,
"Cannot convert Ifpack2 preconditioner name to Ifpack: unknown type: \"" + type +
"\"");
328 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
330 Teuchos::ParameterList ifpack1List = ifpack2List;
332 if (ifpack2List.isParameter(
"relaxation: type") && ifpack2List.get<std::string>(
"relaxation: type") ==
"Symmetric Gauss-Seidel")
333 ifpack1List.set(
"relaxation: type",
"symmetric Gauss-Seidel");
335 if (ifpack2List.isParameter(
"fact: iluk level-of-fill")) {
336 ifpack1List.remove(
"fact: iluk level-of-fill");
337 ifpack1List.set(
"fact: level-of-fill", ifpack2List.get<
int>(
"fact: iluk level-of-fill"));
343 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
345 std::ostringstream out;
346 if (s_ != Teuchos::null) {
347 out << s_->description();
350 out <<
"{type = " << type_ <<
"}";
355 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
360 out0 <<
"Prec. type: " << type_ << std::endl;
363 out0 <<
"PrecType: " << type_ << std::endl;
364 out0 <<
"Parameter list: " << std::endl;
365 Teuchos::OSTab tab2(out);
366 out << this->GetParameterList();
367 out0 <<
"Overlap: " << overlap_ << std::endl;
370 if (verbLevel &
Debug) {
373 <<
"Epetra PrecType: " << Ifpack2ToIfpack1Type(type_) << std::endl
374 <<
"Epetra Parameter list: " << std::endl;
375 Teuchos::OSTab tab2(out);
376 out << Ifpack2ToIfpack1Param(this->GetParameterList());;
382 #endif // MUELU_TRILINOSSMOOTHER_DEF_HPP Important warning messages (one line)
Exception indicating invalid cast attempted.
std::string errorStratimikos_
std::string toString(const T &what)
Little helper function to convert non-string types to strings.
RCP< SmootherPrototype > Copy() const
When this prototype is cloned using Copy(), the clone is an Ifpack or an Ifpack2 smoother.
RCP< SmootherPrototype > sStratimikos_
RCP< SmootherPrototype > sTpetra_
bool IsSetup() const
Get the state of a smoother prototype.
Class that encapsulates external library smoothers.
static std::string Ifpack2ToIfpack1Type(const std::string &type)
Convert an Ifpack2 preconditioner name to Ifpack.
static Teuchos::ParameterList Ifpack2ToIfpack1Param(const Teuchos::ParameterList &ifpack2List)
Convert an Ifpack2 parameter list to Ifpack.
Class that encapsulates Belos smoothers.
Print additional debugging information.
void DeclareInput(Level ¤tLevel) const
Input.
Namespace for MueLu classes and methods.
void Setup(Level ¤tLevel)
TrilinosSmoother cannot be turned into a smoother using Setup(). Setup() always returns a RuntimeErro...
friend class TrilinosSmoother
Friend declaration required for clone() functionality.
std::string description() const
Return a simple one-line description of this object.
virtual void SetParameterList(const Teuchos::ParameterList ¶mList)
Set parameters from a parameter list and return with default values.
Class that holds all level-specific information.
std::string type_
ifpack1/2-specific key phrase that denote smoother type
Xpetra::UnderlyingLib lib()
#define MUELU_DESCRIBE
Helper macro for implementing Describable::describe() for BaseClass objects.
RCP< SmootherPrototype > sEpetra_
Smoother.
RCP< SmootherPrototype > sBelos_
void print(Teuchos::FancyOStream &out, const VerbLevel verbLevel=Default) const
Print the object with some verbosity level to an FancyOStream object.
Print class parameters (more parameters, more verbose)
Exception throws to report errors in the internal logical of the program.
LO overlap_
overlap when using the smoother in additive Schwarz mode
void Apply(MultiVector &X, const MultiVector &B, bool InitialGuessIsZero=false) const
TrilinosSmoother cannot be applied. Apply() always returns a RuntimeError exception.
Class that encapsulates Ifpack2 smoothers.
virtual std::string description() const
Return a simple one-line description of this object.
void SetFactory(const std::string &varName, const RCP< const FactoryBase > &factory)
Custom SetFactory.