42 #ifndef THYRA_SILLY_POWER_METHOD_HPP
43 #define THYRA_SILLY_POWER_METHOD_HPP
45 #include "Thyra_LinearOpBase.hpp"
46 #include "Thyra_VectorStdOps.hpp"
60 template<
class Scalar>
61 bool sillyPowerMethod(
63 const int maxNumIters,
78 out <<
"\nStarting power method (target tolerance = "<<tolerance<<
") ...\n\n";
80 Thyra::seed_randomize<Scalar>(0);
81 Thyra::randomize( Scalar(-one), Scalar(+one), z.ptr() );
84 for(
int iter = 0; iter < maxNumIters; ++iter ) {
85 const ScalarMag z_nrm =
norm(*z);
86 V_StV( q.ptr(), Scalar(one/z_nrm), *z );
87 apply<Scalar>( A,
NOTRANS , *q, z.ptr() );
89 if( iter%(maxNumIters/10) == 0 || iter+1 == maxNumIters ) {
90 V_StVpV(r.ptr(),Scalar(-*lambda),*q,*z);
91 const ScalarMag r_nrm =
norm(*r);
92 out <<
"Iter = " << iter <<
", lambda = " << (*lambda)
93 <<
", ||A*q-lambda*q|| = " << r_nrm << std::endl;
94 if( r_nrm < tolerance )
99 out <<
"\nMaximum number of iterations exceeded with ||-lambda*q + z||"
100 " > tolerence = " << tolerance <<
"\n";
106 #endif // THYRA_SILLY_POWER_METHOD_HPP
virtual RCP< const VectorSpaceBase< Scalar > > range() const =0
Return a smart pointer for the range space for this operator.
Use the non-transposed operator.
RCP< VectorBase< Scalar > > createMember(const RCP< const VectorSpaceBase< Scalar > > &vs, const std::string &label="")
Create a vector member from the vector space.
Base class for all linear operators.
virtual RCP< const VectorSpaceBase< Scalar > > domain() const =0
Return a smart pointer for the domain space for this operator.
Teuchos::ScalarTraits< Scalar >::magnitudeType norm(const VectorBase< Scalar > &v)
Natural norm: result = sqrt(<v,v>).
Scalar scalarProd(const VectorBase< Scalar > &x, const VectorBase< Scalar > &y)
Scalar product result = <x,y>.
void V_StV(const Ptr< VectorBase< Scalar > > &y, const Scalar &alpha, const VectorBase< Scalar > &x)
Assign scaled vector: y(i) = alpha * x(i), i = 0...y->space()->dim()-1.
void V_StVpV(const Ptr< MultiVectorBase< Scalar > > &Z, const Scalar &alpha, const MultiVectorBase< Scalar > &X, const MultiVectorBase< Scalar > &Y)
Z(i,j) = alpha*X(i,j) + Y(i), i = 0...z->space()->dim()-1, , j = 0...Z->domain()->dim()-1.