11 #ifndef ROL_MINRES_HPP
12 #define ROL_MINRES_HPP
28 template<
typename Real>
40 std::array<Real,4>
H_;
45 void givens( Real& c, Real& s, Real& r, Real a, Real b )
const {
50 c = ( a >=
zero ? one : -one );
54 else if( a ==
zero ) {
56 s = ( b >=
zero ? one : -one );
59 else if( std::abs(a) > std::abs(b) ) {
61 auto u = std::copysign(std::sqrt(one+t*t),a);
68 auto u = std::copysign(std::sqrt(one+t*t),b);
77 MINRES( Real absTol = 1.e-4, Real relTol = 1.e-2,
unsigned maxit = 100,
bool useInexact =
false) :
79 clones_(
"v_prev",
"v_curr",
"v_next",
"w_prev",
"w_curr",
"w_next") { }
82 virtual Real
run(
V &x,
OP &A,
const V &b,
OP &M,
int &iter,
int &flag )
override {
84 auto v_prev =
clones_( x,
"v_prev" ); v_prev->zero();
85 auto v_curr =
clones_( x,
"v_curr" ); v_curr->set(b);
86 auto v_next =
clones_( x,
"v_next" ); v_next->zero();
87 auto w_prev =
clones_( x,
"w_prev" ); w_prev->zero();
88 auto w_curr =
clones_( x,
"w_curr" ); w_curr->zero();
89 auto w_next =
clones_( x,
"w_next" ); w_next->zero();
91 Real c_prev{0}, s_prev{0}, c_curr{0}, s_curr{0}, c_next{0}, s_next{0};
95 Real itol = std::sqrt(ROL_EPSILON<Real>());
97 for(
auto &e:
H_ ) e = 0;
103 for( iter=0; iter < (int)Krylov<Real>::getMaximumIteration(); iter++) {
110 A.
apply( *v_next, *v_curr, itol );
112 if( iter>0 ) v_next->axpy(-H_[1],*v_prev);
114 H_[2] = v_next->dot(*v_curr);
116 v_next->axpy(-H_[2],*v_curr);
118 H_[3] = v_next->norm();
120 v_next->scale(1.0/H_[3]);
124 H_[0] = s_prev*H_[1];
130 auto tmp = c_curr*H_[2]-s_curr*H_[1];
131 H_[1] = c_curr*H_[1] + s_curr*H_[2];
136 givens( c_next, s_next, H_[2], H_[2], H_[3] );
140 w_next->set( *v_curr );
142 if( iter>0 ) w_next->axpy( -H_[1], *w_curr );
143 if( iter>1 ) w_next->axpy( -H_[0], *w_prev );
145 w_next->scale(1.0/H_[2]);
147 x.
axpy( rhs_[0], *w_next );
149 v_prev->set( *v_curr );
150 v_curr->set( *v_next );
151 w_prev->set( *w_curr );
152 w_curr->set( *w_next );
184 #endif // ROL_MINRES_HPP
virtual Real run(V &x, OP &A, const V &b, OP &M, int &iter, int &flag) override
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
virtual void apply(Vector< Real > &Hv, const Vector< Real > &v, Real &tol) const =0
Apply linear operator.
std::array< Real, 2 > rhs_
Defines the linear algebra or vector space interface.
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0_ zero()
Provides definitions for Krylov solvers.
Provides the interface to apply a linear operator.
void givens(Real &c, Real &s, Real &r, Real a, Real b) const
VectorCloneMap< Real > clones_
Implements the MINRES algorithm for solving symmetric indefinite systems.
MINRES(Real absTol=1.e-4, Real relTol=1.e-2, unsigned maxit=100, bool useInexact=false)