ddeabm_module Module

Modern Fortran implementation of the DDEABM Adams-Bashforth algorithm.

See also

History

  • Jacob Williams : July 2014 : Created module from the SLATEC Fortran 77 code.
  • Development continues at GitHub.

License

The original SLATEC code is a public domain work of the US Government. The modifications are Copyright (c) 2014-2018, Jacob Williams.

Note

This module depends on roots-fortran. When compiled with FPM, this will automatically be downloaded (see fpm.toml)

Note

The default real kind (wp) can be changed using optional preprocessor flags. This library was built with real kind: real(kind=real64) [8 bytes]


Uses

  • module~~ddeabm_module~~UsesGraph module~ddeabm_module ddeabm_module iso_fortran_env iso_fortran_env module~ddeabm_module->iso_fortran_env root_module root_module module~ddeabm_module->root_module

Variables

Type Visibility Attributes Name Initial
integer, public, parameter :: ddeabm_rk = real64

real kind used by this module [8 bytes]

integer, private, parameter :: wp = ddeabm_rk

local copy of ddeabm_rk with a shorter name

real(kind=wp), private, parameter :: d1mach2 = huge(1.0_wp)

the largest magnitude

real(kind=wp), private, parameter :: d1mach4 = epsilon(1.0_wp)

the largest relative spacing


Abstract Interfaces

abstract interface

  • private function bracket_func(me, t1, t2, x1, x2, g1, g2) result(bracketed)

    function to determine if a root is bracketed

    Arguments

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

    first time point

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

    second time point

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

    state at t1

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

    state at t1

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

    event function value at t1

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

    event function value at t2

    Return Value logical

    if the root is bracketed

abstract interface

  • private function bracket_func_vec(me, ig, t1, t2, x1, x2, g1, g2) result(bracketed)

    function to determine if a root is bracketed (vector event version)

    Arguments

    Type IntentOptional Attributes Name
    class(ddeabm_with_event_class_vec), intent(inout) :: me
    integer, intent(in), optional :: ig

    the event function number

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

    first time point

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

    second time point

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

    state at t1

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

    state at t1

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

    event function ig value at t1

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

    event function ig value at t2

    Return Value logical

    if the root is bracketed

abstract interface

  • private subroutine deriv_func(me, t, x, xdot)

    Interface to the ddeabm_class derivative function.

    Known as df in the documentation. provided by the user to define the system of first order differential equations which is to be solved. for the given values of t and the vector x()=(x(1),x(2),...,x(neq)), the subroutine must evaluate the neq components of the system of differential equations dx/dt=df(t,x) and store the derivatives in the array xdot(), that is, xdot(i) = dx(i)/dt for equations i=1,...,neq.

    Arguments

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

    time

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

    state

    real(kind=wp), intent(out), dimension(:) :: xdot

    derivative of state ()

abstract interface

  • private subroutine report_func(me, t, x)

    Interface to the step reporting function.

    Arguments

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

    time

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

    state

abstract interface

  • private subroutine event_func(me, t, x, g)

    Interface to the ddeabm_with_event_class scalar event function.

    Arguments

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

    time

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

    state

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

    event function: . The event is located when .

abstract interface

  • private subroutine event_func_vec(me, t, x, g, ig)

    Interface to the ddeabm_with_event_class_vec scalar event function.

    Arguments

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

    time

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

    state

    real(kind=wp), intent(out), dimension(:) :: g

    vector event function: . The event is located when any .

    integer, intent(in), optional :: ig

    the event function to compute:

    • if not present, then they are all computed.
    • if i>0 then g(i) is computed, and the other elements are ignored.

    If i<=0 or i>ng, then this is a fatal error.


Derived Types

type, public ::  ddeabm_class

The main DDEABM integration class.

Components

Type Visibility Attributes Name Initial
integer, private :: neq = 0

the number of (first order) differential equations to be integrated (>=0)

integer, private :: maxnum = 500

the expense of solving the problem is monitored by counting the number of steps attempted. when this exceeds maxnum, the counter is reset to zero and the user is informed about possible excessive work.

procedure(deriv_func), private, pointer :: df => null()

