GetFEM  5.5
getfem_continuation.cc
Go to the documentation of this file.
1 /*===========================================================================
2 
3  Copyright (C) 2011-2026 Tomas Ligursky, Yves Renard, Konstantinos Poulios
4 
5  This file is a part of GetFEM
6 
7  GetFEM is free software; you can redistribute it and/or modify it
8  under the terms of the GNU Lesser General Public License as published
9  by the Free Software Foundation; either version 3 of the License, or
10  (at your option) any later version along with the GCC Runtime Library
11  Exception either version 3.1 or (at your option) any later version.
12  This program is distributed in the hope that it will be useful, but
13  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15  License and GCC Runtime Library Exception for more details.
16  You should have received a copy of the GNU Lesser General Public License
17  along with this program. If not, see https://www.gnu.org/licenses/.
18 
19 ===========================================================================*/
20 
21 /** @file getfem_continuation.cc
22  @author Tomas Ligursky <tomas.ligursky@ugn.cas.cz>
23  @author Yves Renard <Yves.Renard@insa-lyon.fr>
24  @author Konstantinos Poulios <logari81@googlemail.com>
25  @date January 12, 2014.
26  @brief inexact Moore-Penrose continuation method.
27 */
28 
30 
31 namespace getfem {
32 
33  void cont_struct_getfem_model::set_variables
34  (const base_vector &x, double gamma) const {
35  md->set_real_variable(parameter_name)[0] = gamma;
36  if (!currentdata_name.empty()) {
37  gmm::add(gmm::scaled(md->real_variable(initdata_name), 1. - gamma),
38  gmm::scaled(md->real_variable(finaldata_name), gamma),
39  md->set_real_variable(currentdata_name));
40  }
41  md->to_variables(x);
42  }
43 
44  void cont_struct_getfem_model::update_matrix
45  (const base_vector &x, double gamma) const {
46  set_variables(x, gamma);
47  if (noisy() > 2) cout << "starting computing tangent matrix" << endl;
48  md->assembly(model::BUILD_MATRIX);
49  }
50 
51  // solve A * g = L
52  void cont_struct_getfem_model::solve
53  (const model_real_sparse_matrix &A, base_vector &g,
54  const base_vector &L) const {
55  if (noisy() > 2) cout << "starting linear solver" << endl;
56  gmm::iteration iter(maxres_solve, (noisy() >= 2) ? noisy() - 2 : 0,
57  40000);
58  (*lsolver)(A, g, L, iter);
59  if (noisy() > 2) cout << "linear solver done" << endl;
60  }
61 
62  // solve A * (g1|g2) = (L1|L2)
63  void cont_struct_getfem_model::solve
64  (const model_real_sparse_matrix &A, base_vector &g1, base_vector &g2,
65  const base_vector &L1, const base_vector &L2) const {
66  if (noisy() > 2) cout << "starting linear solver" << endl;
67  gmm::iteration iter(maxres_solve, (noisy() >= 2) ? noisy() - 2 : 0,
68  40000);
69  (*lsolver)(A, g1, L1, iter);
70  iter.init(); (*lsolver)(A, g2, L2, iter); // (can be optimised)
71  if (noisy() > 2) cout << "linear solver done" << endl;
72  }
73 
74  // F(x, gamma) --> f
75  void cont_struct_getfem_model::F
76  (const base_vector &x, double gamma, base_vector &f) const {
77  set_variables(x, gamma);
78  md->assembly(model::BUILD_RHS);
79  gmm::copy(gmm::scaled(md->real_rhs(), -1.), f);
80  }
81 
82  // (F(x, gamma + eps) - f0) / eps --> g
83  void cont_struct_getfem_model::F_gamma
84  (const base_vector &x, double gamma, const base_vector &f0,
85  base_vector &g) const {
86  const double eps = diffeps;
87  F(x, gamma + eps, g);
88  gmm::add(gmm::scaled(f0, -1.), g);
89  gmm::scale(g, 1./eps);
90  }
91 
92  // (F(x, gamma + eps) - F(x, gamma)) / eps --> g
93  void cont_struct_getfem_model::F_gamma
94  (const base_vector &x, double gamma, base_vector &g) const {
95  base_vector f0(x);
96  F(x, gamma, f0);
97  F_gamma(x, gamma, f0, g);
98  }
99 
100  // F_x(x, gamma) --> A
101  void cont_struct_getfem_model::F_x
102  (const base_vector &x, double gamma, model_real_sparse_matrix &A) const {
103  update_matrix(x, gamma);
104  size_type nbdof = md->nb_dof();
105  gmm::resize(A, nbdof, nbdof);
106  gmm::copy(md->real_tangent_matrix(), A);
107  }
108 
109  // solve F_x(x, gamma) * g = L
110  void cont_struct_getfem_model::solve_grad
111  (const base_vector &x, double gamma, base_vector &g,
112  const base_vector &L) const {
113  update_matrix(x, gamma);
114  solve(md->real_tangent_matrix(), g, L);
115 //int exp;
116 //cout<<"det="<<MUMPS_determinant(md->real_tangent_matrix(),exp)<<"*2^"<<exp<<endl;
117  }
118 
119  // solve F_x(x, gamma) * (g1|g2) = (L1|L2)
120  void cont_struct_getfem_model::solve_grad
121  (const base_vector &x, double gamma, base_vector &g1, base_vector &g2,
122  const base_vector &L1, const base_vector &L2) const {
123  update_matrix(x, gamma);
124  solve(md->real_tangent_matrix(), g1, g2, L1, L2);
125  }
126 
127  // F_x(x, gamma) * w --> y
128  void cont_struct_getfem_model::mult_grad
129  (const base_vector &x, double gamma,
130  const base_vector &w, base_vector &y) const {
131  update_matrix(x, gamma);
132  mult(md->real_tangent_matrix(), w, y);
133  }
134 
135  size_type cont_struct_getfem_model::estimated_memsize(void) {
136  return sizeof(cont_struct_getfem_model)
137  + virtual_cont_struct::estimated_memsize();
138  }
139 
140 } /* end of namespace getfem. */
The Iteration object calculates whether the solution has reached the desired accuracy,...
Definition: gmm_iter.h:52
Inexact Moore-Penrose continuation method.
void copy(const L1 &l1, L2 &l2)
*‍/
Definition: gmm_blas.h:976
void resize(V &v, size_type n)
*‍/
Definition: gmm_blas.h:209
void mult(const L1 &l1, const L2 &l2, L3 &l3)
*‍/
Definition: gmm_blas.h:1663
void add(const L1 &l1, L2 &l2)
*‍/
Definition: gmm_blas.h:1275
size_t size_type
used as the common size type in the library
Definition: bgeot_poly.h:48
GEneric Tool for Finite Element Methods.