9 use,
intrinsic :: iso_fortran_env, only : int32, real64
14 use linalg,
only : qr_factor, form_qr, qr_rank1_update, lu_factor, &
15 rank1_update, mtx_mult, recip_mult_array, solve_triangular_system, &
24 public :: test_convergence
37 logical :: m_uselinesearch = .true.
48 procedure,
public :: get_line_search => lss_get_line_search
58 procedure,
public :: set_line_search => lss_set_line_search
68 procedure,
public :: set_default_line_search => lss_set_default
78 procedure,
public :: is_line_search_defined => &
79 lss_is_line_search_defined
89 procedure,
public :: get_use_line_search => lss_get_use_search
99 procedure,
public :: set_use_line_search => lss_set_use_search
104 module subroutine lss_get_line_search(this, ls)
105 class(line_search_solver),
intent(in) :: this
109 module subroutine lss_set_line_search(this, ls)
110 class(line_search_solver),
intent(inout) :: this
114 module subroutine lss_set_default(this)
115 class(line_search_solver),
intent(inout) :: this
119 pure module function lss_is_line_search_defined(this) result(x)
120 class(line_search_solver),
intent(in) :: this
124 pure module function lss_get_use_search(this) result(x)
125 class(line_search_solver),
intent(in) :: this
129 module subroutine lss_set_use_search(this, x)
130 class(line_search_solver),
intent(inout) :: this
131 logical,
intent(in) :: x
139 type,
extends(line_search_solver) :: quasi_newton_solver
142 integer(int32) :: m_jdelta = 5
237 procedure,
public :: solve => qns_solve
248 procedure,
public :: get_jacobian_interval => qns_get_jac_interval
259 procedure,
public :: set_jacobian_interval => qns_set_jac_interval
264 module subroutine qns_solve(this, fcn, x, fvec, ib, err)
265 class(quasi_newton_solver),
intent(inout) :: this
267 real(real64),
intent(inout),
dimension(:) :: x
268 real(real64),
intent(out),
dimension(:) :: fvec
270 class(errors),
intent(inout),
optional,
target :: err
273 pure module function qns_get_jac_interval(this) result(n)
274 class(quasi_newton_solver),
intent(in) :: this
278 module subroutine qns_set_jac_interval(this, n)
279 class(quasi_newton_solver),
intent(inout) :: this
280 integer(int32),
intent(in) :: n
287 type,
extends(line_search_solver) :: newton_solver
378 procedure,
public :: solve => ns_solve
383 module subroutine ns_solve(this, fcn, x, fvec, ib, err)
384 class(newton_solver),
intent(inout) :: this
386 real(real64),
intent(inout),
dimension(:) :: x
387 real(real64),
intent(out),
dimension(:) :: fvec
389 class(errors),
intent(inout),
optional,
target :: err
479 procedure,
public :: solve => brent_solve
484 module subroutine brent_solve(this, fcn, x, lim, f, ib, err)
485 class(brent_solver),
intent(inout) :: this
487 real(real64),
intent(inout) :: x
489 real(real64),
intent(out),
optional :: f
491 class(errors),
intent(inout),
optional,
target :: err
591 procedure,
public :: solve => newt1var_solve
595 module subroutine newt1var_solve(this, fcn, x, lim, f, ib, err)
596 class(newton_1var_solver),
intent(inout) :: this
598 real(real64),
intent(inout) :: x
600 real(real64),
intent(out),
optional :: f
602 class(errors),
intent(inout),
optional,
target :: err
629 subroutine test_convergence(x, xo, f, g, lg, xtol, ftol, gtol, c, cx, cf, &
632 real(real64),
intent(in),
dimension(:) :: x, xo, f, g
633 real(real64),
intent(in) :: xtol, ftol, gtol
634 logical,
intent(in) :: lg
635 logical,
intent(out) :: c, cx, cf, cg
636 real(real64),
intent(out) :: xnorm, fnorm
639 real(real64),
parameter :: zero = 0.0d0
640 real(real64),
parameter :: one = 1.0d0
641 real(real64),
parameter :: half = 0.5d0
644 integer(int32) :: i, nvar, neqn
645 real(real64) :: test, dxmax, fc, den
654 fc = half * dot_product(f, f)
660 fnorm = max(abs(f(i)), fnorm)
662 if (fnorm < ftol)
then
670 test = abs(x(i) - xo(i)) / max(abs(x(i)), one)
671 xnorm = max(test, xnorm)
673 if (xnorm < xtol)
then
682 den = max(fc, half * nvar)
684 dxmax = abs(g(i)) * max(abs(x(i)), one) / den
685 test = max(test, dxmax)
687 if (test < gtol)
then
A base class for various solvers of equations of one variable.
A base class for various solvers of nonlinear systems of equations.
Defines a type capable of encapsulating an equation of one variable of the form: f(x) = 0.
Defines a set of parameters that describe the behavior of the iteration process.
Defines a pair of numeric values.
Defines a type capable of encapsulating a system of nonlinear equations of the form: F(X) = 0....
Defines a type capable of performing an inexact, backtracking line search to find a point as far alon...
Defines a solver based upon Brent's method for solving an equation of one variable without using deri...
A class describing nonlinear solvers that use a line search algorithm to improve convergence behavior...
Defines a solver based upon Newtons's method for solving an equation of one variable....
Defines a quasi-Newton type solver based upon Broyden's method.