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"
62 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
75 ParameterList paramList = paramListIn;
80 #if defined(HAVE_MUELU_TPETRA) && defined(HAVE_MUELU_AMESOS2)
84 errorTpetra_ =
"Unable to construct Amesos2 direct solver";
92 #if defined(HAVE_MUELU_EPETRA) && defined(HAVE_MUELU_AMESOS)
97 errorEpetra_ =
"Unable to construct Amesos direct solver";
108 "Plase enable (TPETRA and AMESOS2) or (EPETRA and AMESOS)");
111 "Could not enable any direct solver:\n"
112 << (
triedEpetra_ ?
"Epetra mode was disabled due to an error:\n" :
"")
114 << (
triedTpetra_ ?
"Tpetra mode was disabled due to an error:\n" :
"")
120 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
123 if (!sEpetra_.is_null()) sEpetra_->SetFactory(varName, factory);
124 if (!sTpetra_.is_null()) sTpetra_->SetFactory(varName, factory);
127 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
134 bool useTpetra = (currentLevel.
lib() == Xpetra::UseTpetra);
135 s_ = (useTpetra ? sTpetra_ : sEpetra_);
138 #if not defined(HAVE_MUELU_AMESOS2)
140 "Error: running in Tpetra mode, but MueLu with Amesos2 was disabled during the configure stage.\n"
141 "Please make sure that:\n"
142 " - Amesos2 is enabled (Trilinos_ENABLE_Amesos2=ON),\n"
143 " - Amesos2 is available for MueLu to use (MueLu_ENABLE_Amesos2=ON)\n");
146 this->GetOStream(
Errors) <<
"Tpetra mode was disabled due to an error:\n" << errorTpetra_ << std::endl;
150 #if not defined(HAVE_MUELU_AMESOS)
152 "Error: running in Epetra mode, but MueLu with Amesos was disabled during the configure stage.\n"
153 "Please make sure that:\n"
154 " - Amesos is enabled (you can do that with Trilinos_ENABLE_Amesos=ON),\n"
155 " - Amesos is available for MueLu to use (MueLu_ENABLE_Amesos=ON)\n");
158 this->GetOStream(
Errors) <<
"Epetra mode was disabled due to an error:\n" << errorEpetra_ << std::endl;
162 "Direct solver for " << (useTpetra ?
"Tpetra" :
"Epetra") <<
" was not constructed");
165 s_->DeclareInput(currentLevel);
168 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
171 this->GetOStream(
Warnings0) <<
"MueLu::DirectSolver::Setup(): Setup() has already been called" << std::endl;
173 int oldRank = s_->SetProcRankVerbose(this->GetProcRankVerbose());
175 s_->Setup(currentLevel);
177 s_->SetProcRankVerbose(oldRank);
181 this->SetParameterList(s_->GetParameterList());
184 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
188 s_->Apply(X, B, InitialGuessIsZero);
191 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
193 RCP<DirectSolver> newSmoo = rcp(
new DirectSolver(*
this));
197 if (!sEpetra_.is_null())
198 newSmoo->sEpetra_ = sEpetra_->Copy();
199 if (!sTpetra_.is_null())
200 newSmoo->sTpetra_ = sTpetra_->Copy();
203 newSmoo->s_ = (s_.get() == sTpetra_.get() ? newSmoo->sTpetra_ : newSmoo->sEpetra_);
204 newSmoo->SetParameterList(this->GetParameterList());
209 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
211 std::ostringstream out;
212 if (s_ != Teuchos::null) {
213 out << s_->description();
216 out <<
"{type = " << type_ <<
"}";
221 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
226 out0 <<
"Prec. type: " << type_ << std::endl;
229 out0 <<
"Parameter list: " << std::endl;
230 Teuchos::OSTab tab3(out);
231 out << this->GetParameterList();
234 if (verbLevel &
Debug)
#define MUELU_DESCRIBE
Helper macro for implementing Describable::describe() for BaseClass objects.
Class that encapsulates Amesos2 direct solvers.
virtual std::string description() const
Return a simple one-line description of this object.
Class that encapsulates direct solvers. Autoselection of AmesosSmoother or Amesos2Smoother according ...
void print(Teuchos::FancyOStream &out, const VerbLevel verbLevel=Default) const
void Apply(MultiVector &X, const MultiVector &B, bool InitialGuessIsZero=false) const
DirectSolver cannot be applied. Apply() always returns a RuntimeError exception.
std::string description() const
Return a simple one-line description of this object.
void Setup(Level ¤tLevel)
DirectSolver cannot be turned into a smoother using Setup(). Setup() always returns a RuntimeError ex...
void SetFactory(const std::string &varName, const RCP< const FactoryBase > &factory)
Custom SetFactory.
RCP< SmootherPrototype > sEpetra_
Smoother.
void DeclareInput(Level ¤tLevel) const
Input.
RCP< SmootherPrototype > Copy() const
When this prototype is cloned using Copy(), the clone is an Amesos or an Amesos2 smoother.
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 ...
RCP< SmootherPrototype > sTpetra_
Exception indicating invalid cast attempted.
Exception throws to report errors in the internal logical of the program.
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.
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.