48 #ifndef MUELU_DETAILS_LINEARSOLVERFACTORY_DEF_HPP
49 #define MUELU_DETAILS_LINEARSOLVERFACTORY_DEF_HPP
51 #include "MueLu_config.hpp"
54 #include <type_traits>
56 #ifdef HAVE_MUELU_EPETRA
57 #include "Epetra_CrsMatrix.h"
59 #endif // HAVE_MUELU_EPETRA
61 #include "Tpetra_Operator.hpp"
67 template <
class MV,
class OP,
class NormType>
89 void solve(MV& X,
const MV& B);
117 #if defined(HAVE_MUELU_SERIAL) and defined(HAVE_MUELU_EPETRA)
125 , changedParams_(
false) {}
135 const char prefix[] =
"MueLu::Details::LinearSolver::setMatrix: ";
138 if (solver_ != Teuchos::null)
143 "an Epetra_CrsMatrix, but the matrix you provided is of a "
144 "different type. Please provide an Epetra_CrsMatrix instead.");
156 const char prefix[] =
"MueLu::Details::LinearSolver::solve: ";
158 "exist yet. You must call numeric() before you may call this method.");
160 "since the last call to numeric(). Please call numeric() again.");
162 "since the last call to numeric(). Please call numeric() again.");
164 int err = solver_->ApplyInverse(B, X);
167 "nonzero error code "
173 if (solver_ != Teuchos::null && params !=
params_)
174 changedParams_ =
true;
186 const char prefix[] =
"MueLu::Details::LinearSolver::numeric: ";
189 if (solver_ == Teuchos::null || changedA_ || changedParams_) {
191 changedParams_ =
false;
194 "set yet. You must call setMatrix() with a nonnull matrix before you may "
195 "call this method.");
208 if (solver_.is_null()) {
209 return "\"MueLu::Details::LinearSolver\": {MV: Epetra_MultiVector, OP: Epetra_Operator, NormType: double}";
211 return solver_->GetHierarchy()->description();
221 if (solver_.is_null()) {
224 out <<
"\"MueLu::Details::LinearSolver\":" << endl;
226 out <<
"MV: Epetra_MultiVector" << endl
227 <<
"OP: Epetra_Operator" << endl
228 <<
"NormType: double" << endl;
231 solver_->GetHierarchy()->describe(out, verbLevel);
242 #endif // HAVE_MUELU_EPETRA
244 template <
class Scalar,
class LO,
class GO,
class Node>
248 Tpetra::Operator<Scalar, LO, GO, Node>,
249 typename Teuchos::ScalarTraits<Scalar>::magnitudeType>,
255 , changedParams_(false) {}
266 if (solver_ != Teuchos::null)
281 const char prefix[] =
"MueLu::Details::LinearSolver::solve: ";
283 "exist yet. You must call numeric() before you may call this method.");
285 "since the last call to numeric(). Please call numeric() again.");
286 TEUCHOS_TEST_FOR_EXCEPTION(changedParams_, std::runtime_error, prefix <<
"The parameters have been reset "
287 "since the last call to numeric(). Please call numeric() again.");
289 solver_->apply(B, X);
294 if (solver_ != Teuchos::null && params !=
params_)
295 changedParams_ =
true;
307 const char prefix[] =
"MueLu::Details::LinearSolver::numeric: ";
310 if (solver_ == Teuchos::null || changedParams_) {
312 "set yet. You must call setMatrix() with a nonnull matrix before you may "
313 "call this method.");
321 }
else if (changedA_) {
323 "set yet. You must call setMatrix() with a nonnull matrix before you may "
324 "call this method.");
331 "a Tpetra::CrsMatrix, but the matrix you provided is of a "
332 "different type. Please provide a Tpetra::CrsMatrix instead.");
337 changedParams_ =
false;
343 if (solver_.is_null()) {
344 std::ostringstream os;
345 os <<
"\"MueLu::Details::LinearSolver\": {"
346 <<
"MV: " << TypeNameTraits<Tpetra::MultiVector<Scalar, LO, GO, Node> >::name()
347 <<
"OP: " << TypeNameTraits<Tpetra::Operator<Scalar, LO, GO, Node> >::name()
348 <<
"NormType: " << TypeNameTraits<typename Teuchos::ScalarTraits<Scalar>::magnitudeType>::name()
352 return solver_->GetHierarchy()->description();
363 if (solver_.is_null()) {
366 out <<
"\"MueLu::Details::LinearSolver\":" << endl;
368 out <<
"MV: " << TypeNameTraits<Tpetra::MultiVector<Scalar, LO, GO, Node> >::name() << endl
369 <<
"OP: " << TypeNameTraits<Tpetra::Operator<Scalar, LO, GO, Node> >::name() << endl
370 <<
"NormType: " << TypeNameTraits<typename Teuchos::ScalarTraits<Scalar>::magnitudeType>::name() << endl;
373 solver_->GetHierarchy()->describe(out, verbLevel);
385 template <
class MV,
class OP,
class NormType>
393 template <
class MV,
class OP,
class NormType>
396 #ifdef HAVE_TEUCHOSCORE_CXX11
397 typedef std::shared_ptr<MueLu::Details::LinearSolverFactory<MV, OP, NormType> > ptr_type;
402 #endif // HAVE_TEUCHOSCORE_CXX11
405 Trilinos::Details::registerLinearSolverFactory<MV, OP, NormType>(
"MueLu", factory);
418 #define MUELU_DETAILS_LINEARSOLVERFACTORY_INSTANT(SC, LO, GO, NT) \
419 template class MueLu::Details::LinearSolverFactory<Tpetra::MultiVector<SC, LO, GO, NT>, \
420 Tpetra::Operator<SC, LO, GO, NT>, \
421 typename Tpetra::MultiVector<SC, LO, GO, NT>::mag_type>;
423 #endif // MUELU_DETAILS_LINEARSOLVERFACTORY_DEF_HPP
Interface for a "factory" that creates MueLu solvers.
Teuchos::RCP< const OP > getMatrix() const
Get a pointer to this Solver's matrix.
std::string description() const
Implementation of Teuchos::Describable::description.
Teuchos::RCP< MueLu::TpetraOperator< Scalar, LocalOrdinal, GlobalOrdinal, Node > > CreateTpetraPreconditioner(const Teuchos::RCP< Tpetra::Operator< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &inA, Teuchos::ParameterList &inParamList)
Helper function to create a MueLu or AMGX preconditioner that can be used by Tpetra.Given a Tpetra::Operator, this function returns a constructed MueLu preconditioner.
void symbolic()
Set up any part of the solve that depends on the structure of the input matrix, but not its numerical...
Teuchos::RCP< Teuchos::ParameterList > params_
void setParameters(const Teuchos::RCP< Teuchos::ParameterList > ¶ms)
Set this solver's parameters.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
std::string description() const
Implementation of Teuchos::Describable::description.
virtual Teuchos::RCP< Trilinos::Details::LinearSolver< MV, OP, NormType > > getLinearSolver(const std::string &solverName)
Get an instance of a MueLu solver.
void numeric()
Set up any part of the solve that depends on both the structure and the numerical values of the input...
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
LinearSolver()
Constructor.
void setParameters(const Teuchos::RCP< Teuchos::ParameterList > ¶ms)
Set this solver's parameters.
virtual ~LinearSolver()
Destructor (virtual for memory safety).
Teuchos::RCP< TpetraOperator< Scalar, LO, GO, Node > > solver_
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Implementation of Teuchos::Describable::describe.
Various adapters that will create a MueLu preconditioner that is a Tpetra::Operator.
static const EVerbosityLevel verbLevel_default
LinearSolver()
Constructor.
Teuchos::RCP< const OP > A_
Teuchos::RCP< MueLu::EpetraOperator > CreateEpetraPreconditioner(const Teuchos::RCP< Epetra_CrsMatrix > &inA, Teuchos::ParameterList ¶mListIn)
Helper function to create a MueLu preconditioner that can be used by Epetra.Given a EpetraCrs_Matrix...
void setMatrix(const Teuchos::RCP< const Tpetra::Operator< Scalar, LO, GO, Node > > &A)
Set the Solver's matrix.
static void registerLinearSolverFactory()
Register this LinearSolverFactory with the central registry.
Teuchos::RCP< const Tpetra::Operator< Scalar, LO, GO, Node > > A_
Teuchos::RCP< const Tpetra::Operator< Scalar, LO, GO, Node > > getMatrix() const
Get a pointer to this Solver's matrix.
Various adapters that will create a MueLu preconditioner that is an Epetra_Operator.
virtual ~LinearSolver()
Destructor (virtual for memory safety).
void symbolic()
Set up any part of the solve that depends on the structure of the input matrix, but not its numerical...
Teuchos::RCP< Teuchos::ParameterList > params_
void solve(MV &X, const MV &B)
Solve the linear system(s) AX=B.
void numeric()
Set up any part of the solve that depends on both the structure and the numerical values of the input...
void ReuseTpetraPreconditioner(const Teuchos::RCP< Tpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &inA, MueLu::TpetraOperator< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Op)
Helper function to reuse an existing MueLu preconditioner.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Implementation of Teuchos::Describable::describe.
void setMatrix(const Teuchos::RCP< const OP > &A)
Set the Solver's matrix.
void solve(Tpetra::MultiVector< Scalar, LO, GO, Node > &X, const Tpetra::MultiVector< Scalar, LO, GO, Node > &B)
Solve the linear system(s) AX=B.