to define the system of first order differential equations which is to be solved. for the given values of x and the vector u(*)=(u(1),u(2),...,u(neq)), the subroutine must evaluate the neq components of the system of differential equations du/dx=df(x,u) and store the derivatives in the array uprime(*), that is, uprime(i) = du(i)/dx for equations i=1,...,neq.

procedure(report_func), private, pointer :: report => null()

a function for reporting the integration steps (optional). this can be associated in ddeabm_initialize or ddeabm_with_event_initialize, and is enabled using the mode argument in ddeabm_wrapper or ddeabm_with_event_wrapper

logical, private :: scalar_tols = .true.
real(kind=wp), private, allocatable, dimension(:) :: rtol

the user input rel tol

real(kind=wp), private, allocatable, dimension(:) :: atol

the user input abs tol

real(kind=wp), private, allocatable, dimension(:) :: rtol_tmp

rel tol used internally

real(kind=wp), private, allocatable, dimension(:) :: atol_tmp

abs tol used internally

integer, private, dimension(4) :: info = 0

info array

integer, private :: initial_step_mode = 1

how to choose the initial step h:

Read more…
real(kind=wp), private :: initial_step_size = 0.0_wp

when initial_step_mode=3, the h value to use. (for the other modes, this will also contain the value used)

integer, private :: icount = 0

replaced iwork(liw) in original code

real(kind=wp), private :: tprev = 0.0_wp

replaced rwork(itstar) in original code

real(kind=wp), private, dimension(:), allocatable :: two

array

real(kind=wp), private, dimension(:), allocatable :: gstr

array

real(kind=wp), private, allocatable, dimension(:) :: ypout

(neq) contains the approximate derivative of the solution component y(i). in ddeabm, it is obtained by calling subroutine df to evaluate the differential equation using t and y(*) when idid=1 or 2, and by interpolation when idid=3.

real(kind=wp), private, allocatable, dimension(:) :: yp

(neq)

real(kind=wp), private, allocatable, dimension(:) :: yy

(neq)

real(kind=wp), private, allocatable, dimension(:) :: wt

(neq)

real(kind=wp), private, allocatable, dimension(:) :: p

(neq)

real(kind=wp), private, allocatable, dimension(:, :) :: phi

(neq,16)

real(kind=wp), private, dimension(12) :: alpha = 0.0_wp
real(kind=wp), private, dimension(12) :: beta = 0.0_wp
real(kind=wp), private, dimension(12) :: psi = 0.0_wp
real(kind=wp), private, dimension(12) :: v = 0.0_wp
real(kind=wp), private, dimension(12) :: w = 0.0_wp
real(kind=wp), private, dimension(13) :: sig = 0.0_wp
real(kind=wp), private, dimension(13) :: g = 0.0_wp
real(kind=wp), private, dimension(11) :: gi = 0.0_wp
real(kind=wp), private :: h = 0.0_wp

the step size h to be attempted on the next step.

real(kind=wp), private :: eps = 0.0_wp

if the tolerances have been increased by the code (idid=-2), they were multiplied by eps.

real(kind=wp), private :: x = 0.0_wp

contains the current value of the independent variable, i.e. the farthest point integration has reached. this will be different from t only when interpolation has been performed (idid=3).

real(kind=wp), private :: xold = 0.0_wp
real(kind=wp), private :: hold = 0.0_wp
real(kind=wp), private :: told = 0.0_wp
real(kind=wp), private :: delsgn = 0.0_wp
real(kind=wp), private :: tstop = 0.0_wp

(see info(4))

real(kind=wp), private :: twou = 0.0_wp

machine dependent parameter

real(kind=wp), private :: fouru = 0.0_wp

machine dependent parameter

logical, private :: start = .false.

indicator for dsteps code

logical, private :: phase1 = .false.

indicator for dsteps code

logical, private :: nornd = .false.

indicator for dsteps code

logical, private :: stiff = .false.

indicator for stiffness detection

logical, private :: intout = .false.

indicator for intermediate-output

integer, private :: ns = 0
integer, private :: kord = 0
integer, private :: kold = 0
integer, private :: init = 0

initialization indicator

