49 #ifndef IFPACK2_KRYLOV_DEF_HPP 50 #define IFPACK2_KRYLOV_DEF_HPP 56 template <
class MatrixType,
class PrecType>
59 Comm_(A->getRowMap()->getComm()),
63 ResidualTolerance_(0.001),
65 ZeroStartingSolution_(true),
66 PreconditionerType_(1),
69 IsInitialized_(false),
77 Time_(
"Ifpack2::Krylov"),
81 TEUCHOS_TEST_FOR_EXCEPTION(A_ == Teuchos::null, std::runtime_error,
82 Teuchos::typeName(*
this) <<
"::Krylov(): input matrix reference was null.");
86 template <
class MatrixType,
class PrecType>
91 template <
class MatrixType,
class PrecType>
94 using Teuchos::Exceptions::InvalidParameterName;
95 using Teuchos::Exceptions::InvalidParameterType;
107 template <
class MatrixType,
class PrecType>
108 const Teuchos::RCP<const Teuchos::Comm<int> > &
114 template <
class MatrixType,
class PrecType>
115 Teuchos::RCP<const Tpetra::RowMatrix<typename MatrixType::scalar_type,typename MatrixType::local_ordinal_type,typename MatrixType::global_ordinal_type,typename MatrixType::node_type> >
121 template <
class MatrixType,
class PrecType>
122 const Teuchos::RCP<const Tpetra::Map<typename MatrixType::local_ordinal_type,typename MatrixType::global_ordinal_type,typename MatrixType::node_type> >&
125 return A_->getDomainMap();
129 template <
class MatrixType,
class PrecType>
130 const Teuchos::RCP<const Tpetra::Map<typename MatrixType::local_ordinal_type,typename MatrixType::global_ordinal_type,typename MatrixType::node_type> >&
133 return A_->getRangeMap();
137 template <
class MatrixType,
class PrecType>
143 template <
class MatrixType,
class PrecType>
145 return(NumInitialize_);
149 template <
class MatrixType,
class PrecType>
155 template <
class MatrixType,
class PrecType>
161 template <
class MatrixType,
class PrecType>
163 return(InitializeTime_);
167 template <
class MatrixType,
class PrecType>
169 return(ComputeTime_);
173 template <
class MatrixType,
class PrecType>
179 template <
class MatrixType,
class PrecType>
185 const Teuchos::Ptr<
const Tpetra::RowMatrix<scalar_type,local_ordinal_type,global_ordinal_type,node_type> > &matrix) {
190 if (Condest_ == -1.0) {
191 Condest_ = Ifpack2::Condest(*
this, CT, MaxIters, Tol, matrix);
197 template <
class MatrixType,
class PrecType>
200 IsInitialized_ =
false;
204 TEUCHOS_TEST_FOR_EXCEPTION(Comm_->getSize() == 1 && A_->getNodeNumRows() != A_->getNodeNumCols(), std::runtime_error,
"Ifpack2::Krylov::Initialize ERROR, matrix must be square");
205 NumMyRows_ = A_->getNodeNumRows();
207 belosList_ = Teuchos::rcp(
new Teuchos::ParameterList(
"GMRES") );
208 belosList_->set(
"Maximum Iterations",Iterations_);
209 belosList_->set(
"Convergence Tolerance",ResidualTolerance_);
210 if(PreconditionerType_==0) {
213 else if(PreconditionerType_==1) {
216 else if(PreconditionerType_==2) {
219 else if(PreconditionerType_==3) {
224 else if(PreconditionerType_==4) {
225 ifpack2_prec_=Teuchos::rcp(
new Chebyshev<MatrixType>(A_) );
227 if(PreconditionerType_>0) {
228 ifpack2_prec_->initialize();
229 ifpack2_prec_->setParameters(params_);
232 belosProblem_ -> setOperator(A_);
233 if(IterationType_==1) {
241 IsInitialized_ =
true;
244 InitializeTime_ += Time_.totalElapsedTime();
248 template <
class MatrixType,
class PrecType>
259 if(PreconditionerType_>0) {
260 ifpack2_prec_->compute();
261 belosProblem_->setLeftPrec(ifpack2_prec_);
266 ComputeTime_ += Time_.totalElapsedTime();
270 template <
class MatrixType,
class PrecType>
272 typename MatrixType::local_ordinal_type,
273 typename MatrixType::global_ordinal_type,
274 typename MatrixType::node_type>& X,
275 Tpetra::MultiVector<
typename MatrixType::scalar_type,
276 typename MatrixType::local_ordinal_type,
277 typename MatrixType::global_ordinal_type,
278 typename MatrixType::node_type>& Y,
279 Teuchos::ETransp mode,
280 typename MatrixType::scalar_type alpha,
281 typename MatrixType::scalar_type beta)
const 283 TEUCHOS_TEST_FOR_EXCEPTION(!
isComputed(), std::runtime_error,
284 "Ifpack2::Krylov::apply() ERROR, compute() hasn't been called yet.");
286 TEUCHOS_TEST_FOR_EXCEPTION(X.getNumVectors() != Y.getNumVectors(), std::runtime_error,
287 "Ifpack2::Krylov::apply() ERROR, X.getNumVectors() != Y.getNumVectors().");
293 Teuchos::RCP< const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> > Xcopy;
294 if (X.getLocalMV().getValues() == Y.getLocalMV().getValues()) {
295 Xcopy = Teuchos::rcp(
new Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>(X) );
298 Xcopy = Teuchos::rcp( &X,
false );
301 const Teuchos::RCP< Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> > Zeros =
302 Teuchos::rcp(
new Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> (Y) );
303 if(ZeroStartingSolution_==
true) {
308 belosProblem_->setProblem(Zeros,Xcopy);
310 belosSolver_->solve();
315 ApplyTime_ += Time_.totalElapsedTime();
319 template <
class MatrixType,
class PrecType>
321 std::ostringstream oss;
322 oss << Teuchos::Describable::description();
325 oss <<
"{status = initialized, computed";
328 oss <<
"{status = initialized, not computed";
332 oss <<
"{status = not initialized, not computed";
334 oss <<
", global rows = " << A_->getGlobalNumRows()
335 <<
", global cols = " << A_->getGlobalNumCols()
341 template <
class MatrixType,
class PrecType>
345 using Teuchos::VERB_DEFAULT;
346 using Teuchos::VERB_NONE;
347 using Teuchos::VERB_LOW;
348 using Teuchos::VERB_MEDIUM;
349 using Teuchos::VERB_HIGH;
350 using Teuchos::VERB_EXTREME;
351 Teuchos::EVerbosityLevel vl = verbLevel;
352 if (vl == VERB_DEFAULT) vl = VERB_LOW;
353 const int myImageID = Comm_->getRank();
354 Teuchos::OSTab tab(out);
360 if (vl != VERB_NONE && myImageID == 0) {
virtual ~Krylov()
Krylov Destructor.
Definition: Ifpack2_Krylov_def.hpp:87
CondestType
Ifpack2::CondestType: enum to define the type of condition number estimate.
Definition: Ifpack2_CondestType.hpp:50
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with some verbosity level to an FancyOStream object.
Definition: Ifpack2_Krylov_def.hpp:342
double getComputeTime() const
Returns the time spent in Compute().
Definition: Ifpack2_Krylov_def.hpp:168
int getNumInitialize() const
Returns the number of calls to Initialize().
Definition: Ifpack2_Krylov_def.hpp:144
Krylov(const Teuchos::RCP< const Tpetra::RowMatrix< scalar_type, local_ordinal_type, global_ordinal_type, node_type > > &A)
Krylov explicit constuctor with Tpetra::RowMatrix input.
Definition: Ifpack2_Krylov_def.hpp:57
const Teuchos::RCP< const Tpetra::Map< local_ordinal_type, global_ordinal_type, node_type > > & getRangeMap() const
Tpetra::Map representing the range of this operator.
Definition: Ifpack2_Krylov_def.hpp:131
std::string description() const
Return a simple one-line description of this object.
Definition: Ifpack2_Krylov_def.hpp:320
void getParameter(const Teuchos::ParameterList ¶ms, const std::string &name, T &value)
Set a value from a ParameterList if a parameter with the specified name exists.
Definition: Ifpack2_Parameters.hpp:59
bool isInitialized() const
Returns true if the preconditioner has been successfully initialized.
Definition: Ifpack2_Krylov_decl.hpp:187
magnitude_type computeCondEst(CondestType CT=Cheap, local_ordinal_type MaxIters=1550, magnitude_type Tol=1e-9, const Teuchos::Ptr< const Tpetra::RowMatrix< scalar_type, local_ordinal_type, global_ordinal_type, node_type > > &Matrix_in=Teuchos::null)
Computes the estimated condition number and returns the value.
Definition: Ifpack2_Krylov_def.hpp:182
const Teuchos::RCP< const Teuchos::Comm< int > > & getComm() const
Returns the Tpetra::BlockMap object associated with the range of this matrix operator.
Definition: Ifpack2_Krylov_def.hpp:109
void apply(const Tpetra::MultiVector< scalar_type, local_ordinal_type, global_ordinal_type, node_type > &X, Tpetra::MultiVector< scalar_type, local_ordinal_type, global_ordinal_type, node_type > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, scalar_type alpha=Teuchos::ScalarTraits< scalar_type >::one(), scalar_type beta=Teuchos::ScalarTraits< scalar_type >::zero()) const
Returns the result of a few iterations of CG/GMRES on a Tpetra::MultiVector X in Y.
Definition: Ifpack2_Krylov_def.hpp:271
ILUT incomplete factorization of a Tpetra sparse matrix.
Definition: Ifpack2_ILUT_decl.hpp:96
void setParameters(const Teuchos::ParameterList ¶ms)
Set parameters for the preconditioner.
Definition: Ifpack2_Krylov_def.hpp:92
double getApplyTime() const
Returns the time spent in apply().
Definition: Ifpack2_Krylov_def.hpp:174
Teuchos::RCP< const Tpetra::RowMatrix< scalar_type, local_ordinal_type, global_ordinal_type, node_type > > getMatrix() const
Returns a reference to the matrix to be preconditioned.
Definition: Ifpack2_Krylov_def.hpp:116
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input MatrixType.
Definition: Ifpack2_Krylov_decl.hpp:127
const Teuchos::RCP< const Tpetra::Map< local_ordinal_type, global_ordinal_type, node_type > > & getDomainMap() const
Tpetra::Map representing the domain of this operator.
Definition: Ifpack2_Krylov_def.hpp:123
void compute()
Setup iteration.
Definition: Ifpack2_Krylov_def.hpp:249
MatrixType::scalar_type scalar_type
The type of the entries of the input MatrixType.
Definition: Ifpack2_Krylov_decl.hpp:117
bool hasTransposeApply() const
Whether this object's apply() method can apply the transpose (or conjugate transpose, if applicable).
Definition: Ifpack2_Krylov_def.hpp:138
int getNumApply() const
Returns the number of calls to apply().
Definition: Ifpack2_Krylov_def.hpp:156
bool isComputed() const
If compute() is completed, this query returns true, otherwise it returns false.
Definition: Ifpack2_Krylov_decl.hpp:202
void initialize()
Initialize Krylov preconditioner object.
Definition: Ifpack2_Krylov_def.hpp:198
double getInitializeTime() const
Returns the time spent in Initialize().
Definition: Ifpack2_Krylov_def.hpp:162
Teuchos::ScalarTraits< scalar_type >::magnitudeType magnitude_type
The type of the magnitude (absolute value) of a matrix entry.
Definition: Ifpack2_Krylov_decl.hpp:148
Additive Schwarz domain decomposition for Tpetra::RowMatrix objects.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:123
int getNumCompute() const
Returns the number of calls to Compute().
Definition: Ifpack2_Krylov_def.hpp:150
Relaxation preconditioners for Tpetra::RowMatrix and Tpetra::CrsMatrix sparse matrices.
Definition: Ifpack2_Relaxation_decl.hpp:231
Ifpack2::Container: a pure virtual class for creating and solving local linear problems.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:67