10#ifndef BELOS_DETAILS_LINEARSOLVER_HPP
11#define BELOS_DETAILS_LINEARSOLVER_HPP
17#include "Trilinos_Details_LinearSolver.hpp"
43template<
class MV,
class OP,
class ScalarType,
class NormType>
45 public Trilinos::Details::LinearSolver<MV, OP, NormType>
75 if (problem_.is_null ()) {
76 problem_ = Teuchos::rcp (
new problem_type (
A, Teuchos::null, Teuchos::null));
77 }
else if (
A != problem_->getOperator ()) {
78 problem_->setOperator (
A);
84 if (problem_.is_null ()) {
87 return problem_->getOperator ();
94 (problem_.is_null () || problem_->getOperator ().is_null (),
95 std::runtime_error,
"Belos::Details::LinearSolver::solve: "
96 "The matrix A in the linear system to solve has not yet been set. "
97 "Please call setMatrix() with a nonnull input before calling solve().");
98 Teuchos::RCP<MV>
X_ptr = Teuchos::rcpFromRef (
X);
99 Teuchos::RCP<const MV>
B_ptr = Teuchos::rcpFromRef (B);
101 problem_->setLHS (
X_ptr);
102 problem_->setRHS (
B_ptr);
103 problem_->setProblem ();
108 if (solver_.is_null ()) {
110 solver_ =
factory.create (solverName_, params_);
111 solver_->setProblem (problem_);
115 (
void) solver_->solve ();
120 if (! solver_.is_null () && !
params.is_null ()) {
121 solver_->setParameters (
params);
129 (problem_.is_null () || problem_->getOperator ().is_null (),
130 std::runtime_error,
"Belos::Details::LinearSolver::symbolic: "
131 "The matrix A in the linear system to solve has not yet been set. "
132 "Please call setMatrix() with a nonnull input before calling this method.");
137 solver_ = Teuchos::null;
143 (problem_.is_null () || problem_->getOperator ().is_null (),
144 std::runtime_error,
"Belos::Details::LinearSolver::numeric: "
145 "The matrix A in the linear system to solve has not yet been set. "
146 "Please call setMatrix() with a nonnull input before calling this method.");
152 problem_->setProblem ();
157 std::string solverName_;
159 Teuchos::RCP<problem_type> problem_;
161 Teuchos::RCP<solver_type> solver_;
163 Teuchos::RCP<Teuchos::ParameterList> params_;
Belos' implementation of Trilinos::Details::LinearSolver.
void setParameters(const Teuchos::RCP< Teuchos::ParameterList > ¶ms)
Set the solver's parameters.
void symbolic()
Precompute for matrix structure changes.
void setMatrix(const Teuchos::RCP< const OP > &A)
Set the solver's matrix.
Teuchos::RCP< const OP > getMatrix() const
Get the solver's matrix.
LinearSolver(const std::string &solverName)
Constructor.
virtual ~LinearSolver()
Destructor (virtual for memory safety).
void numeric()
Precompute for matrix values' changes.
void solve(MV &X, const MV &B)
Solve the linear system AX=B for X.
Alternative run-time polymorphic interface for operators.