48 #ifndef IFPACK2_DETAILS_LINEARSOLVER_DEF_HPP
49 #define IFPACK2_DETAILS_LINEARSOLVER_DEF_HPP
64 template<
class SC,
class LO,
class GO,
class NT>
66 LinearSolver (
const Teuchos::RCP<prec_type>& solver,
const std::string& solverName) :
68 solverName_ (solverName)
71 using Teuchos::rcp_dynamic_cast;
72 const char prefix[] =
"Ifpack2::Details::LinearSolver: ";
73 TEUCHOS_TEST_FOR_EXCEPTION(solver.is_null (), std::invalid_argument,
74 prefix <<
"Input solver is NULL.");
76 typedef Tpetra::RowMatrix<SC, LO, GO, NT> row_matrix_type;
77 typedef ::Ifpack2::Details::CanChangeMatrix<row_matrix_type> mixin_type;
78 RCP<mixin_type> innerSolver = rcp_dynamic_cast<mixin_type> (solver);
79 TEUCHOS_TEST_FOR_EXCEPTION
80 (innerSolver.is_null (), std::invalid_argument, prefix <<
"The input "
81 "solver does not implement the setMatrix() feature. Only Ifpack2 solvers "
82 "that inherit from Ifpack2::Details::CanChangeMatrix implement this feature.");
85 template<
class SC,
class LO,
class GO,
class NT>
91 using Teuchos::rcp_dynamic_cast;
92 typedef Tpetra::RowMatrix<SC, LO, GO, NT> row_matrix_type;
93 typedef ::Ifpack2::Details::CanChangeMatrix<row_matrix_type> mixin_type;
94 const char prefix[] =
"Ifpack2::Details::LinearSolver::setMatrix: ";
101 RCP<const row_matrix_type> A_row;
102 if (! A.is_null ()) {
103 A_row = rcp_dynamic_cast<const row_matrix_type> (A);
104 TEUCHOS_TEST_FOR_EXCEPTION
105 (A_row.is_null (), std::invalid_argument, prefix <<
"The input matrix A, "
106 "if not null, must be a Tpetra::RowMatrix.");
108 TEUCHOS_TEST_FOR_EXCEPTION
109 (solver_.is_null (), std::logic_error, prefix <<
"Solver is NULL. "
110 "This should never happen! Please report this bug to the Ifpack2 "
113 RCP<mixin_type> innerSolver = rcp_dynamic_cast<mixin_type> (solver_);
114 TEUCHOS_TEST_FOR_EXCEPTION
115 (innerSolver.is_null (), std::logic_error, prefix <<
"The solver does not "
116 "implement the setMatrix() feature. Only input preconditioners that "
117 "inherit from Ifpack2::Details::CanChangeMatrix implement this. We should"
118 " never get here! Please report this bug to the Ifpack2 developers.");
119 innerSolver->setMatrix (A_row);
124 template<
class SC,
class LO,
class GO,
class NT>
125 Teuchos::RCP<const typename LinearSolver<SC, LO, GO, NT>::OP>
131 template<
class SC,
class LO,
class GO,
class NT>
136 const char prefix[] =
"Ifpack2::Details::LinearSolver::solve: ";
137 TEUCHOS_TEST_FOR_EXCEPTION
138 (solver_.is_null (), std::logic_error, prefix <<
"The solver is NULL! "
139 "This should never happen. Please report this bug to the Ifpack2 "
141 TEUCHOS_TEST_FOR_EXCEPTION
142 (A_.is_null (), std::runtime_error, prefix <<
"The matrix has not been "
143 "set yet. You must call setMatrix() with a nonnull matrix before you "
144 "may call this method.");
145 solver_->apply (B, X);
148 template<
class SC,
class LO,
class GO,
class NT>
153 solver_->setParameters (*params);
156 template<
class SC,
class LO,
class GO,
class NT>
161 const char prefix[] =
"Ifpack2::Details::LinearSolver::symbolic: ";
162 TEUCHOS_TEST_FOR_EXCEPTION
163 (solver_.is_null (), std::logic_error, prefix <<
"The solver is NULL! "
164 "This should never happen. Please report this bug to the Ifpack2 "
166 TEUCHOS_TEST_FOR_EXCEPTION
167 (A_.is_null (), std::runtime_error, prefix <<
"The matrix has not been "
168 "set yet. You must call setMatrix() with a nonnull matrix before you "
169 "may call this method.");
170 solver_->initialize ();
173 template<
class SC,
class LO,
class GO,
class NT>
178 const char prefix[] =
"Ifpack2::Details::LinearSolver::numeric: ";
179 TEUCHOS_TEST_FOR_EXCEPTION
180 (solver_.is_null (), std::logic_error, prefix <<
"The solver is NULL! "
181 "This should never happen. Please report this bug to the Ifpack2 "
183 TEUCHOS_TEST_FOR_EXCEPTION
184 (A_.is_null (), std::runtime_error, prefix <<
"The matrix has not been "
185 "set yet. You must call setMatrix() with a nonnull matrix before you "
186 "may call this method.");
190 template<
class SC,
class LO,
class GO,
class NT>
195 const char prefix[] =
"Ifpack2::Details::LinearSolver::description: ";
196 TEUCHOS_TEST_FOR_EXCEPTION
197 (solver_.is_null (), std::logic_error, prefix <<
"The solver is NULL! "
198 "This should never happen. Please report this bug to the Ifpack2 "
200 return solver_->description ();
203 template<
class SC,
class LO,
class GO,
class NT>
207 const Teuchos::EVerbosityLevel verbLevel)
const
209 const char prefix[] =
"Ifpack2::Details::LinearSolver::describe: ";
210 TEUCHOS_TEST_FOR_EXCEPTION
211 (solver_.is_null (), std::logic_error, prefix <<
"The solver is NULL! "
212 "This should never happen. Please report this bug to the Ifpack2 "
214 solver_->describe (out, verbLevel);
223 #define IFPACK2_DETAILS_LINEARSOLVER_INSTANT(SC, LO, GO, NT) \
224 template class Ifpack2::Details::LinearSolver<SC, LO, GO, NT>;
226 #endif // IFPACK2_DETAILS_LINEARSOLVER_DEF_HPP