Loading...
Searching...
No Matches
power_iteration.hpp
Go to the documentation of this file.
1#pragma once
2
4
6
7/// @brief Power iteration to estimate the largest eigenvalue of a
8/// row-normalized operator D^{-1}A, where D^{-1} is the inverted diagonal of A.
9///
10/// @tparam OperatorT Operator type (must satisfy OperatorLike).
11template < terra::linalg::OperatorLike OperatorT >
12//template<typename OperatorT>
14 OperatorT& op,
15 SrcOf< OperatorT >& tmpIt,
16 SrcOf< OperatorT >& tmpAux,
17 //VectorQ1Scalar< double>& tmpIt,
18 //VectorQ1Scalar< double>& tmpAux,
19 const int iterations )
20{
21 // TODO typecheck on src dst
22
23 // randomize start
24 randomize( tmpIt );
25
26 // normalize
27 auto norm = linalg::norm_2( tmpIt );
28 lincomb( tmpIt, { 1.0 / norm }, { tmpIt }, 0.0 );
29
30 // apply operator
31 apply( op, tmpIt, tmpAux );
32
33 auto radius = 0.0;
34 for ( int iteration = 0; iteration < iterations; ++iteration )
35 {
36 // normalize
37 norm = linalg::norm_2( tmpAux );
38 lincomb( tmpIt, { 1.0 / norm }, { tmpAux }, 0.0 );
39
40 // apply operator
41 apply( op, tmpIt, tmpAux );
42
43 // compute radius
44 radius = dot( tmpIt, tmpAux );
45 }
46 return radius;
47}
48
49} // namespace terra::linalg::solvers
Definition block_preconditioner_2x2.hpp:7
double power_iteration(OperatorT &op, SrcOf< OperatorT > &tmpIt, SrcOf< OperatorT > &tmpAux, const int iterations)
Power iteration to estimate the largest eigenvalue of a row-normalized operator D^{-1}A,...
Definition power_iteration.hpp:13
void lincomb(Vector &y, const std::vector< ScalarOf< Vector > > &c, const std::vector< Vector > &x, const ScalarOf< Vector > &c0)
Compute a linear combination of vectors. Implements: .
Definition vector.hpp:72
ScalarOf< Vector > norm_2(const Vector &y)
Compute the 2-norm (Euclidean norm) of a vector. Implements: .
Definition vector.hpp:166
void randomize(Vector &y)
Randomize the entries of a vector. Sets each entry of to a random value.
Definition vector.hpp:146
Operator::SrcVectorType SrcOf
Alias for the source vector type of an operator.
Definition operator.hpp:145
ScalarOf< Vector > dot(const Vector &y, const Vector &x)
Compute the dot product of two vectors. Implements: .
Definition vector.hpp:118
void apply(LinearForm &L, typename LinearForm::DstVectorType &dst)
Apply a linear form and write to a destination vector.
Definition linear_form.hpp:37