10#ifndef THYRA_SILLY_POWER_METHOD_HPP
11#define THYRA_SILLY_POWER_METHOD_HPP
13#include "Thyra_LinearOpBase.hpp"
14#include "Thyra_VectorStdOps.hpp"
31 const int maxNumIters,
46 out <<
"\nStarting power method (target tolerance = "<<tolerance<<
") ...\n\n";
47 VectorPtr q = createMember(A.
domain()), z = createMember(A.
range()), r = createMember(A.
range());
48 Thyra::seed_randomize<Scalar>(0);
49 Thyra::randomize( Scalar(-one), Scalar(+one), z.ptr() );
52 for(
int iter = 0; iter < maxNumIters; ++iter ) {
53 const ScalarMag z_nrm = norm(*z);
54 V_StV( q.ptr(), Scalar(one/z_nrm), *z );
55 apply<Scalar>( A, NOTRANS , *q, z.ptr() );
56 *lambda = scalarProd(*q,*z);
57 if( iter%(maxNumIters/10) == 0 || iter+1 == maxNumIters ) {
58 V_StVpV(r.ptr(),Scalar(-*lambda),*q,*z);
59 const ScalarMag r_nrm = norm(*r);
60 out <<
"Iter = " << iter <<
", lambda = " << (*lambda)
61 <<
", ||A*q-lambda*q|| = " << r_nrm << std::endl;
62 if( r_nrm < tolerance )
67 out <<
"\nMaximum number of iterations exceeded with ||-lambda*q + z||"
68 " > tolerence = " << tolerance <<
"\n";
Base class for all linear operators.
virtual RCP< const VectorSpaceBase< Scalar > > range() const =0
Return a smart pointer for the range space for this operator.
virtual RCP< const VectorSpaceBase< Scalar > > domain() const =0
Return a smart pointer for the domain space for this operator.
@ NOTRANS
Use the non-transposed operator.