initialize Subroutine

private subroutine initialize(me, n, f, rtol, atol, stepsize_method, hinit_method, report, g)

Initialize the rk_variable_step_class.

Type Bound

rk_variable_step_class

Arguments

Type IntentOptional Attributes Name
class(rk_variable_step_class), intent(inout) :: me
integer, intent(in) :: n

number of equations

procedure(deriv_func) :: f

derivative function

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

relative tolerance (if size=1, then same tol used for all equations)

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

absolute tolerance (if size=1, then same tol used for all equations)

class(stepsize_class), intent(in) :: stepsize_method

method for varying the step size

integer, intent(in), optional :: hinit_method

which method to use for automatic initial step size computation. 1 = use hstart, 2 = use hinit.

procedure(report_func), optional :: report

for reporting the steps

procedure(event_func), optional :: g

for stopping at an event


Calls

proc~~initialize~~CallsGraph proc~initialize rk_module_variable_step::rk_variable_step_class%initialize proc~destroy rk_module_variable_step::rk_variable_step_class%destroy proc~initialize->proc~destroy

Source Code

    subroutine initialize(me,n,f,rtol,atol,stepsize_method,hinit_method,report,g)

    implicit none

    class(rk_variable_step_class),intent(inout) :: me
    integer,intent(in)                          :: n               !! number of equations
    procedure(deriv_func)                       :: f               !! derivative function
    real(wp),dimension(:),intent(in)            :: rtol            !! relative tolerance (if size=1,
                                                                   !! then same tol used for all
                                                                   !! equations)
    real(wp),dimension(:),intent(in)            :: atol            !! absolute tolerance (if size=1,
                                                                   !! then same tol used for all
                                                                   !! equations)
    class(stepsize_class),intent(in)            :: stepsize_method !! method for varying the step size
    integer,intent(in),optional                 :: hinit_method    !! which method to use for
                                                                   !! automatic initial step size
                                                                   !! computation.
                                                                   !! 1 = use `hstart`, 2 = use `hinit`.
    procedure(report_func),optional             :: report          !! for reporting the steps
    procedure(event_func),optional              :: g               !! for stopping at an event

    call me%destroy()

    me%n = n
    me%f => f

    allocate(me%rtol(n))
    allocate(me%atol(n))
    if (size(rtol)==1) then
        me%rtol = rtol(1) !use this for all equations
    else if (size(rtol)==n) then
        me%rtol = rtol
    else
        error stop 'invalid size for rtol array.'
    end if
    if (size(atol)==1) then
        me%atol = atol(1) !use this for all equations
    else if (size(atol)==n) then
        me%atol = atol
    else
        error stop 'invalid size for atol array.'
    end if

    if (present(hinit_method)) me%hinit_method = hinit_method

    if (present(report)) me%report => report
    if (present(g))      me%g      => g

    allocate(me%stepsize_method, source=stepsize_method)

    me%num_rejected_steps = 0

    end subroutine initialize