47 #ifndef _NONLINEARRICHARDSON_HPP 48 #define _NONLINEARRICHARDSON_HPP 51 #include <lifev/core/algorithm/NonLinearLineSearch.hpp> 52 #include <lifev/core/array/VectorEpetra.hpp> 81 template <
class Fct >
82 Int NonLinearRichardson ( VectorEpetra& sol,
88 Int NonLinearLineSearch,
90 UInt verboseLevel = 0,
91 std::ostream& output = std::cout,
109 const Real gamma = 0.9;
113 if ( sol.comm().MyPID() != 0 )
118 VectorEpetra residual ( sol.map() );
119 VectorEpetra step ( sol.map() );
125 if ( verboseLevel > 0 )
127 std::cout << std::endl;
128 std::cout <<
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" << std::endl;
129 std::cout <<
" Non-Linear Richardson: starting " << std::endl;
130 std::cout <<
"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" << std::endl;
131 std::cout << std::endl;
134 functional.evalResidual ( residual, sol, iter );
136 Real normRes = residual.normInf();
137 Real stop_tol = abstol + reltol * normRes;
138 Real linearRelTol = std::fabs (eta_max);
148 Real solNormInf (sol.normInf() );
150 if ( verboseLevel > 1 )
152 output << std::scientific;
153 output <<
"# time = ";
154 output << time <<
" " <<
"initial norm_res " << normRes
155 <<
" rel tol = " << reltol
156 <<
" stop tol = " << stop_tol
157 <<
"initial norm_sol " 158 << solNormInf << std::endl;
159 output <<
"#iter disp_norm step_norm residual_norm" << std::endl;
161 while ( normRes > stop_tol && iter < maxit )
163 if ( verboseLevel > 0 )
165 std::cout << std::endl;
166 std::cout <<
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" << std::endl;
167 std::cout <<
" Non-Linear Richardson: iteration = " << iter << std::endl
168 <<
" residual = " << normRes << std::endl
169 <<
" rel tol = " << reltol << std::endl
170 <<
" abs tol = " << abstol << std::endl
171 <<
" tolerance = " << stop_tol << std::endl;
172 std::cout <<
"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" << std::endl;
173 std::cout << std::endl;
178 ratio = normRes / normResOld;
179 normResOld = normRes;
180 normRes = residual.normInf();
184 functional.solveJac (step, residual, linearRelTol);
186 solNormInf = sol.normInf();
187 stepNormInf = step.normInf();
188 if ( verboseLevel > 1 )
190 output << std::setw (5) << iter
191 << std::setw (15) << solNormInf
192 << std::setw (15) << stepNormInf;
194 linres = linearRelTol;
197 slope = normRes * normRes * ( linres * linres - 1 );
199 Int status (EXIT_SUCCESS);
200 switch ( NonLinearLineSearch )
204 functional.evalResidual ( residual, sol, iter);
208 status = NonLinearLineSearchParabolic ( functional, residual, sol, step, normRes, lambda, iter, verboseLevel );
211 status = NonLinearLineSearchCubic ( functional, residual, sol, step, normRes, lambda, slope, iter, verboseLevel );
214 std::cout <<
"Unknown NonLinearLineSearch \n";
215 status = EXIT_FAILURE;
218 if (status == EXIT_FAILURE)
223 normRes = residual.normInf();
225 if ( verboseLevel > 1 )
227 output << std::setw (15) << normRes << std::endl;
232 eta_old = linearRelTol;
233 eta_new = gamma * ratio * ratio;
234 if ( gamma * eta_old * eta_old > .1 )
236 eta_new = std::max<Real> ( eta_new, gamma * eta_old * eta_old );
238 linearRelTol = std::min<Real> ( eta_new, eta_max );
239 linearRelTol = std::min<Real> ( eta_max,
240 std::max<Real> ( linearRelTol,
241 .5 * stop_tol / normRes ) );
249 if ( normRes > stop_tol )
251 if ( verboseLevel > 0 )
253 std::cout <<
"!!! NonLinRichardson: convergence fails" << std::endl;
260 if ( verboseLevel > 0 )
262 std::cout << std::endl;
263 std::cout <<
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" << std::endl;
264 std::cout <<
" Non-Linear Richardson: convergence = " << normRes << std::endl
265 <<
" iterations = " << iter << std::endl;
266 std::cout <<
"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" << std::endl;
267 std::cout << std::endl;
int32_type Int
Generic integer data.
double Real
Generic real data.
uint32_type UInt
generic unsigned integer (used mainly for addressing)