43 #ifndef IFPACK2_CHEBYSHEV_DEF_HPP 44 #define IFPACK2_CHEBYSHEV_DEF_HPP 49 template<
class MatrixType>
50 Chebyshev<MatrixType>::
51 Chebyshev (
const Teuchos::RCP<const row_matrix_type>& A)
55 IsInitialized_ (false),
60 InitializeTime_ (0.0),
65 {this->setObjectLabel(
"Ifpack2::Chebyshev");}
68 template<
class MatrixType>
69 Chebyshev<MatrixType>::~Chebyshev() {
73 template<
class MatrixType>
78 impl_.
setParameters (const_cast<Teuchos::ParameterList&> (List));
83 template<
class MatrixType>
84 const Teuchos::RCP<const Teuchos::Comm<int> > &
86 return impl_.
getMatrix ()->getRowMap ()->getComm ();
90 template<
class MatrixType>
91 Teuchos::RCP<const typename Chebyshev<MatrixType>::row_matrix_type>
98 template<
class MatrixType>
99 const Teuchos::RCP<const typename Chebyshev<MatrixType>::map_type>&
102 return impl_.
getMatrix ()->getDomainMap ();
106 template<
class MatrixType>
107 const Teuchos::RCP<const typename Chebyshev<MatrixType>::map_type>&
110 return impl_.
getMatrix ()->getRangeMap ();
114 template<
class MatrixType>
120 template<
class MatrixType>
122 return(NumInitialize_);
126 template<
class MatrixType>
132 template<
class MatrixType>
138 template<
class MatrixType>
140 return(InitializeTime_);
144 template<
class MatrixType>
146 return(ComputeTime_);
150 template<
class MatrixType>
156 template<
class MatrixType>
158 return(ComputeFlops_);
162 template<
class MatrixType>
168 template<
class MatrixType>
176 template<
class MatrixType>
180 local_ordinal_type MaxIters,
182 const Teuchos::Ptr<const row_matrix_type>& matrix)
184 if (! isComputed ()) {
185 return -Teuchos::ScalarTraits<magnitude_type>::one ();
190 Condest_ = Ifpack2::Condest (*
this, CT, MaxIters, Tol, matrix);
196 template<
class MatrixType>
199 apply (
const Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& X,
200 Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& Y,
201 Teuchos::ETransp mode,
203 scalar_type beta)
const 206 Teuchos::TimeMonitor timeMon (*Time_);
210 TEUCHOS_TEST_FOR_EXCEPTION(! isComputed(), std::runtime_error,
211 "Ifpack2::Chebyshev::apply(): You must call the compute() method before " 212 "you may call apply().");
213 TEUCHOS_TEST_FOR_EXCEPTION(
214 X.getNumVectors() != Y.getNumVectors(),
216 "Ifpack2::Chebyshev::apply(): X and Y must have the same number of " 217 "columns. X.getNumVectors() = " << X.getNumVectors() <<
" != " 218 <<
"Y.getNumVectors() = " << Y.getNumVectors() <<
".");
219 #ifdef HAVE_TEUCHOS_DEBUG 224 TEUCHOS_TEST_FOR_EXCEPTION(
227 "Ifpack2::Chebyshev: The domain Map of the matrix must be the same as " 228 "the Map of the input vector(s) X.");
229 TEUCHOS_TEST_FOR_EXCEPTION(
232 "Ifpack2::Chebyshev: The range Map of the matrix must be the same as " 233 "the Map of the output vector(s) Y.");
235 #endif // HAVE_TEUCHOS_DEBUG 236 applyImpl (X, Y, mode, alpha, beta);
239 ApplyTime_ += Time_->totalElapsedTime ();
243 template<
class MatrixType>
246 applyMat (
const Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& X,
247 Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& Y,
248 Teuchos::ETransp mode)
const 250 TEUCHOS_TEST_FOR_EXCEPTION(X.getNumVectors() != Y.getNumVectors(), std::runtime_error,
251 "Ifpack2::Chebyshev::applyMat(): X.getNumVectors() != Y.getNumVectors().");
256 template<
class MatrixType>
259 IsInitialized_ =
true;
269 template<
class MatrixType>
273 Teuchos::TimeMonitor timeMon (*Time_);
274 if (! isInitialized ()) {
283 ComputeTime_ += Time_->totalElapsedTime();
287 template<
class MatrixType>
290 PowerMethod (
const Tpetra::Operator<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& Operator,
291 const Tpetra::Vector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& InvPointDiagonal,
292 const int MaximumIterations,
293 scalar_type& lambda_max)
295 const scalar_type one = STS::one();
296 const scalar_type zero = STS::zero();
299 Teuchos::Array<scalar_type> RQ_top(1), RQ_bottom(1);
300 vector_type x (Operator.getDomainMap ());
301 vector_type y (Operator.getRangeMap ());
303 Teuchos::Array<magnitude_type> norms (x.getNumVectors ());
305 x.scale (one / norms[0]);
307 for (
int iter = 0; iter < MaximumIterations; ++iter) {
308 Operator.apply (x, y);
309 y.elementWiseMultiply (one, InvPointDiagonal, y, zero);
310 y.dot (x, RQ_top ());
311 x.dot (x, RQ_bottom ());
312 lambda_max = RQ_top[0] / RQ_bottom[0];
314 TEUCHOS_TEST_FOR_EXCEPTION(
317 "Ifpack2::Chebyshev::PowerMethod: norm == 0 at iteration " << (iter+1)
318 <<
" of " << MaximumIterations);
319 x.update (one / norms[0], y, zero);
324 template<
class MatrixType>
326 CG(
const Tpetra::Operator<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Operator,
327 const Tpetra::Vector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& InvPointDiagonal,
328 const int MaximumIterations,
329 scalar_type& lambda_min, scalar_type& lambda_max)
331 TEUCHOS_TEST_FOR_EXCEPTION(
332 true, std::logic_error,
333 "Ifpack2::Chebyshev::CG: Not implemented. " 334 "Please use Belos' implementation of CG with Tpetra objects.");
338 template <
class MatrixType>
340 std::ostringstream oss;
341 oss << Teuchos::LabeledObject::getObjectLabel();
342 if (isInitialized()) {
344 oss <<
"{status = initialized, computed, ";
347 oss <<
"{status = initialized, not computed, ";
351 oss <<
"{status = not initialized, not computed, ";
354 oss << impl_.description();
356 oss <<
", global rows = " << impl_.getMatrix ()->getGlobalNumRows()
357 <<
", global cols = " << impl_.getMatrix ()->getGlobalNumCols()
363 template <
class MatrixType>
368 using Teuchos::VERB_DEFAULT;
369 using Teuchos::VERB_NONE;
370 using Teuchos::VERB_LOW;
371 using Teuchos::VERB_MEDIUM;
372 using Teuchos::VERB_HIGH;
373 using Teuchos::VERB_EXTREME;
377 Teuchos::EVerbosityLevel vl = verbLevel;
378 if (vl == VERB_DEFAULT) {
381 RCP<const Comm<int> > comm = A_->getRowMap ()->getComm ();
383 const int myImageID = comm->getRank();
384 Teuchos::OSTab tab(out);
386 scalar_type MinVal, MaxVal;
388 Teuchos::ArrayRCP<const scalar_type> DiagView = InvDiagonal_->get1dView();
389 scalar_type myMinVal = DiagView[0];
390 scalar_type myMaxVal = DiagView[0];
391 for(
typename Teuchos::ArrayRCP<scalar_type>::size_type i=1; i<DiagView.size(); ++i) {
392 if (STS::magnitude(myMinVal) > STS::magnitude(DiagView[i])) myMinVal = DiagView[i];
393 if (STS::magnitude(myMaxVal) < STS::magnitude(DiagView[i])) myMaxVal = DiagView[i];
395 Teuchos::reduceAll(*comm, Teuchos::REDUCE_MIN, 1, &myMinVal, &MinVal);
396 Teuchos::reduceAll(*comm, Teuchos::REDUCE_MAX, 1, &myMaxVal, &MaxVal);
404 if (vl != VERB_NONE && myImageID == 0) {
405 out << this->description() << endl;
407 out <<
"===============================================================================" << std::endl;
408 out <<
"Degree of polynomial = " << PolyDegree_ << std::endl;
409 if (ZeroStartingSolution_) { out <<
"Using zero starting solution" << endl; }
410 else { out <<
"Using input starting solution" << endl; }
411 if (Condest_ == -1.0) { out <<
"Condition number estimate = N/A" << endl; }
412 else { out <<
"Condition number estimate = " << Condest_ << endl; }
414 out <<
"Minimum value on stored inverse diagonal = " << MinVal << std::endl;
415 out <<
"Maximum value on stored inverse diagonal = " << MaxVal << std::endl;
418 out <<
"Phase # calls Total Time (s) Total MFlops MFlops/s " << endl;
419 out <<
"------------ ------- --------------- --------------- ---------------" << endl;
420 out << setw(12) <<
"initialize()" << setw(5) << getNumInitialize() <<
" " << setw(15) << getInitializeTime() << endl;
421 out << setw(12) <<
"compute()" << setw(5) << getNumCompute() <<
" " << setw(15) << getComputeTime() <<
" " 422 << setw(15) << getComputeFlops() <<
" " 423 << setw(15) << (getComputeTime() != 0.0 ? getComputeFlops() / getComputeTime() * 1.0e-6 : 0.0) << endl;
424 out << setw(12) <<
"apply()" << setw(5) << getNumApply() <<
" " << setw(15) << getApplyTime() <<
" " 425 << setw(15) << getApplyFlops() <<
" " 426 << setw(15) << (getApplyTime() != 0.0 ? getApplyFlops() / getApplyTime() * 1.0e-6 : 0.0) << endl;
427 out <<
"===============================================================================" << std::endl;
433 template<
class MatrixType>
438 Teuchos::ETransp mode,
440 scalar_type beta)
const 442 using Teuchos::ArrayRCP;
446 using Teuchos::rcp_const_cast;
447 using Teuchos::rcpFromRef;
449 const scalar_type zero = STS::zero();
450 const scalar_type one = STS::one();
471 Y_orig = rcp (
new MV (Y));
480 RCP<const MV> X_copy;
481 bool copiedInput =
false;
482 if (X.getLocalMV().getValues() == Y.getLocalMV().getValues()) {
483 X_copy = rcp (
new MV (X));
487 X_copy = rcpFromRef (X);
496 RCP<MV> X_copy_nonConst = rcp_const_cast<MV> (X_copy);
498 X_copy_nonConst = rcp (
new MV (X));
501 X_copy_nonConst->scale (alpha);
502 X_copy = rcp_const_cast<
const MV> (X_copy_nonConst);
505 impl_.apply (*X_copy, Y);
508 Y.update (beta, *Y_orig, one);
513 template<
class MatrixType>
515 return impl_.getLambdaMaxForApply();
521 #endif // IFPACK2_CHEBYSHEV_DEF_HPP CondestType
Ifpack2::CondestType: enum to define the type of condition number estimate.
Definition: Ifpack2_CondestType.hpp:50
virtual const Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > & getDomainMap() const
Returns the Map associated with the domain of this operator, which must be compatible with X...
Definition: Ifpack2_BorderedOperator_def.hpp:69
Left-scaled Chebyshev iteration.
Definition: Ifpack2_Details_Chebyshev_decl.hpp:128
void setParameters(Teuchos::ParameterList &plist)
Set (or reset) parameters.
Definition: Ifpack2_Chebyshev_def.hpp:75
Definition: Ifpack2_BlockRelaxation_decl.hpp:64
bool hasTransposeApply() const
Whether it's possible to apply the transpose of this operator.
Definition: Ifpack2_Chebyshev_def.hpp:115
Ifpack2::Container: a pure virtual class for creating and solving local linear problems.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:67
Teuchos::RCP< const MAT > getMatrix() const
Get the matrix given to the constructor.
Definition: Ifpack2_Chebyshev_def.hpp:93
virtual const Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > & getRangeMap() const
Returns the Map associated with the range of this operator, which must be compatible with Y...
Definition: Ifpack2_BorderedOperator_def.hpp:76