GetFEM  5.6
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  GMM_ASSERT1(!md->has_internal_variables(), "Continuation is not "
36  "available for models with internal variables");
37  md->set_real_variable(parameter_name)[0] = gamma;
38  if (!currentdata_name.empty()) {
39  gmm::add(gmm::scaled(md->real_variable(initdata_name), 1. - gamma),
40  gmm::scaled(md->real_variable(finaldata_name), gamma),
41  md->set_real_variable(currentdata_name));
42  }
43  md->to_variables(x);
44  }
45 
46  void cont_struct_getfem_model::update_matrix
47  (const base_vector &x, double gamma) const {
48  set_variables(x, gamma);
49  if (noisy() > 2) cout << "starting computing tangent matrix" << endl;
50  md->assembly(model::BUILD_MATRIX);
51  }
52 
53  // solve A * g = L
54  void cont_struct_getfem_model::solve
55  (const model_real_sparse_matrix &A, base_vector &g,
56  const base_vector &L) const {
57  if (noisy() > 2) cout << "starting linear solver" << endl;
58  gmm::iteration iter(maxres_solve, (noisy() >= 2) ? noisy() - 2 : 0,
59  40000);
60  (*lsolver)(A, g, L, iter);
61  if (noisy() > 2) cout << "linear solver done" << endl;
62  }
63 
64  // solve A * (g1|g2) = (L1|L2)
65  void cont_struct_getfem_model::solve
66  (const model_real_sparse_matrix &A, base_vector &g1, base_vector &g2,
67  const base_vector &L1, const base_vector &L2) const {
68  if (noisy() > 2) cout << "starting linear solver" << endl;
69  gmm::iteration iter(maxres_solve, (noisy() >= 2) ? noisy() - 2 : 0,
70  40000);
71  (*lsolver)(A, g1, L1, iter);
72  iter.init(); (*lsolver)(A, g2, L2, iter); // (can be optimised)
73  if (noisy() > 2) cout << "linear solver done" << endl;
74  }
75 
76  // F(x, gamma) --> f
77  void cont_struct_getfem_model::F
78  (const base_vector &x, double gamma, base_vector &f) const {
79  set_variables(x, gamma);
80  md->assembly(model::BUILD_RHS);
81  gmm::copy(gmm::scaled(md->real_rhs(), -1.), f);
82  }
83 
84  // (F(x, gamma + eps) - f0) / eps --> g
85  void cont_struct_getfem_model::F_gamma
86  (const base_vector &x, double gamma, const base_vector &f0,
87  base_vector &g) const {
88  const double eps = diffeps;
89  F(x, gamma + eps, g);
90  gmm::add(gmm::scaled(f0, -1.), g);
91  gmm::scale(g, 1./eps);
92  }
93 
94  // (F(x, gamma + eps) - F(x, gamma)) / eps --> g
95  void cont_struct_getfem_model::F_gamma
96  (const base_vector &x, double gamma, base_vector &g) const {
97  base_vector f0(x);
98  F(x, gamma, f0);
99  F_gamma(x, gamma, f0, g);
100  }
101 
102  // F_x(x, gamma) --> A
103  void cont_struct_getfem_model::F_x
104  (const base_vector &x, double gamma, model_real_sparse_matrix &A) const {
105  update_matrix(x, gamma);
106  size_type nbdof = md->nb_dof();
107  gmm::resize(A, nbdof, nbdof);
108  gmm::copy(md->real_tangent_matrix(), A);
109  }
110 
111  // solve F_x(x, gamma) * g = L
112  void cont_struct_getfem_model::solve_grad
113  (const base_vector &x, double gamma, base_vector &g,
114  const base_vector &L) const {
115  update_matrix(x, gamma);
116  solve(md->real_tangent_matrix(), g, L);
117 //int exp;
118 //cout<<"det="<<MUMPS_determinant(md->real_tangent_matrix(),exp)<<"*2^"<<exp<<endl;
119  }
120 
121  // solve F_x(x, gamma) * (g1|g2) = (L1|L2)
122  void cont_struct_getfem_model::solve_grad
123  (const base_vector &x, double gamma, base_vector &g1, base_vector &g2,
124  const base_vector &L1, const base_vector &L2) const {
125  update_matrix(x, gamma);
126  solve(md->real_tangent_matrix(), g1, g2, L1, L2);
127  }
128 
129  // F_x(x, gamma) * w --> y
130  void cont_struct_getfem_model::mult_grad
131  (const base_vector &x, double gamma,
132  const base_vector &w, base_vector &y) const {
133  update_matrix(x, gamma);
134  mult(md->real_tangent_matrix(), w, y);
135  }
136 
137  size_type cont_struct_getfem_model::estimated_memsize(void) {
138  return sizeof(cont_struct_getfem_model)
139  + virtual_cont_struct::estimated_memsize();
140  }
141 
142 } /* 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.