59 double resminreach, resadd;
70 nit = 0; res = 0.0; written =
false;
71 resminreach = 1E200; resadd = 0.0;
76 double div_res = 1E200)
77 : rhsn(1.0), maxiter(mit), noise(noi), resmax(r), diverged_res(div_res)
80 void operator ++(
int) { nit++; written =
false; resadd += res; }
81 void operator ++() { (*this)++; }
83 bool first(
void) {
return nit == 0; }
86 int get_noisy(
void)
const {
return noise; }
87 void set_noisy(
int n) { noise = n; }
88 void reduce_noisy(
void) {
if (noise > 0) noise--; }
90 double get_resmax(
void)
const {
return resmax; }
91 void set_resmax(
double r) { resmax = r; }
93 double get_res()
const {
return res; }
94 void enforce_converged(
bool c =
true)
95 {
if (c) res = double(0);
else res = rhsn * resmax + double(1); }
102 double get_diverged_residual(
void)
const {
return diverged_res; }
103 void set_diverged_residual(
double r) { diverged_res = r; }
105 size_type get_iteration(
void)
const {
return nit; }
106 void set_iteration(size_type i) { nit = i; }
108 size_type get_maxiter(
void)
const {
return maxiter; }
109 void set_maxiter(size_type i) { maxiter = i; }
111 double get_rhsnorm(
void)
const {
return rhsn; }
112 void set_rhsnorm(
double r) { rhsn = r; }
114 bool converged(
void) {
115 return !isnan(res) && res <= rhsn * resmax;
117 bool converged(
double nr) {
119 resminreach = std::min(resminreach, res);
122 template <
typename VECT>
bool converged(
const VECT &v)
124 bool diverged(
void) {
125 return isnan(res) || (nit>=maxiter)
126 || (res>=rhsn*diverged_res && nit > 4);
128 bool diverged(
double nr) {
130 resminreach = std::min(resminreach, res);
134 bool finished(
double nr) {
135 if (callback) callback(*
this);
136 if (noise > 0 && !written) {
137 double a = (rhsn == 0) ? 1.0 : rhsn;
139 cout << name <<
" iter " << std::setw(3) << nit <<
" residual "
140 << std::setw(12) << gmm::abs(nr) / a;
149 return (converged(nr) || diverged(nr));
151 template <
typename VECT>
bool finished_vect(
const VECT &v)
155 void set_name(
const std::string &n) { name = n; }
156 const std::string &get_name(
void)
const {
return name; }
The Iteration object calculates whether the solution has reached the desired accuracy,...
number_traits< typename linalg_traits< V >::value_type >::magnitude_type vect_norm2(const V &v)
Euclidean norm of a vector.
Include the base gmm files.
size_t size_type
used as the common size type in the library