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"
61 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
63 : type_(type), overlap_(overlap)
78 ParameterList paramList = paramListIn;
84 #if defined(HAVE_MUELU_TPETRA) && defined(HAVE_MUELU_IFPACK2)
96 #if defined(HAVE_MUELU_EPETRA) && defined(HAVE_MUELU_IFPACK)
112 "Please enable (TPETRA and IFPACK2) or (EPETRA and IFPACK)");
115 "Could not construct any smoother:\n"
116 << (
triedEpetra_ ?
"=> Failed to build an Epetra smoother due to the following exception:\n" :
"=> Epetra and/or Ifpack are not enabled.\n")
118 << (
triedTpetra_ ?
"=> Failed to build a Tpetra smoother due to the following exception:\n" :
"=> Tpetra and/or Ifpack2 are not enabled.\n")
124 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
127 if (!sEpetra_.is_null()) sEpetra_->SetFactory(varName, factory);
128 if (!sTpetra_.is_null()) sTpetra_->SetFactory(varName, factory);
131 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
138 bool useTpetra = (currentLevel.
lib() == Xpetra::UseTpetra);
139 s_ = (useTpetra ? sTpetra_ : sEpetra_);
142 #if not defined(HAVE_MUELU_IFPACK22)
144 "Error: running in Tpetra mode, but MueLu with Ifpack2 was disabled during the configure stage.\n"
145 "Please make sure that:\n"
146 " - Ifpack2 is enabled (Trilinos_ENABLE_Ifpack2=ON),\n"
147 " - Ifpack2 is available for MueLu to use (MueLu_ENABLE_Ifpack2=ON)\n");
150 this->GetOStream(
Errors) <<
"Tpetra mode was disabled due to an error:\n" << errorTpetra_ << std::endl;
154 #if not defined(HAVE_MUELU_IFPACK)
156 "Error: running in Epetra mode, but MueLu with Ifpack was disabled during the configure stage.\n"
157 "Please make sure that:\n"
158 " - Ifpack is enabled (you can do that with Trilinos_ENABLE_Ifpack=ON),\n"
159 " - Ifpack is available for MueLu to use (MueLu_ENABLE_Ifpack=ON)\n");
162 this->GetOStream(
Errors) <<
"Epetra mode was disabled due to an error:\n" << errorEpetra_ << std::endl;
166 "Smoother for " << (useTpetra ?
"Tpetra" :
"Epetra") <<
" was not constructed");
169 s_->DeclareInput(currentLevel);
172 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
175 this->GetOStream(
Warnings0) <<
"MueLu::TrilinosSmoother::Setup(): Setup() has already been called" << std::endl;
177 int oldRank = s_->SetProcRankVerbose(this->GetProcRankVerbose());
179 s_->Setup(currentLevel);
181 s_->SetProcRankVerbose(oldRank);
185 this->SetParameterList(s_->GetParameterList());
188 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
192 s_->Apply(X, B, InitialGuessIsZero);
195 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
196 RCP<MueLu::SmootherPrototype<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
198 RCP<TrilinosSmoother> newSmoo = rcp(
new TrilinosSmoother(type_, this->GetParameterList(), overlap_));
202 if (!sEpetra_.is_null())
203 newSmoo->sEpetra_ = sEpetra_->Copy();
204 if (!sTpetra_.is_null())
205 newSmoo->sTpetra_ = sTpetra_->Copy();
208 newSmoo->s_ = (s_.get() == sTpetra_.get() ? newSmoo->sTpetra_ : newSmoo->sEpetra_);
209 newSmoo->SetParameterList(this->GetParameterList());
214 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
216 if (type ==
"RELAXATION") {
return "point relaxation stand-alone"; }
217 if (type ==
"CHEBYSHEV") {
return "Chebyshev"; }
218 if (type ==
"ILUT") {
return "ILUT"; }
219 if (type ==
"RILUK") {
return "ILU"; }
220 if (type ==
"ILU") {
return "ILU"; }
221 if (type ==
"Amesos") {
return "Amesos"; }
227 if (type ==
"LINESMOOTHING_BLOCKRELAXATION") {
return "LINESMOOTHING_BLOCKRELAXATION"; }
228 if (type ==
"LINESMOOTHING_BLOCK RELAXATION") {
return "LINESMOOTHING_BLOCKRELAXATION"; }
229 if (type ==
"LINESMOOTHING_BLOCK_RELAXATION") {
return "LINESMOOTHING_BLOCKRELAXATION"; }
230 if (type ==
"LINESMOOTHING_BANDEDRELAXATION") {
return "LINESMOOTHING_BLOCKRELAXATION"; }
231 if (type ==
"LINESMOOTHING_BANDED RELAXATION") {
return "LINESMOOTHING_BLOCKRELAXATION"; }
232 if (type ==
"LINESMOOTHING_BANDED_RELAXATION") {
return "LINESMOOTHING_BLOCKRELAXATION"; }
233 if (type ==
"LINESMOOTHING_TRIDIRELAXATION") {
return "LINESMOOTHING_BLOCKRELAXATION"; }
234 if (type ==
"LINESMOOTHING_TRIDI RELAXATION") {
return "LINESMOOTHING_BLOCKRELAXATION"; }
235 if (type ==
"LINESMOOTHING_TRIDI_RELAXATION") {
return "LINESMOOTHING_BLOCKRELAXATION"; }
236 if (type ==
"LINESMOOTHING_TRIDIAGONALRELAXATION") {
return "LINESMOOTHING_BLOCKRELAXATION"; }
237 if (type ==
"LINESMOOTHING_TRIDIAGONAL RELAXATION") {
return "LINESMOOTHING_BLOCKRELAXATION"; }
238 if (type ==
"LINESMOOTHING_TRIDIAGONAL_RELAXATION") {
return "LINESMOOTHING_BLOCKRELAXATION"; }
239 if(type ==
"BLOCK_RELAXATION" ||
240 type ==
"BLOCK RELAXATION" ||
241 type ==
"BLOCKRELAXATION" ||
243 type ==
"BANDED_RELAXATION" ||
244 type ==
"BANDED RELAXATION" ||
245 type ==
"BANDEDRELAXATION" ||
247 type ==
"TRIDI_RELAXATION" ||
248 type ==
"TRIDI RELAXATION" ||
249 type ==
"TRIDIRELAXATION" ||
250 type ==
"TRIDIAGONAL_RELAXATION" ||
251 type ==
"TRIDIAGONAL RELAXATION" ||
252 type ==
"TRIDIAGONALRELAXATION") {
253 return "block relaxation stand-alone";
256 TEUCHOS_TEST_FOR_EXCEPTION(
true,
Exceptions::RuntimeError,
"Cannot convert Ifpack2 preconditioner name to Ifpack: unknown type: \"" + type +
"\"");
259 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
261 Teuchos::ParameterList ifpack1List = ifpack2List;
263 if (ifpack2List.isParameter(
"relaxation: type") && ifpack2List.get<std::string>(
"relaxation: type") ==
"Symmetric Gauss-Seidel")
264 ifpack1List.set(
"relaxation: type",
"symmetric Gauss-Seidel");
266 if (ifpack2List.isParameter(
"fact: iluk level-of-fill")) {
267 ifpack1List.remove(
"fact: iluk level-of-fill");
268 ifpack1List.set(
"fact: level-of-fill", ifpack2List.get<
int>(
"fact: iluk level-of-fill"));
274 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
276 std::ostringstream out;
277 if (s_ != Teuchos::null) {
278 out << s_->description();
281 out <<
"{type = " << type_ <<
"}";
286 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
291 out0 <<
"Prec. type: " << type_ << std::endl;
294 out0 <<
"PrecType: " << type_ << std::endl;
295 out0 <<
"Parameter list: " << std::endl;
296 Teuchos::OSTab tab2(out);
297 out << this->GetParameterList();
298 out0 <<
"Overlap: " << overlap_ << std::endl;
301 if (verbLevel &
Debug) {
304 <<
"Epetra PrecType: " << Ifpack2ToIfpack1Type(type_) << std::endl
305 <<
"Epetra Parameter list: " << std::endl;
306 Teuchos::OSTab tab2(out);
307 out << Ifpack2ToIfpack1Param(this->GetParameterList());;
#define MUELU_DESCRIBE
Helper macro for implementing Describable::describe() for BaseClass objects.
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
friend class TrilinosSmoother
Friend declaration required for clone() functionality.
void DeclareInput(Level ¤tLevel) const
Input.
RCP< SmootherPrototype > sEpetra_
Smoother.
void SetFactory(const std::string &varName, const RCP< const FactoryBase > &factory)
Custom SetFactory.
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)
std::string toString(const T &what)
Little helper function to convert non-string types to strings.