initialize_rk_class Subroutine

private subroutine initialize_rk_class(me, n, f, report, g, stop_on_errors, max_number_of_steps, report_rate, solver, dense_output)

Initialize the rk_class.

Type Bound

rk_class

Arguments

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

number of variables

procedure(deriv_func) :: f

derivative function

procedure(report_func), optional :: report

for reporting the steps

procedure(event_func), optional :: g

for stopping at an event

logical, intent(in), optional :: stop_on_errors

stop the program for any errors (default is False)

integer, intent(in), optional :: max_number_of_steps

max number of steps allowed

integer, intent(in), optional :: report_rate

how often to call report function: 0 : no reporting (same as not associating report), 1 : report every point, 2 : report every other point, etc. The first and last point are always reported.

class(root_method), intent(in), optional :: solver

the root-finding method to use for even finding. if not present, then brent_solver is used.

logical, intent(in), optional :: dense_output

to enable the dense output (default is False). This is ignored if the method does not have one.


Calls

proc~~initialize_rk_class~~CallsGraph proc~initialize_rk_class rk_class%initialize_rk_class proc~dense_coefficients rk_class%dense_coefficients proc~initialize_rk_class->proc~dense_coefficients proc~dense_invalidate rk_class%dense_invalidate proc~initialize_rk_class->proc~dense_invalidate proc~destroy rk_class%destroy proc~initialize_rk_class->proc~destroy properties properties proc~initialize_rk_class->properties

Source Code

    subroutine initialize_rk_class(me,n,f,report,g,stop_on_errors,&
                                   max_number_of_steps,report_rate,&
                                   solver,dense_output)

    implicit none

    class(rk_class),intent(inout)   :: me
    integer,intent(in)              :: n       !! number of variables
    procedure(deriv_func)           :: f       !! derivative function
    procedure(event_func),optional  :: g       !! for stopping at an event
    procedure(report_func),optional :: report  !! for reporting the steps
    logical,intent(in),optional     :: stop_on_errors !! stop the program for
                                                      !! any errors (default is False)
    integer,intent(in),optional     :: max_number_of_steps !! max number of steps allowed
    integer,intent(in),optional     :: report_rate !! how often to call report function:
                                                   !! `0` : no reporting (same as not associating `report`),
                                                   !! `1` : report every point,
                                                   !! `2` : report every other point, etc.
                                                   !! The first and last point are always reported.
    class(root_method),intent(in),optional :: solver !! the root-finding method to use for even finding.
                                                     !! if not present, then `brent_solver` is used.
    logical,intent(in),optional :: dense_output !! to enable the dense output (default is False).
                                                !! This is ignored if the method does not have one.

    type(rklib_properties) :: props !! to get the method properties
    real(wp),dimension(:,:),allocatable :: b !! dense output coefficients
    integer :: form !! form of the dense output coefficients

    call me%destroy()

    me%n = n
    me%f => f
    if (present(report)) me%report => report
    if (present(g))      me%g      => g
    if (present(stop_on_errors)) me%stop_on_errors = stop_on_errors
    if (present(max_number_of_steps)) me%max_number_of_steps = abs(max_number_of_steps)
    if (present(report_rate)) me%report_rate = abs(report_rate)
    if (present(solver)) me%solver = solver

    ! dense output (if the method has one):
    props = me%properties()
    if (allocated(me%dense_b))  deallocate(me%dense_b)
    if (allocated(me%dense_x))  deallocate(me%dense_x)
    if (allocated(me%dense_xf)) deallocate(me%dense_xf)
    if (allocated(me%dense_r))  deallocate(me%dense_r)
    me%dense_enabled = .false.
    if (props%dense) then
        call me%dense_coefficients(b, form)
        call move_alloc(b, me%dense_b)
        me%dense_form = form
        if (present(dense_output)) me%dense_enabled = dense_output
        if (me%dense_enabled) then
            allocate(me%dense_x(n))
            allocate(me%dense_xf(n))
            allocate(me%dense_r(n, size(me%dense_b,2)))
        end if
    end if
    call me%dense_invalidate()

    ! allocate the registers:
    ! [any extra stages for the dense output are stored after the ones for the step]
    if (allocated(me%funcs)) deallocate(me%funcs)
    if (me%dense_enabled) then
        allocate(me%funcs(n, max(props%number_of_registers, size(me%dense_b,1))))
    else
        allocate(me%funcs(n, props%number_of_registers))
    end if
    me%funcs = zero

    ! reset internal variables:
    me%num_steps = 0
    me%stopped = .false.

    end subroutine initialize_rk_class