integer, private :: ksteps = 0

counter for attempted steps

integer, private :: kle4 = 0

step counter for stiffness detection

integer, private :: iquit = 0

termination flag

integer, private :: kprev = 0
integer, private :: ivc = 0
integer, private, dimension(10) :: iv = 0
integer, private :: kgi = 0
logical, private :: error = .false.

will be set in stop_integration. indicates an error and to abort the integration

Type-Bound Procedures

procedure, public, non_overridable :: initialize => ddeabm_initialize
procedure, public, non_overridable :: integrate => ddeabm_wrapper
procedure, public, non_overridable :: destroy => destroy_ddeabm
procedure, public, non_overridable :: first_call => ddeabm_new_problem
procedure, public, non_overridable :: interpolate => ddeabm_interp ../../

state interpolation function

procedure, public, non_overridable :: stop_integration => ddeabm_stop_integration ../../

user can call this in df routine to stop the integration

procedure, private, non_overridable :: ddeabm
procedure, private, non_overridable :: ddes
procedure, private, non_overridable :: dhstrt
procedure, private, non_overridable :: dsteps

type, public, extends(ddeabm_class) ::  ddeabm_with_event_class

A version of ddeabm_class with event location (root finding).

Read more…

Components

Type Visibility Attributes Name Initial
real(kind=wp), private :: tol = 0.0_wp

tolerance for root finding

real(kind=wp), private :: t_saved = 0.0_wp

time of last successful step (used to continue after a root finding)

real(kind=wp), private, dimension(:), allocatable :: x_saved

state of last successful step. size (neq). (used to continue after a root finding)

procedure(event_func), private, pointer :: gfunc => null()

event function: g(t,x)=0 at event

procedure(bracket_func), private, pointer :: bracket => null()

a function for determining if the root is bracketed. the default just checks for a sign change in the event function. the user can specify this to use other conditions.

Type-Bound Procedures

procedure, public, non_overridable :: initialize => ddeabm_initialize
procedure, public, non_overridable :: integrate => ddeabm_wrapper
procedure, public, non_overridable :: destroy => destroy_ddeabm
procedure, public, non_overridable :: first_call => ddeabm_new_problem
procedure, public, non_overridable :: interpolate => ddeabm_interp ../../

state interpolation function

procedure, public, non_overridable :: stop_integration => ddeabm_stop_integration ../../

user can call this in df routine to stop the integration

procedure, public, non_overridable :: initialize_event => ddeabm_with_event_initialize
procedure, public, non_overridable :: integrate_to_event => ddeabm_with_event_wrapper

main routine for integration to an event (note that integrate can also still be used from ddeabm_class)

type, public, extends(ddeabm_class) ::  ddeabm_with_event_class_vec

A version of ddeabm_class with event location (root finding) of a vector function (it will stop on the first root it encounters)

Read more…

Components

Type Visibility Attributes Name Initial
integer, private :: n_g_eqns = 0

number of gfunc event equations

real(kind=wp), private, dimension(:), allocatable :: tol

tolerance for root finding. this is a vector (size n_g_eqns)

real(kind=wp), private :: t_saved = 0.0_wp

time of last successful step (used to continue after a root finding)

real(kind=wp), private, dimension(:), allocatable :: x_saved

state of last successful step. size (neq). (used to continue after a root finding)

procedure(event_func_vec), private, pointer :: gfunc => null()

event function: g(t,x)=0 at event

procedure(bracket_func_vec), private, pointer :: bracket => null()

a function for determining if the root is bracketed. the default just checks for a sign change in the event function. the user can specify this to use other conditions.

Type-Bound Procedures

procedure, public, non_overridable :: initialize => ddeabm_initialize
procedure, public, non_overridable :: integrate => ddeabm_wrapper
procedure, public, non_overridable :: destroy => destroy_ddeabm
procedure, public, non_overridable :: first_call => ddeabm_new_problem
procedure, public, non_overridable :: interpolate => ddeabm_interp ../../

state interpolation function

procedure, public, non_overridable :: stop_integration => ddeabm_stop_integration ../../

user can call this in df routine to stop the integration

