20 #ifndef SELDON_FILE_ITERATIVE_CXX
25 #include "Iterative.hxx"
33 #include "BiCgStab.cxx"
34 #include "BiCgStabl.cxx"
46 #include "IterativeInline.cxx"
59 fail_convergence =
false;
61 init_guess_null =
true;
62 type_solver = 0; parameter_restart = 10;
63 type_preconditioning = 0;
71 max_iter = max_iteration;
75 fail_convergence =
false;
77 init_guess_null =
true;
78 type_solver = 0; parameter_restart = 10;
79 type_preconditioning = 0;
92 init_guess_null =
true;
96 file_name_history = outer.file_name_history;
101 template<
class Titer>
109 template<
class Titer>
112 return parameter_restart;
117 template<
class Titer>
120 return facteur_reste;
125 template<
class Titer>
133 template<
class Titer>
141 template<
class Titer>
143 int param_restart,
int type_prec)
145 type_solver = type_resolution;
146 parameter_restart = param_restart;
147 type_preconditioning = type_prec;
152 template<
class Titer>
155 parameter_restart = m;
160 template<
class Titer>
163 tolerance = stopping_criterion;
168 template<
class Titer>
171 max_iter = max_iteration;
176 template<
class Titer>
184 template<
class Titer>
192 template<
class Titer>
200 template<
class Titer>
203 file_name_history = file_name;
204 std::remove(file_name.data());
209 template<
class Titer>
217 template<
class Titer>
template<
class Vector1>
220 Titer norme_rhs =
Norm2(r);
222 if (norme_rhs == Titer(0))
226 facteur_reste = Titer(1)/norme_rhs;
235 template<
class Titer>
246 template<
class Titer>
249 return init_guess_null;
254 template<
class Titer>
257 init_guess_null = type;
262 template<
class Titer>
template<
class Vector1>
267 Titer reste =
Norm2(r);
269 reste = facteur_reste*reste;
272 if ((print_level >= 1)&&(nb_iter%100 == 0))
273 cout<<
"Residu at iteration number "<<
274 GetNumberIteration()<<
" "<<reste<<endl;
275 else if (print_level >= 6)
276 cout<<
"Residu at iteration number "<<
277 GetNumberIteration()<<
" "<<reste<<endl;
279 if (file_name_history.size() > 0)
281 ofstream file_out(file_name_history.data(), ios::app);
282 file_out.setf(ios::scientific);
283 file_out << GetNumberIteration() <<
" " << reste <<
'\n';
289 if ((reste < tolerance)||(nb_iter >= max_iter))
297 template<
class Titer>
301 Titer reste = facteur_reste*r;
304 if ((print_level >= 1)&&(nb_iter%100 == 0))
305 cout<<
"Residu at iteration number "<<
306 GetNumberIteration()<<
" "<<reste<<endl;
307 else if (print_level >= 6)
308 cout<<
"Residu at iteration number "<<
309 GetNumberIteration()<<
" "<<reste<<endl;
311 if (file_name_history.size() > 0)
313 ofstream file_out(file_name_history.data(), ios::app);
314 file_out.setf(ios::scientific);
315 file_out << GetNumberIteration() <<
" " << reste <<
'\n';
321 if ((reste < tolerance)||(nb_iter >= max_iter))
329 template<
class Titer>
332 fail_convergence =
true;
335 if ((print_level >= 1)&&(nb_iter%100==0))
336 cout<<
"Error during resolution : "<<s<<endl;
341 template<
class Titer>
350 template<
class Titer>
354 file_name_history.clear();
356 if (nb_iter >= max_iter)
359 if (fail_convergence)
367 #define SELDON_FILE_ITERATIVE_CXX
int parameter_restart
restart parameter (for Gmres and Gcr)
bool First() const
Returns true if it is the first iteration.
int max_iter
maximum number of iterations
int GetNumberIteration() const
Returns the number of iterations.
int GetRestart() const
Returns the restart parameter.
Titer GetTolerance() const
Returns stopping criterion.
bool fail_convergence
true if the iterative solver has converged print level
ClassComplexType< T >::Treal Norm2(const VectorExpression< T, E > &X)
returns 2-norm of an expression with vectors
int type_solver
iterative solver used
int GetTypeSolver() const
Returns the type of solver.
void SaveFullHistory(const string &file)
History of residuals is printed in a file.
void SetMaxNumberIteration(int max_iteration)
Changes the maximum number of iterations.
int Init(const Vector1 &r)
Initialization with the right hand side.
Iteration & operator++(void)
Increment the number of iterations.
void ShowMessages()
Sets to a normal display (residual each 100 iterations)
int ErrorCode()
Returns the error code (if an error occured)
Iteration()
Default constructor.
void ShowFullHistory()
Sets to a complete display (residual each iteration)
Titer GetFactor() const
Returns used coefficient to compute relative residual.
Titer tolerance
stopping criterion
void Fail(int i, const string &s)
Informs of a failure in the iterative solver.
int error_code
error code returned by iterative solver
void SetTolerance(Titer stopping_criterion)
Changes the stopping criterion.
Titer facteur_reste
inverse of norm of first residual
void SetNumberIteration(int nb)
Changes the number of iterations.
int type_preconditioning
preconditioner used
Class containing parameters for an iterative resolution.
bool IsInitGuess_Null() const
Returns true if the initial guess is null.
void SetSolver(int type_resolution, int param_restart, int type_prec)
Changes the type of solver and preconditioning.
void SetRestart(int m)
Changes the restart parameter.
void HideMessages()
Doesn't display any information.
bool Finished(const Vector1 &r) const
Returns true if the iterative solver has reached its end.
void SetInitGuess(bool type)
informs if the initial guess is null