itp_solver Derived Type

type, public, extends(root_solver) :: itp_solver

ITP root solver


Inherits

type~~itp_solver~~InheritsGraph type~itp_solver itp_solver type~root_solver root_solver type~itp_solver->type~root_solver

Components

Type Visibility Attributes Name Initial
real(kind=wp), private :: k1 = 0.1_wp

from (0, inf)

real(kind=wp), private :: k2 = 0.98_wp*(1.0_wp+golden_ratio)

from [1, 1+phi]

integer, private :: n0 = 1

Type-Bound Procedures

procedure, public :: initialize => initialize_root_solver

initialize the class [must be called first]

  • private subroutine initialize_root_solver(me, f, ftol, rtol, atol, maxiter)

    Initialize the root_solver class.

    Read more…

    Arguments

    Type IntentOptional Attributes Name
    class(root_solver), intent(out) :: me
    procedure(func) :: f

    user function f(x) to find the root of

    real(kind=wp), intent(in), optional :: ftol

    absolute tolerance for f=0

    real(kind=wp), intent(in), optional :: rtol

    relative tol for x

    real(kind=wp), intent(in), optional :: atol

    absolute tol for x

    integer, intent(in), optional :: maxiter

    maximum number of iterations

procedure, public :: solve

main routine for finding the root

  • private subroutine solve(me, ax, bx, xzero, fzero, iflag, fax, fbx, bisect_on_failure)

    Main wrapper routine for all the methods.

    Arguments

    Type IntentOptional Attributes Name
    class(root_solver), intent(inout) :: me
    real(kind=wp), intent(in) :: ax

    left endpoint of initial interval

    real(kind=wp), intent(in) :: bx

    right endpoint of initial interval

    real(kind=wp), intent(out) :: xzero

    abscissa approximating a zero of f in the interval ax,bx

    real(kind=wp), intent(out) :: fzero

    value of f at the root (f(xzero))

    integer, intent(out) :: iflag

    status flag (-1=error, 0=root found, -4=ax must be /= bx)

    real(kind=wp), intent(in), optional :: fax

    if f(ax) is already known, it can be input here

    real(kind=wp), intent(in), optional :: fbx

    if f(bx) is already known, it can be input here

    logical, intent(in), optional :: bisect_on_failure

    if true, then if the specified method fails, it will be retried using the bisection method. (default is False). Note that this can use up to maxiter additional function evaluations.

procedure, public :: find_root => itp

  • private subroutine itp(me, ax, bx, fax, fbx, xzero, fzero, iflag)

    Compute the zero of the function f(x) in the interval ax,bx using the Interpolate Truncate and Project (ITP) method.

    Read more…

    Arguments

    Type IntentOptional Attributes Name
    class(itp_solver), intent(inout) :: me
    real(kind=wp), intent(in) :: ax

    left endpoint of initial interval

    real(kind=wp), intent(in) :: bx

    right endpoint of initial interval

    real(kind=wp), intent(in) :: fax

    f(ax)

    real(kind=wp), intent(in) :: fbx

    f(ax)

    real(kind=wp), intent(out) :: xzero

    abscissa approximating a zero of f in the interval ax,bx

    real(kind=wp), intent(out) :: fzero

    value of f at the root (f(xzero))

    integer, intent(out) :: iflag

    status flag (0=root found, -2=max iterations reached)

procedure, public :: set_optional_inputs => itp_optional_inputs

  • private subroutine itp_optional_inputs(me, k1, k2, n0)

    For the itp method, set the optional inputs.

    Arguments

    Type IntentOptional Attributes Name
    class(itp_solver), intent(inout) :: me
    real(kind=wp), intent(in), optional :: k1

    from (0, inf) [Default is 0.1]

    real(kind=wp), intent(in), optional :: k2

    from [1, 1+phi] [Default is 0.98*(1+phi)]

    integer, intent(in), optional :: n0

    [Default is 1

Source Code

    type,extends(root_solver),public :: itp_solver
    !! ITP root solver
    private

    ! tuning parameters for ITP:
    real(wp) :: k1 = 0.1_wp  !! from (0, inf)
    real(wp) :: k2 = 0.98_wp * (1.0_wp + golden_ratio)  !! from [1, 1+phi]
    integer  :: n0 = 1

    contains
    private
    procedure,public :: find_root => itp
    procedure,public :: set_optional_inputs => itp_optional_inputs
    end type itp_solver