procedure, public, non_overridable :: initialize_event => ddeabm_with_event_initialize_vec
procedure, public, non_overridable :: integrate_to_event => ddeabm_with_event_wrapper_vec

main routine for integration to an event (note that integrate can also still be used from ddeabm_class)


Functions

private function dhvnrm(v, n) result(m)

Author
Jacob Williams
Date
7/1/2014

Compute the maximum norm of the first n elements of vector v. Replacement for the original SLATEC routine.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in), dimension(:) :: v
integer, intent(in) :: n

Return Value real(kind=wp)


Subroutines

private subroutine ddeabm_stop_integration(me)

Author
Jacob Williams

Call this to abort the integration if there is an error. (Can be called in df by the user.) The step will be considered invalid and not returned.

Read more…

Arguments

Type IntentOptional Attributes Name
class(ddeabm_class), intent(inout) :: me

private subroutine ddeabm_new_problem(me)

Author
Jacob Williams

Call this to indicate that a new problem is being solved. It sets info(1) = 0 (see ddeabm documentation).

Arguments

Type IntentOptional Attributes Name
class(ddeabm_class), intent(inout) :: me

private subroutine ddeabm_initialize(me, neq, maxnum, df, rtol, atol, report, initial_step_mode, initial_step_size)

Author
Jacob Williams

Initialize the ddeabm_class, and set the variables that cannot be changed during a problem.

Arguments

Type IntentOptional Attributes Name
class(ddeabm_class), intent(inout) :: me
integer, intent(in) :: neq

number of equations to be integrated

integer, intent(in) :: maxnum

maximum number of integration steps allowed

procedure(deriv_func) :: df

derivative function dx/dt

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

relative tolerance for integration (see ddeabm)

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

absolution tolerance for integration (see ddeabm)

procedure(report_func), optional :: report

reporting function

integer, intent(in), optional :: initial_step_mode

how to choose the initial step h:

Read more…
real(kind=wp), intent(in), optional :: initial_step_size

for initial_step_mode=3

private subroutine ddeabm_with_event_initialize(me, neq, maxnum, df, rtol, atol, g, root_tol, report, bracket, initial_step_mode, initial_step_size)

Author
Jacob Williams

Initialize ddeabm_with_event_class class, and set the variables that cannot be changed during a problem.

Read more…

Arguments

Type IntentOptional Attributes Name
class(ddeabm_with_event_class), intent(inout) :: me
integer, intent(in) :: neq

number of equations to be integrated

integer, intent(in) :: maxnum

maximum number of integration steps allowed

procedure(deriv_func) :: df

derivative function

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

relative tolerance for integration (see ddeabm)

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

absolution tolerance for integration (see ddeabm)

procedure(event_func) :: g

Event function . This should be a smooth function than can have values and . When (within the tolerance), then a root has been located and the integration will stop.

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

tolerance for the root finding

procedure(report_func), optional :: report

reporting function

procedure(bracket_func), optional :: bracket

root bracketing function. if not present, the default is used.

integer, intent(in), optional :: initial_step_mode

how to choose the initial step h:

Read more…
real(kind=wp), intent(in), optional :: initial_step_size

for initial_step_mode=3

private subroutine ddeabm_with_event_initialize_vec(me, neq, maxnum, df, rtol, atol, ng, g, root_tol, report, bracket, initial_step_mode, initial_step_size)

Author
Jacob Williams

Initialize ddeabm_with_event_class_vec class, and set the variables that cannot be changed during a problem.

Read more…

Arguments

Type IntentOptional Attributes Name
class(ddeabm_with_event_class_vec), intent(inout) :: me
integer, intent(in) :: neq

number of equations to be integrated

integer, intent(in) :: maxnum

maximum number of integration steps allowed

procedure(deriv_func) :: df

derivative function

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

relative tolerance for integration (see ddeabm)

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

absolution tolerance for integration (see ddeabm)

integer, intent(in) :: ng

number of event functions in g

procedure(event_func_vec) :: g

Event function . This should be a smooth function than can have values and . When (within the tolerance), then a root has been located and the integration will stop.

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

tolerance for the root finding. This should be sized ng or 1 (in which case the value is used for all elements)

