46 #ifndef MUELU_DIRECTSOLVER_DEF_HPP 47 #define MUELU_DIRECTSOLVER_DEF_HPP 49 #include <Xpetra_Utils.hpp> 50 #include <Xpetra_Matrix.hpp> 57 #include "MueLu_Amesos2Smoother.hpp" 59 #include "MueLu_BelosSmoother.hpp" 60 #include "MueLu_StratimikosSmoother.hpp" 64 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
78 ParameterList paramList = paramListIn;
83 #if defined(HAVE_MUELU_TPETRA) && defined(HAVE_MUELU_AMESOS2) 87 errorTpetra_ =
"Unable to construct Amesos2 direct solver";
88 else if (!
sTpetra_->constructionSuccessful()) {
96 }
catch (Teuchos::Exceptions::InvalidParameterName& e) {
101 #if defined(HAVE_MUELU_EPETRA) && defined(HAVE_MUELU_AMESOS) 106 errorEpetra_ =
"Unable to construct Amesos direct solver";
107 else if (!
sEpetra_->constructionSuccessful()) {
117 #if defined(HAVE_MUELU_BELOS) 122 else if (!
sBelos_->constructionSuccessful()) {
133 #if defined(HAVE_MUELU_STRATIMIKOS) && defined(HAVE_MUELU_TPETRA) && defined(HAVE_MUELU_THYRA) 151 "Plase enable (TPETRA and AMESOS2) or (EPETRA and AMESOS) or (BELOS) or (STRATIMIKOS)");
154 "Could not enable any direct solver:\n" 155 << (
triedEpetra_ ?
"Epetra mode was disabled due to an error:\n" :
"")
157 << (
triedTpetra_ ?
"Tpetra mode was disabled due to an error:\n" :
"")
159 << (
triedBelos_ ?
"Belos was disabled due to an error:\n" :
"")
167 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
170 if (!sEpetra_.is_null()) sEpetra_->SetFactory(varName, factory);
171 if (!sTpetra_.is_null()) sTpetra_->SetFactory(varName, factory);
172 if (!sBelos_.is_null()) sBelos_->SetFactory(varName, factory);
173 if (!sStratimikos_.is_null()) sStratimikos_->SetFactory(varName, factory);
176 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
178 if (!sBelos_.is_null())
180 else if (!sStratimikos_.is_null())
188 bool useTpetra = (currentLevel.
lib() == Xpetra::UseTpetra);
189 s_ = (useTpetra ? sTpetra_ : sEpetra_);
192 #if not defined(HAVE_MUELU_AMESOS2) 194 "Error: running in Tpetra mode, but MueLu with Amesos2 was disabled during the configure stage.\n" 195 "Please make sure that:\n" 196 " - Amesos2 is enabled (Trilinos_ENABLE_Amesos2=ON),\n" 197 " - Amesos2 is available for MueLu to use (MueLu_ENABLE_Amesos2=ON)\n");
200 this->GetOStream(
Errors) <<
"Tpetra mode was disabled due to an error:\n" << errorTpetra_ << std::endl;
204 #if not defined(HAVE_MUELU_AMESOS) 206 "Error: running in Epetra mode, but MueLu with Amesos was disabled during the configure stage.\n" 207 "Please make sure that:\n" 208 " - Amesos is enabled (you can do that with Trilinos_ENABLE_Amesos=ON),\n" 209 " - Amesos is available for MueLu to use (MueLu_ENABLE_Amesos=ON)\n");
212 this->GetOStream(
Errors) <<
"Epetra mode was disabled due to an error:\n" << errorEpetra_ << std::endl;
216 "Direct solver for " << (useTpetra ?
"Tpetra" :
"Epetra") <<
" was not constructed");
220 s_->DeclareInput(currentLevel);
223 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
226 this->GetOStream(
Warnings0) <<
"MueLu::DirectSolver::Setup(): Setup() has already been called" << std::endl;
228 int oldRank = s_->SetProcRankVerbose(this->GetProcRankVerbose());
230 s_->Setup(currentLevel);
232 s_->SetProcRankVerbose(oldRank);
236 this->SetParameterList(s_->GetParameterList());
239 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
243 s_->Apply(X, B, InitialGuessIsZero);
246 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
248 RCP<DirectSolver> newSmoo = rcp(
new DirectSolver(*
this));
252 if (!sEpetra_.is_null())
253 newSmoo->sEpetra_ = sEpetra_->Copy();
254 if (!sTpetra_.is_null())
255 newSmoo->sTpetra_ = sTpetra_->Copy();
256 if (!sBelos_.is_null())
257 newSmoo->sBelos_ = sBelos_->Copy();
258 if (!sStratimikos_.is_null())
259 newSmoo->sStratimikos_ = sStratimikos_->Copy();
262 if (s_.get() == sBelos_.get())
263 newSmoo->s_ = newSmoo->sBelos_;
264 else if (s_.get() == sStratimikos_.get())
265 newSmoo->s_ = newSmoo->sStratimikos_;
266 else if (s_.get() == sTpetra_.get())
267 newSmoo->s_ = newSmoo->sTpetra_;
269 newSmoo->s_ = newSmoo->sEpetra_;
270 newSmoo->SetParameterList(this->GetParameterList());
275 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
277 std::ostringstream out;
278 if (s_ != Teuchos::null) {
279 out << s_->description();
282 out <<
"{type = " << type_ <<
"}";
287 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
292 out0 <<
"Prec. type: " << type_ << std::endl;
295 out0 <<
"Parameter list: " << std::endl;
296 Teuchos::OSTab tab3(out);
297 out << this->GetParameterList();
300 if (verbLevel &
Debug)
306 #endif // MUELU_DIRECTSOLVER_DEF_HPP void print(Teuchos::FancyOStream &out, const VerbLevel verbLevel=Default) const
Important warning messages (one line)
void Apply(MultiVector &X, const MultiVector &B, bool InitialGuessIsZero=false) const
DirectSolver cannot be applied. Apply() always returns a RuntimeError exception.
Exception indicating invalid cast attempted.
void Setup(Level ¤tLevel)
DirectSolver cannot be turned into a smoother using Setup(). Setup() always returns a RuntimeError ex...
std::string toString(const T &what)
Little helper function to convert non-string types to strings.
std::string errorStratimikos_
bool IsSetup() const
Get the state of a smoother prototype.
Class that encapsulates Belos smoothers.
Print additional debugging information.
Namespace for MueLu classes and methods.
std::string type_
amesos1/2-specific key phrase that denote smoother type
DirectSolver(const std::string &type="", const Teuchos::ParameterList ¶mList=Teuchos::ParameterList())
Constructor Note: only parameters shared by Amesos and Amesos2 should be used for type and paramList ...
Class that encapsulates direct solvers. Autoselection of AmesosSmoother or Amesos2Smoother according ...
virtual void SetParameterList(const Teuchos::ParameterList ¶mList)
Set parameters from a parameter list and return with default values.
std::string description() const
Return a simple one-line description of this object.
Class that holds all level-specific information.
Class that encapsulates Amesos2 direct solvers.
RCP< SmootherPrototype > sBelos_
void DeclareInput(Level ¤tLevel) const
Input.
Xpetra::UnderlyingLib lib()
#define MUELU_DESCRIBE
Helper macro for implementing Describable::describe() for BaseClass objects.
RCP< SmootherPrototype > sTpetra_
void SetFactory(const std::string &varName, const RCP< const FactoryBase > &factory)
Custom SetFactory.
RCP< SmootherPrototype > sEpetra_
Smoother.
Print class parameters (more parameters, more verbose)
Exception throws to report errors in the internal logical of the program.
RCP< SmootherPrototype > sStratimikos_
RCP< SmootherPrototype > Copy() const
When this prototype is cloned using Copy(), the clone is an Amesos or an Amesos2 smoother.
virtual std::string description() const
Return a simple one-line description of this object.