10#ifndef MUELU_DIRECTSOLVER_DEF_HPP
11#define MUELU_DIRECTSOLVER_DEF_HPP
13#include <Xpetra_Utils.hpp>
14#include <Xpetra_Matrix.hpp>
21#include "MueLu_Amesos2Smoother.hpp"
23#include "MueLu_BelosSmoother.hpp"
24#include "MueLu_StratimikosSmoother.hpp"
25#include "MueLu_RefMaxwellSmoother.hpp"
29template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
43 ParameterList paramList = paramListIn;
51 errorTpetra_ =
"Unable to construct Amesos2 direct solver";
52 else if (!
sTpetra_->constructionSuccessful()) {
60 }
catch (Teuchos::Exceptions::InvalidParameterName& e) {
64#if defined(HAVE_MUELU_BELOS)
69 else if (!
sBelos_->constructionSuccessful()) {
80#if defined(HAVE_MUELU_STRATIMIKOS) && defined(HAVE_MUELU_THYRA)
110 "Unable to construct any direct solver."
111 "Plase enable (TPETRA and AMESOS2) or (EPETRA and AMESOS) or (BELOS) or (STRATIMIKOS)");
114 "Could not enable any direct solver:\n"
115 << (
triedEpetra_ ?
"Epetra mode was disabled due to an error:\n" :
"")
117 << (
triedTpetra_ ?
"Tpetra mode was disabled due to an error:\n" :
"")
119 << (
triedBelos_ ?
"Belos was disabled due to an error:\n" :
"")
130template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
133 if (!sEpetra_.is_null()) sEpetra_->SetFactory(varName, factory);
134 if (!sTpetra_.is_null()) sTpetra_->SetFactory(varName, factory);
135 if (!sBelos_.is_null()) sBelos_->SetFactory(varName, factory);
136 if (!sStratimikos_.is_null()) sStratimikos_->SetFactory(varName, factory);
137 if (!sRefMaxwell_.is_null()) sRefMaxwell_->SetFactory(varName, factory);
140template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
142 if (!sBelos_.is_null())
144 else if (!sStratimikos_.is_null())
146 else if (!sRefMaxwell_.is_null())
154 bool useTpetra = (currentLevel.
lib() == Xpetra::UseTpetra);
155 s_ = (useTpetra ? sTpetra_ : sEpetra_);
158#if not defined(HAVE_MUELU_AMESOS2)
160 "Error: running in Tpetra mode, but MueLu with Amesos2 was disabled during the configure stage.\n"
161 "Please make sure that:\n"
162 " - Amesos2 is enabled (Trilinos_ENABLE_Amesos2=ON),\n"
163 " - Amesos2 is available for MueLu to use (MueLu_ENABLE_Amesos2=ON)\n");
166 this->GetOStream(
Errors) <<
"Tpetra mode was disabled due to an error:\n"
167 << errorTpetra_ << std::endl;
171#if not defined(HAVE_MUELU_AMESOS)
173 "Error: running in Epetra mode, but MueLu with Amesos was disabled during the configure stage.\n"
174 "Please make sure that:\n"
175 " - Amesos is enabled (you can do that with Trilinos_ENABLE_Amesos=ON),\n"
176 " - Amesos is available for MueLu to use (MueLu_ENABLE_Amesos=ON)\n");
179 this->GetOStream(
Errors) <<
"Epetra mode was disabled due to an error:\n"
180 << errorEpetra_ << std::endl;
184 "Direct solver for " << (useTpetra ?
"Tpetra" :
"Epetra") <<
" was not constructed");
188 s_->DeclareInput(currentLevel);
191template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
194 this->GetOStream(
Warnings0) <<
"MueLu::DirectSolver::Setup(): Setup() has already been called" << std::endl;
196 int oldRank = s_->SetProcRankVerbose(this->GetProcRankVerbose());
198 s_->Setup(currentLevel);
200 s_->SetProcRankVerbose(oldRank);
204 this->SetParameterList(s_->GetParameterList());
207template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
211 s_->Apply(X, B, InitialGuessIsZero);
214template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
216 RCP<DirectSolver> newSmoo = rcp(
new DirectSolver(*
this));
220 if (!sEpetra_.is_null())
221 newSmoo->sEpetra_ = sEpetra_->Copy();
222 if (!sTpetra_.is_null())
223 newSmoo->sTpetra_ = sTpetra_->Copy();
224 if (!sBelos_.is_null())
225 newSmoo->sBelos_ = sBelos_->Copy();
226 if (!sStratimikos_.is_null())
227 newSmoo->sStratimikos_ = sStratimikos_->Copy();
228 if (!sRefMaxwell_.is_null())
229 newSmoo->sRefMaxwell_ = sRefMaxwell_->Copy();
232 if (s_.get() == sBelos_.get())
233 newSmoo->s_ = newSmoo->sBelos_;
234 else if (s_.get() == sStratimikos_.get())
235 newSmoo->s_ = newSmoo->sStratimikos_;
236 else if (s_.get() == sRefMaxwell_.get())
237 newSmoo->s_ = newSmoo->sRefMaxwell_;
238 else if (s_.get() == sTpetra_.get())
239 newSmoo->s_ = newSmoo->sTpetra_;
241 newSmoo->s_ = newSmoo->sEpetra_;
242 newSmoo->SetParameterList(this->GetParameterList());
247template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
249 std::ostringstream out;
250 if (s_ != Teuchos::null) {
251 out << s_->description();
254 out <<
"{type = " << type_ <<
"}";
259template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
264 out0 <<
"Prec. type: " << type_ << std::endl;
267 out0 <<
"Parameter list: " << std::endl;
268 Teuchos::OSTab tab3(out);
269 out << this->GetParameterList();
272 if (verbLevel &
Debug)
#define MUELU_DESCRIBE
Helper macro for implementing Describable::describe() for BaseClass objects.
Class that encapsulates Amesos2 direct solvers.
Class that encapsulates Belos smoothers.
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 errorRefMaxwell_
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 > sBelos_
RCP< SmootherPrototype > sStratimikos_
RCP< SmootherPrototype > sEpetra_
Smoother.
std::string errorStratimikos_
RCP< SmootherPrototype > sRefMaxwell_
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.
Class that encapsulates Operator smoothers.
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)