procedure(report_func), optional :: report

reporting function

procedure(bracket_func_vec), optional :: bracket

root bracketing function. if not present, the default is used.

integer, intent(in), optional :: initial_step_mode

how to choose the initial step h:

Read more…
real(kind=wp), intent(in), optional :: initial_step_size

for initial_step_mode=3

private subroutine destroy_ddeabm(me)

Author
Jacob Williams

Destructor for ddeabm_class.

Arguments

Type IntentOptional Attributes Name
class(ddeabm_class), intent(out) :: me

private subroutine ddeabm_wrapper(me, t, y, tout, tstop, idid, integration_mode, tstep)

Author
Jacob Williams

Wrapper routine for ddeabm.

Read more…

Arguments

Type IntentOptional Attributes Name
class(ddeabm_class), intent(inout) :: me
real(kind=wp), intent(inout) :: t
real(kind=wp), intent(inout), dimension(me%neq) :: y
real(kind=wp), intent(in) :: tout

time at which a solution is desired.

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

for some problems it may not be permissible to integrate past a point tstop because a discontinuity occurs there or the solution or its derivative is not defined beyond tstop. when you have declared a tstop point (see info(4)), you have told the code not to integrate past tstop. in this case any tout beyond tstop is invalid input. [not used if not present]

integer, intent(out) :: idid

indicator reporting what the code did. you must monitor this integer variable to decide what action to take next.

integer, intent(in), optional :: integration_mode

Step mode: 1 - normal integration from t to tout, no reporting [default]. 2 - normal integration from t to tout, report each step.

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

Fixed time step to use for integration_mode=2. If not present, then default integrator steps are used. If integration_mode=1, then this is ignored.

private subroutine ddeabm_with_event_wrapper(me, t, y, tmax, tstop, idid, gval, integration_mode, tstep, continue)

Author
Jacob Williams

Wrapper routine for ddeabm, with event finding. It will integrate until g(t,x)=0 or t=tmax (whichever comes first). Note that a root at the initial time is ignored (user should check for this manually)

Read more…

Arguments

Type IntentOptional Attributes Name
class(ddeabm_with_event_class), intent(inout) :: me
real(kind=wp), intent(inout) :: t
real(kind=wp), intent(inout), dimension(me%neq) :: y
real(kind=wp), intent(in) :: tmax

max time at which a solution is desired. (if root not located, it will integrate to tmax)

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

for some problems it may not be permissible to integrate past a point tstop because a discontinuity occurs there or the solution or its derivative is not defined beyond tstop. when you have declared a tstop point (see info(4)), you have told the code not to integrate past tstop. in this case any tmax beyond tstop is invalid input. [not used if not present]

integer, intent(out) :: idid

indicator reporting what the code did. you must monitor this integer variable to decide what action to take next. idid=1000 means a root was found. See ddeabm for other values.

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

value of the event function g(t,x) at the final time t

integer, intent(in), optional :: integration_mode

Step mode: 1 - normal integration from t to tout, no reporting [default]. 2 - normal integration from t to tout, report each step.

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

Fixed time step to use for reporting and evaluation of event function. If not present, then default integrator steps are used.

logical, intent(in), optional :: continue

to continue after a previous event location. This option can be used after a previous call to this routine has found an event, to continue integration to the next event without having to restart the integration. It will not report the initial point (which would have been reported as the last point of the previous call).

private subroutine ddeabm_interp(me, tc, yc)

Interpolation function. Can be used for dense output after a step. It calls the low-level routine dintp.

Arguments

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

point at which solution is desired

real(kind=wp), intent(out), dimension(me%neq) :: yc

interpolated state at tc

private subroutine ddeabm_with_event_wrapper_vec(me, t, y, tmax, tstop, idid, gval, integration_mode, tstep, continue)

Author
Jacob Williams

Wrapper routine for ddeabm, with event finding for multiple functions. It will integrate until any g(t,x)=0 or t=tmax (whichever comes first). Note that a root at the initial time is ignored (user should check for this manually)

Read more…

Arguments

