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"
22#include "MueLu_BelosSmoother.hpp"
23#include "MueLu_StratimikosSmoother.hpp"
24#include "MueLu_RefMaxwellSmoother.hpp"
28template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
41 ParameterList paramList = paramListIn;
49 errorTpetra_ =
"Unable to construct Amesos2 direct solver";
50 else if (!
sTpetra_->constructionSuccessful()) {
58 }
catch (Teuchos::Exceptions::InvalidParameterName& e) {
62#if defined(HAVE_MUELU_BELOS)
67 else if (!
sBelos_->constructionSuccessful()) {
78#if defined(HAVE_MUELU_STRATIMIKOS) && defined(HAVE_MUELU_THYRA)
108 "Unable to construct any direct solver.");
111 "Could not enable any direct solver:\n"
112 << (
triedTpetra_ ?
"Tpetra mode was disabled due to an error:\n" :
"")
114 << (
triedBelos_ ?
"Belos was disabled due to an error:\n" :
"")
125template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
128 if (!sTpetra_.is_null()) sTpetra_->SetFactory(varName, factory);
129 if (!sBelos_.is_null()) sBelos_->SetFactory(varName, factory);
130 if (!sStratimikos_.is_null()) sStratimikos_->SetFactory(varName, factory);
131 if (!sRefMaxwell_.is_null()) sRefMaxwell_->SetFactory(varName, factory);
134template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
136 if (!sBelos_.is_null())
138 else if (!sStratimikos_.is_null())
140 else if (!sRefMaxwell_.is_null())
147 this->GetOStream(
Errors) <<
"Belos mode was disabled due to an error:\n"
148 << errorBelos_ << std::endl;
149 if (triedStratimikos_)
150 this->GetOStream(
Errors) <<
"Stratimikos mode was disabled due to an error:\n"
151 << errorStratimikos_ << std::endl;
152 if (triedRefMaxwell_)
153 this->GetOStream(
Errors) <<
"RefMaxwell mode was disabled due to an error:\n"
154 << errorRefMaxwell_ << std::endl;
156 this->GetOStream(
Errors) <<
"Tpetra mode was disabled due to an error:\n"
157 << errorTpetra_ << std::endl;
160 "Direct solver was not constructed");
163 s_->DeclareInput(currentLevel);
166template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
169 this->GetOStream(
Warnings0) <<
"MueLu::DirectSolver::Setup(): Setup() has already been called" << std::endl;
171 int oldRank = s_->SetProcRankVerbose(this->GetProcRankVerbose());
173 s_->Setup(currentLevel);
175 s_->SetProcRankVerbose(oldRank);
179 this->SetParameterList(s_->GetParameterList());
182template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
186 s_->Apply(X, B, InitialGuessIsZero);
189template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
191 RCP<DirectSolver> newSmoo = rcp(
new DirectSolver(*
this));
195 if (!sTpetra_.is_null())
196 newSmoo->sTpetra_ = sTpetra_->Copy();
197 if (!sBelos_.is_null())
198 newSmoo->sBelos_ = sBelos_->Copy();
199 if (!sStratimikos_.is_null())
200 newSmoo->sStratimikos_ = sStratimikos_->Copy();
201 if (!sRefMaxwell_.is_null())
202 newSmoo->sRefMaxwell_ = sRefMaxwell_->Copy();
205 if (s_.get() == sBelos_.get())
206 newSmoo->s_ = newSmoo->sBelos_;
207 else if (s_.get() == sStratimikos_.get())
208 newSmoo->s_ = newSmoo->sStratimikos_;
209 else if (s_.get() == sRefMaxwell_.get())
210 newSmoo->s_ = newSmoo->sRefMaxwell_;
212 newSmoo->s_ = newSmoo->sTpetra_;
213 newSmoo->SetParameterList(this->GetParameterList());
218template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
220 std::ostringstream out;
221 if (s_ != Teuchos::null) {
222 out << s_->description();
225 out <<
"{type = " << type_ <<
"}";
230template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
235 out0 <<
"Prec. type: " << type_ << std::endl;
238 out0 <<
"Parameter list: " << std::endl;
239 Teuchos::OSTab tab3(out);
240 out << this->GetParameterList();
243 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_
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_
Smoother.
Exception indicating invalid cast attempted.
Exception throws to report errors in the internal logical of the program.
Class that holds all level-specific information.
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)