29 static rmodel_plsolver_type rdefault_linear_solver(
const model &md) {
30 return default_linear_solver<model_real_sparse_matrix,
31 model_real_plain_vector>(md);
34 static cmodel_plsolver_type cdefault_linear_solver(
const model &md) {
35 return default_linear_solver<model_complex_sparse_matrix,
36 model_complex_plain_vector>(md);
39 void default_newton_line_search::init_search(
double r,
size_t git,
double) {
40 alpha_min_ratio = 0.9;
42 alpha_max_ratio = 10.0;
45 glob_it = git;
if (git <= 1) count_pat = 0;
46 conv_alpha =
alpha = alpha_old = 1.;
47 conv_r = first_res = r; it = 0;
49 max_ratio_reached =
false;
52 double default_newton_line_search::next_try(
void) {
53 alpha_old =
alpha; ++it;
55 if (alpha >= 0.4)
alpha *= 0.5;
else alpha *= alpha_mult;
59 bool default_newton_line_search::is_converged(
double r,
double) {
61 if (!max_ratio_reached && r < first_res * alpha_max_ratio) {
62 alpha_max_ratio_reached = alpha_old; r_max_ratio_reached = r;
63 it_max_ratio_reached = it; max_ratio_reached =
true;
65 if (max_ratio_reached &&
66 r < r_max_ratio_reached * 0.5 &&
67 r > first_res * 1.1 && it <= it_max_ratio_reached+1) {
68 alpha_max_ratio_reached = alpha_old; r_max_ratio_reached = r;
69 it_max_ratio_reached = it;
71 if (count == 0 || r < conv_r)
72 { conv_r = r; conv_alpha = alpha_old; count = 1; }
73 if (conv_r < first_res) ++count;
75 if (r < first_res * alpha_min_ratio)
76 { count_pat = 0;
return true; }
77 if (count>=5 || (alpha < alpha_min && max_ratio_reached) || alpha<1e-15) {
78 if (conv_r < first_res * 0.99) count_pat = 0;
80 { conv_r=r_max_ratio_reached; conv_alpha=alpha_max_ratio_reached; }
81 if (conv_r >= first_res * 0.999) count_pat++;
93 template <
typename MATRIX,
typename VECTOR,
typename PLSOLVER>
96 abstract_newton_line_search &ls,
const MATRIX &K,
99 VECTOR state(md.nb_dof());
100 md.from_variables(state);
101 md.cancel_init_step();
102 md.set_time_integration(2);
103 scalar_type dt = md.get_time_step();
104 scalar_type ddt = md.get_init_time_step();
105 scalar_type t = md.get_time();
108 md.set_time_step(ddt);
111 md.copy_init_time_derivative();
114 md.set_time_step(dt);
116 md.to_variables(state);
117 md.set_time_integration(1);
125 template <
typename MATRIX,
typename VECTOR,
typename PLSOLVER>
128 abstract_newton_line_search &ls,
const MATRIX &K,
131 VECTOR state(md.nb_dof());
132 md.from_variables(state);
134 int time_integration = md.is_time_integration();
135 if (time_integration) {
136 if (time_integration == 1 && md.is_init_step()) {
137 compute_init_values(md, iter, lsolver, ls, K, rhs);
140 md.set_time(md.get_time() + md.get_time_step());
141 md.call_init_affine_dependent_variables(time_integration);
144 if (md.is_linear()) {
145 md.assembly(model::BUILD_ALL);
146 (*lsolver)(K, state, rhs, iter);
149 model_pb<MATRIX, VECTOR> mdpb(md, ls, state, rhs, K);
150 if (dynamic_cast<newton_search_with_step_control *>(&ls))
151 Newton_with_step_control(mdpb, iter, *lsolver);
153 classical_Newton(mdpb, iter, *lsolver);
155 md.to_variables(state);
159 rmodel_plsolver_type lsolver,
160 abstract_newton_line_search &ls) {
166 cmodel_plsolver_type lsolver,
167 abstract_newton_line_search &ls) {
174 rmodel_plsolver_type lsolver) {
175 default_newton_line_search ls;
180 cmodel_plsolver_type lsolver) {
181 newton_search_with_step_control ls;
187 newton_search_with_step_control ls;
const model_real_plain_vector & real_rhs() const
Gives the access to the right hand side of the tangent linear system.
const model_complex_plain_vector & complex_rhs() const
Gives access to the right hand side of the tangent linear system.
The Iteration object calculates whether the solution has reached the desired accuracy, or whether the maximum number of iterations has been reached.
void standard_solve(model &md, gmm::iteration &iter, rmodel_plsolver_type lsolver, abstract_newton_line_search &ls)
A default solver for the model brick system.
``Model'' variables store the variables, the data and the description of a model. ...
size_t size_type
used as the common size type in the library
Input/output on sparse matrices.
Standard solvers for model bricks.
bool is_complex() const
Boolean which says if the model deals with real or complex unknowns and data.
GEneric Tool for Finite Element Methods.
const model_real_sparse_matrix & real_tangent_matrix() const
Gives the access to the tangent matrix.
size_type alpha(short_type n, short_type d)
Return the value of which is the number of monomials of a polynomial of variables and degree ...
const model_complex_sparse_matrix & complex_tangent_matrix() const
Gives the access to the tangent matrix.