Type IntentOptional Attributes Name
class(ddeabm_with_event_class_vec), intent(inout) :: me
real(kind=wp), intent(inout) :: t
real(kind=wp), intent(inout), dimension(me%neq) :: y
real(kind=wp), intent(in) :: tmax

max time at which a solution is desired. (if root not located, it will integrate to tmax)

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

for some problems it may not be permissible to integrate past a point tstop because a discontinuity occurs there or the solution or its derivative is not defined beyond tstop. when you have declared a tstop point (see info(4)), you have told the code not to integrate past tstop. in this case any tmax beyond tstop is invalid input. [not used if not present]

integer, intent(out) :: idid

indicator reporting what the code did. you must monitor this integer variable to decide what action to take next. idid>1000 means a root was found for the (idid-1000)th g function. See ddeabm for other values.

real(kind=wp), intent(out), dimension(:) :: gval

value of the event functions g(t,x) at the final time t

integer, intent(in), optional :: integration_mode

Step mode: 1 - normal integration from t to tout, no reporting [default]. 2 - normal integration from t to tout, report each step.

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

Fixed time step to use for reporting and evaluation of event function. If not present, then default integrator steps are used.

logical, intent(in), optional :: continue

to continue after a previous event location. This option can be used after a previous call to this routine has found an event, to continue integration to the next event without having to restart the integration. It will not report the initial point (which would have been reported as the last point of the previous call).

private subroutine ddeabm(me, neq, t, y, tout, info, rtol, atol, idid)

solve an initial value problem in ordinary differential equations using an adams-bashforth method.

Read more…

Arguments

Type IntentOptional Attributes Name
class(ddeabm_class), intent(inout) :: me
integer, intent(in) :: neq

the number of (first order) differential equations to be integrated. (neq >= 1)

real(kind=wp), intent(inout) :: t

value of the independent variable. on input, set it to the initial point of the integration. the code changes its value. on output, the solution was successfully advanced to the output value of t.

real(kind=wp), intent(inout), dimension(neq) :: y
real(kind=wp), intent(in) :: tout
integer, intent(inout), dimension(4) :: info
real(kind=wp), intent(inout), dimension(:) :: rtol
real(kind=wp), intent(inout), dimension(:) :: atol
integer, intent(out) :: idid

private subroutine ddes(me, neq, t, y, tout, info, rtol, atol, idid, ypout, yp, yy, wt, p, phi, alpha, beta, psi, v, w, sig, g, gi, h, eps, x, xold, hold, told, delsgn, tstop, twou, fouru, start, phase1, nornd, stiff, intout, ns, kord, kold, init, ksteps, kle4, iquit, kprev, ivc, iv, kgi)

ddeabm merely allocates storage for ddes to relieve the user of the inconvenience of a long call list. consequently ddes is used as described in the comments for ddeabm.

Read more…

Arguments

Type IntentOptional Attributes Name
class(ddeabm_class), intent(inout) :: me
integer, intent(in) :: neq
real(kind=wp), intent(inout) :: t
real(kind=wp), intent(inout), dimension(neq) :: y
real(kind=wp), intent(in) :: tout
integer, intent(inout), dimension(4) :: info
real(kind=wp), intent(inout), dimension(:) :: rtol
real(kind=wp), intent(inout), dimension(:) :: atol
integer, intent(inout) :: idid
real(kind=wp), intent(inout), dimension(neq) :: ypout
real(kind=wp), intent(inout), dimension(neq) :: yp
real(kind=wp), intent(inout), dimension(neq) :: yy
real(kind=wp), intent(inout), dimension(neq) :: wt
real(kind=wp), intent(inout), dimension(neq) :: p
real(kind=wp), intent(inout), dimension(neq, 16) :: phi
real(kind=wp), intent(inout), dimension(12) :: alpha
real(kind=wp), intent(inout), dimension(12) :: beta
real(kind=wp), intent(inout), dimension(12) :: psi
real(kind=wp), intent(inout), dimension(12) :: v
real(kind=wp), intent(inout), dimension(12) :: w
real(kind=wp), intent(inout), dimension(13) :: sig
real(kind=wp), intent(inout), dimension(13) :: g
real(kind=wp), intent(inout), dimension(11) :: gi
real(kind=wp), intent(inout) :: h
real(kind=wp), intent(inout) :: eps
real(kind=wp), intent(inout) :: x
real(kind=wp), intent(inout) :: xold
real(kind=wp), intent(inout) :: hold
real(kind=wp), intent(inout) :: told
real(kind=wp), intent(inout) :: delsgn
real(kind=wp), intent(inout) :: tstop
real(kind=wp), intent(inout) :: twou
real(kind=wp), intent(inout) :: fouru
logical, intent(inout) :: start
logical, intent(inout) :: phase1
logical, intent(inout) :: nornd
logical, intent(inout) :: stiff
logical, intent(inout) :: intout
integer, intent(inout) :: ns
integer, intent(inout) :: kord
integer, intent(inout) :: kold
integer, intent(inout) :: init
integer, intent(inout) :: ksteps
integer, intent(inout) :: kle4
integer, intent(inout) :: iquit
integer, intent(inout) :: kprev
integer, intent(inout) :: ivc
integer, intent(inout), dimension(10) :: iv
integer, intent(inout) :: kgi

