43 #ifndef IFPACK2_CHEBYSHEV_DEF_HPP
44 #define IFPACK2_CHEBYSHEV_DEF_HPP
49 template<
class MatrixType>
50 Chebyshev<MatrixType>::
53 Time_ (Teuchos::
rcp (new Teuchos::Time (
"Ifpack2::Chebyshev"))),
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>
86 return impl_.
getMatrix ()->getRowMap ()->getComm ();
90 template<
class MatrixType>
92 Chebyshev<MatrixType>::
94 return impl_.getMatrix ();
98 template<
class MatrixType>
102 return impl_.
getMatrix ()->getDomainMap ();
106 template<
class MatrixType>
108 Chebyshev<MatrixType>::
109 getRangeMap()
const {
110 return impl_.getMatrix ()->getRangeMap ();
114 template<
class MatrixType>
120 template<
class MatrixType>
122 return(NumInitialize_);
126 template<
class MatrixType>
127 int Chebyshev<MatrixType>::getNumCompute()
const {
132 template<
class MatrixType>
133 int Chebyshev<MatrixType>::getNumApply()
const {
138 template<
class MatrixType>
139 double Chebyshev<MatrixType>::getInitializeTime()
const {
140 return(InitializeTime_);
144 template<
class MatrixType>
145 double Chebyshev<MatrixType>::getComputeTime()
const {
146 return(ComputeTime_);
150 template<
class MatrixType>
151 double Chebyshev<MatrixType>::getApplyTime()
const {
156 template<
class MatrixType>
157 double Chebyshev<MatrixType>::getComputeFlops()
const {
158 return(ComputeFlops_);
162 template<
class MatrixType>
163 double Chebyshev<MatrixType>::getApplyFlops()
const {
168 template<
class MatrixType>
169 typename Chebyshev<MatrixType>::magnitude_type
170 Chebyshev<MatrixType>::
176 template<
class MatrixType>
177 typename Chebyshev<MatrixType>::magnitude_type
178 Chebyshev<MatrixType>::
180 local_ordinal_type MaxIters,
184 if (! isComputed ()) {
190 Condest_ = Ifpack2::Condest (*
this, CT, MaxIters, Tol, matrix);
196 template<
class MatrixType>
198 Chebyshev<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,
203 scalar_type beta)
const
211 "Ifpack2::Chebyshev::apply(): You must call the compute() method before "
212 "you may call apply().");
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
225 ! X.getMap ()->isSameAs (*getDomainMap ()),
227 "Ifpack2::Chebyshev: The domain Map of the matrix must be the same as "
228 "the Map of the input vector(s) X.");
230 ! Y.getMap ()->isSameAs (*getRangeMap ()),
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,
251 "Ifpack2::Chebyshev::applyMat(): X.getNumVectors() != Y.getNumVectors().");
252 impl_.getMatrix ()->apply (X, Y, mode);
256 template<
class MatrixType>
257 void Chebyshev<MatrixType>::initialize() {
259 IsInitialized_ =
true;
269 template<
class MatrixType>
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();
300 vector_type x (Operator.getDomainMap ());
301 vector_type y (Operator.getRangeMap ());
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];
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>
325 void Chebyshev<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)
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>
381 RCP<const Comm<int> > comm = A_->getRowMap ()->getComm ();
383 const int myImageID = comm->getRank();
386 scalar_type MinVal, MaxVal;
389 scalar_type myMinVal = DiagView[0];
390 scalar_type myMaxVal = DiagView[0];
392 if (STS::magnitude(myMinVal) > STS::magnitude(DiagView[i])) myMinVal = DiagView[i];
393 if (STS::magnitude(myMaxVal) < STS::magnitude(DiagView[i])) myMaxVal = DiagView[i];
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>
440 scalar_type beta)
const
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>
514 typename MatrixType::scalar_type Chebyshev<MatrixType>::getLambdaMaxForApply()
const {
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
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
TEUCHOS_DEPRECATED void reduceAll(const Comm< Ordinal > &comm, const EReductionType reductType, const Packet &send, Packet *globalReduct)
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
bool hasTransposeApply() const
Whether it's possible to apply the transpose of this operator.
Definition: Ifpack2_Chebyshev_def.hpp:115
TypeTo as(const TypeFrom &t)
Teuchos::RCP< const MAT > getMatrix() const
Get the matrix given to the constructor.
Definition: Ifpack2_Chebyshev_def.hpp:93