42 #ifndef BELOS_DETAILS_LINEARSOLVER_HPP 43 #define BELOS_DETAILS_LINEARSOLVER_HPP 49 #include "Trilinos_Details_LinearSolver.hpp" 75 template<
class MV,
class OP,
class ScalarType,
class NormType>
77 public Trilinos::Details::LinearSolver<MV, OP, NormType>
92 solverName_ (solverName)
107 if (problem_.is_null ()) {
108 problem_ = Teuchos::rcp (
new problem_type (A, Teuchos::null, Teuchos::null));
109 }
else if (A != problem_->getOperator ()) {
110 problem_->setOperator (A);
116 if (problem_.is_null ()) {
117 return Teuchos::null;
119 return problem_->getOperator ();
125 TEUCHOS_TEST_FOR_EXCEPTION
126 (problem_.is_null () || problem_->getOperator ().is_null (),
127 std::runtime_error,
"Belos::Details::LinearSolver::solve: " 128 "The matrix A in the linear system to solve has not yet been set. " 129 "Please call setMatrix() with a nonnull input before calling solve().");
130 Teuchos::RCP<MV> X_ptr = Teuchos::rcpFromRef (X);
131 Teuchos::RCP<const MV> B_ptr = Teuchos::rcpFromRef (B);
133 problem_->setLHS (X_ptr);
134 problem_->setRHS (B_ptr);
135 problem_->setProblem ();
140 if (solver_.is_null ()) {
142 solver_ = factory.
create (solverName_, params_);
143 solver_->setProblem (problem_);
147 (void) solver_->solve ();
152 if (! solver_.is_null () && ! params.is_null ()) {
153 solver_->setParameters (params);
160 TEUCHOS_TEST_FOR_EXCEPTION
161 (problem_.is_null () || problem_->getOperator ().is_null (),
162 std::runtime_error,
"Belos::Details::LinearSolver::symbolic: " 163 "The matrix A in the linear system to solve has not yet been set. " 164 "Please call setMatrix() with a nonnull input before calling this method.");
169 solver_ = Teuchos::null;
174 TEUCHOS_TEST_FOR_EXCEPTION
175 (problem_.is_null () || problem_->getOperator ().is_null (),
176 std::runtime_error,
"Belos::Details::LinearSolver::numeric: " 177 "The matrix A in the linear system to solve has not yet been set. " 178 "Please call setMatrix() with a nonnull input before calling this method.");
184 problem_->setProblem ();
189 std::string solverName_;
191 Teuchos::RCP<problem_type> problem_;
193 Teuchos::RCP<solver_type> solver_;
195 Teuchos::RCP<Teuchos::ParameterList> params_;
void solve(MV &X, const MV &B)
Solve the linear system AX=B for X.
Belos' implementation of Trilinos::Details::LinearSolver.
virtual ~LinearSolver()
Destructor (virtual for memory safety).
void setMatrix(const Teuchos::RCP< const OP > &A)
Set the solver's matrix.
void symbolic()
Precompute for matrix structure changes.
void numeric()
Precompute for matrix values' changes.
Teuchos::RCP< const OP > getMatrix() const
Get the solver's matrix.
A linear system to solve, and its associated information.
LinearSolver(const std::string &solverName)
Constructor.
The Belos::SolverManager is a templated virtual base class that defines the basic interface that any ...
Teuchos::RCP< solver_base_type > create(const std::string &solverName, const Teuchos::RCP< Teuchos::ParameterList > &solverParams)
Create, configure, and return the specified solver.
void setParameters(const Teuchos::RCP< Teuchos::ParameterList > ¶ms)
Set the solver's parameters.
Factory for all solvers which Belos supports.