private subroutine dhstrt(me, neq, a, b, y, yprime, etol, morder, small, big, spy, pv, yp, sf, h)

Computes a starting step size to be used in solving initial value problems in ordinary differential equations.

Read more…

Arguments

Type IntentOptional Attributes Name
class(ddeabm_class), intent(inout) :: me
integer, intent(in) :: neq

the number of (first order) differential equations to be integrated.

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

the initial point of integration.

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

a value of the independent variable used to define the direction of integration. a reasonable choice is to set b to the first point at which a solution is desired. you can also use b, if necessary, to restrict the length of the first integration step because the algorithm will not compute a starting step length which is bigger than abs(b-a), unless b has been chosen too close to a. (it is presumed that dhstrt has been called with b different from a on the machine being used. also see the discussion about the parameter small.)

real(kind=wp), intent(in), dimension(neq) :: y

the vector of initial values of the neq solution components at the initial point a.

real(kind=wp), intent(in), dimension(neq) :: yprime

the vector of derivatives of the neq solution components at the initial point a. (defined by the differential equations in subroutine me%df)

real(kind=wp), intent(in), dimension(neq) :: etol

the vector of error tolerances corresponding to the neq solution components. it is assumed that all elements are positive. following the first integration step, the tolerances are expected to be used by the integrator in an error test which roughly requires that abs(local error) <= etol for each vector component.

integer, intent(in) :: morder

the order of the formula which will be used by the initial value method for taking the first integration step.

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

a small positive machine dependent constant which is used for protecting against computations with numbers which are too small relative to the precision of floating point arithmetic. small should be set to (approximately) the smallest positive double precision number such that (1.0_wp+small) > 1.0_wp. on the machine being used. the quantity small**(3.0_wp/8.0_wp) is used in computing increments of variables for approximating derivatives by differences. also the algorithm will not compute a starting step length which is smaller than 100.0_wp*small*abs(a).

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

a large positive machine dependent constant which is used for preventing machine overflows. a reasonable choice is to set big to (approximately) the square root of the largest double precision number which can be held in the machine.

real(kind=wp), intent(inout), dimension(neq) :: spy

work array of length neq which provide the routine with needed storage space.

real(kind=wp), intent(inout), dimension(neq) :: pv

work array of length neq which provide the routine with needed storage space.

real(kind=wp), intent(inout), dimension(neq) :: yp

work array of length neq which provide the routine with needed storage space.

real(kind=wp), intent(inout), dimension(neq) :: sf

work array of length neq which provide the routine with needed storage space.

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

appropriate starting step size to be attempted by the differential equation method.

private subroutine dintp(x, y, xout, yout, ypout, neqn, kold, phi, ivc, iv, kgi, gi, alpha, og, ow, ox, oy)

approximate the solution at xout by evaluating the polynomial computed in dsteps at xout. must be used in conjunction with dsteps.

Read more…

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: x
real(kind=wp), intent(in), dimension(neqn) :: y
real(kind=wp), intent(in) :: xout

point at which solution is desired

real(kind=wp), intent(out), dimension(neqn) :: yout

