30 #define __Iteration_H 1
32 #include <boost/shared_ptr.hpp>
56 template<
typename Real>
70 typedef typename ublas::type_traits<Real>::value_type value_type;
71 typedef typename ublas::type_traits<Real>::real_type real_type;
88 __iterations( iter.__iterations ),
89 __max_iter( iter.__max_iter ),
90 __residual( iter.__residual ),
91 __precision( iter.__precision ),
92 __norm_init( iter.__norm_init )
118 __precision = iter.__precision;
119 __max_iter = iter.__max_iter;
120 __residual = iter.__residual;
121 __norm_init = iter.__norm_init;
137 int numberOfIterations()
const
150 real_type relativePrecision()
const
155 int maximumNumberOfIterations()
const
165 real_type relaxation ()
const
169 int iteration()
const
205 void setRelaxation ( real_type __w )
231 if ( this->isConverged( r ) )
236 else if ( __iterations >= __max_iter )
244 handleEvents(
true );
245 std::string why =
"Solver has not converged";
246 SExceptionSolverHasNotConverged __e( why.c_str(), LOCATION );
247 __e.setNumberOfIterations( __iterations );
248 __e.setResidual( __residual );
253 handleEvents( ret, verbose );
259 template<
typename VectorX>
260 bool isFinished(
const VectorX& r,
bool verbose =
false )
264 if ( this->isConverged( r ) )
269 else if ( __iterations >= __max_iter )
277 handleEvents(
true );
278 std::string why =
"Solver has not converged";
279 SExceptionSolverHasNotConverged __e( why.c_str(), LOCATION );
280 __e.setNumberOfIterations( __iterations );
281 __e.setResidual( __residual );
286 handleEvents( ret, verbose );
293 __residual = r / __norm_init;
294 return ( __residual <= __precision );
297 template<
typename VectorX>
bool isConverged( VectorX
const& x )
throw()
299 __residual = ublas::norm_2( x ) / __norm_init;
300 return ( __residual <= __precision );
305 return ( __iterations == 0 );
333 virtual void handleEvents(
bool __is_finished,
bool verbose )
335 if ( __iterations == 0 )
340 std::cout <<
"iteration " << __iterations <<
" : " <<
residual() <<
"\n";
343 if ( __is_finished ==
true )
348 std::cout <<
"iteration " << __iterations <<
" : " <<
residual() <<
"\n";
354 std::cout <<
"iteration " << __iterations <<
" : " <<
residual() <<
"\n";
365 real_type __residual;
366 real_type __precision;
367 real_type __norm_init;
369 real_type M_relaxation;
372 typedef Iteration<double> iteration_type;
373 typedef boost::shared_ptr<iteration_type> iteration_ptrtype;