You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
4.0 KiB

  1. /* -*- c++ -*- (enables emacs c++ mode) */
  2. /*===========================================================================
  3. Copyright (C) 2002-2015 Yves Renard
  4. This file is a part of GETFEM++
  5. Getfem++ is free software; you can redistribute it and/or modify it
  6. under the terms of the GNU Lesser General Public License as published
  7. by the Free Software Foundation; either version 3 of the License, or
  8. (at your option) any later version along with the GCC Runtime Library
  9. Exception either version 3.1 or (at your option) any later version.
  10. This program is distributed in the hope that it will be useful, but
  11. WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  12. or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  13. License and GCC Runtime Library Exception for more details.
  14. You should have received a copy of the GNU Lesser General Public License
  15. along with this program; if not, write to the Free Software Foundation,
  16. Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
  17. As a special exception, you may use this file as it is a part of a free
  18. software library without restriction. Specifically, if other files
  19. instantiate templates or use macros or inline functions from this file,
  20. or you compile this file and link it with other files to produce an
  21. executable, this file does not by itself cause the resulting executable
  22. to be covered by the GNU Lesser General Public License. This exception
  23. does not however invalidate any other reasons why the executable file
  24. might be covered by the GNU Lesser General Public License.
  25. ===========================================================================*/
  26. /**@file gmm_iter_solvers.h
  27. @author Yves Renard <Yves.Renard@insa-lyon.fr>
  28. @date October 13, 2002.
  29. @brief Include standard gmm iterative solvers (cg, gmres, ...)
  30. */
  31. #ifndef GMM_ITER_SOLVERS_H__
  32. #define GMM_ITER_SOLVERS_H__
  33. #include "gmm_iter.h"
  34. namespace gmm {
  35. /** mixed method to find a zero of a real function G, a priori
  36. * between a and b. If the zero is not between a and b, iterations
  37. * of secant are applied. When a convenient interval is found,
  38. * iterations of dichotomie and regula falsi are applied.
  39. */
  40. template <typename FUNC, typename T>
  41. T find_root(const FUNC &G, T a = T(0), T b = T(1),
  42. T tol = gmm::default_tol(T())) {
  43. T c, Ga = G(a), Gb = G(b), Gc, d;
  44. d = gmm::abs(b - a);
  45. #if 0
  46. for (int i = 0; i < 4; i++) { /* secant iterations. */
  47. if (d < tol) return (b + a) / 2.0;
  48. c = b - Gb * (b - a) / (Gb - Ga); Gc = G(c);
  49. a = b; b = c; Ga = Gb; Gb = Gc;
  50. d = gmm::abs(b - a);
  51. }
  52. #endif
  53. while (Ga * Gb > 0.0) { /* secant iterations. */
  54. if (d < tol) return (b + a) / 2.0;
  55. c = b - Gb * (b - a) / (Gb - Ga); Gc = G(c);
  56. a = b; b = c; Ga = Gb; Gb = Gc;
  57. d = gmm::abs(b - a);
  58. }
  59. c = std::max(a, b); a = std::min(a, b); b = c;
  60. while (d > tol) {
  61. c = b - (b - a) * (Gb / (Gb - Ga)); /* regula falsi. */
  62. if (c > b) c = b; if (c < a) c = a;
  63. Gc = G(c);
  64. if (Gc*Gb > 0) { b = c; Gb = Gc; } else { a = c; Ga = Gc; }
  65. c = (b + a) / 2.0 ; Gc = G(c); /* Dichotomie. */
  66. if (Gc*Gb > 0) { b = c; Gb = Gc; } else { a = c; Ga = Gc; }
  67. d = gmm::abs(b - a); c = (b + a) / 2.0; if ((c == a) || (c == b)) d = 0.0;
  68. }
  69. return (b + a) / 2.0;
  70. }
  71. }
  72. #include "gmm_precond_diagonal.h"
  73. #include "gmm_precond_ildlt.h"
  74. #include "gmm_precond_ildltt.h"
  75. #include "gmm_precond_mr_approx_inverse.h"
  76. #include "gmm_precond_ilu.h"
  77. #include "gmm_precond_ilut.h"
  78. #include "gmm_precond_ilutp.h"
  79. #include "gmm_solver_cg.h"
  80. #include "gmm_solver_bicgstab.h"
  81. #include "gmm_solver_qmr.h"
  82. #include "gmm_solver_constrained_cg.h"
  83. #include "gmm_solver_Schwarz_additive.h"
  84. #include "gmm_modified_gram_schmidt.h"
  85. #include "gmm_tri_solve.h"
  86. #include "gmm_solver_gmres.h"
  87. #include "gmm_solver_bfgs.h"
  88. #include "gmm_least_squares_cg.h"
  89. // #include "gmm_solver_idgmres.h"
  90. #endif // GMM_ITER_SOLVERS_H__