solution at xout

real(kind=wp), intent(out), dimension(neqn) :: ypout

derivative of solution at xout

integer, intent(in) :: neqn
integer, intent(in) :: kold
real(kind=wp), intent(in), dimension(neqn, 16) :: phi
integer, intent(in) :: ivc
integer, intent(in), dimension(10) :: iv
integer, intent(in) :: kgi
real(kind=wp), intent(in), dimension(11) :: gi
real(kind=wp), intent(in), dimension(12) :: alpha
real(kind=wp), intent(in), dimension(13) :: og
real(kind=wp), intent(in), dimension(12) :: ow
real(kind=wp), intent(in) :: ox
real(kind=wp), intent(in), dimension(neqn) :: oy

private subroutine dsteps(me, neqn, y, x, h, eps, wt, start, hold, k, kold, crash, phi, p, yp, psi, alpha, beta, sig, v, w, g, phase1, ns, nornd, ksteps, twou, fouru, xold, kprev, ivc, iv, kgi, gi)

integrate a system of first order ordinary differential equations one step.

Read more…

Arguments

Type IntentOptional Attributes Name
class(ddeabm_class), intent(inout) :: me
integer, intent(in) :: neqn

number of equations to be integrated

real(kind=wp), intent(inout), dimension(neqn) :: y

solution vector at x

real(kind=wp), intent(inout) :: x

independent variable

real(kind=wp), intent(inout) :: h

appropriate step size for next step. normally determined by code

real(kind=wp), intent(inout) :: eps

local error tolerance

real(kind=wp), intent(inout), dimension(neqn) :: wt

vector of weights for error criterion

logical, intent(inout) :: start

logical variable set .true. for first step, .false. otherwise

real(kind=wp), intent(inout) :: hold

step size used for last successful step

integer, intent(inout) :: k

appropriate order for next step (determined by code)

integer, intent(inout) :: kold

order used for last successful step

logical, intent(inout) :: crash

logical variable set .true. when no step can be taken, .false. otherwise.

real(kind=wp), intent(inout), dimension(neqn, 16) :: phi

required for the interpolation subroutine dintp

real(kind=wp), intent(inout), dimension(neqn) :: p

required for the interpolation subroutine dintp

real(kind=wp), intent(inout), dimension(neqn) :: yp

derivative of solution vector at x after successful step

real(kind=wp), intent(inout), dimension(12) :: psi
real(kind=wp), intent(inout), dimension(12) :: alpha

required for the interpolation subroutine dintp

real(kind=wp), intent(inout), dimension(12) :: beta
real(kind=wp), intent(inout), dimension(13) :: sig
real(kind=wp), intent(inout), dimension(12) :: v
real(kind=wp), intent(inout), dimension(12) :: w

required for the interpolation subroutine dintp

real(kind=wp), intent(inout), dimension(13) :: g

required for the interpolation subroutine dintp

logical, intent(inout) :: phase1
integer, intent(inout) :: ns

number of dsteps taken with size h

logical, intent(inout) :: nornd
integer, intent(inout) :: ksteps

counter on attempted steps

real(kind=wp), intent(inout) :: twou

2.*u where u is machine unit roundoff quantity

real(kind=wp), intent(inout) :: fouru

4.*u where u is machine unit roundoff quantity

real(kind=wp), intent(inout) :: xold

required for the interpolation subroutine dintp

integer, intent(inout) :: kprev
integer, intent(inout) :: ivc

required for the interpolation subroutine dintp

integer, intent(inout), dimension(10) :: iv

required for the interpolation subroutine dintp

integer, intent(inout) :: kgi

required for the interpolation subroutine dintp

real(kind=wp), intent(inout), dimension(11) :: gi

required for the interpolation subroutine dintp

private subroutine report_error(subrou, messg, nerr, level)

Author
Jacob Williams

Report an error message.

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: subrou

subroutine where error occurred

character(len=*), intent(in) :: messg

error message

integer, intent(in) :: nerr

error code

integer, intent(in) :: level

[Not used here] * -1: warning message (once), * 0: warning message, * 1: recoverable error, * 2: fatal error