Runge-Kutta integration.
derivative function
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(rk_class), | intent(inout) | :: | me | |||
| real(kind=wp), | intent(in) | :: | t |
time |
||
| real(kind=wp), | intent(in), | dimension(me%n) | :: | x |
state vector |
|
| real(kind=wp), | intent(out), | dimension(me%n) | :: | xdot |
derivative of state vector |
event function
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(rk_class), | intent(inout) | :: | me | |||
| real(kind=wp), | intent(in) | :: | t |
time |
||
| real(kind=wp), | intent(in), | dimension(me%n) | :: | x |
state vector |
|
| real(kind=wp), | intent(out) | :: | g |
g(t,x). The goal is to stop the integration when g=0. |
report function
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(rk_class), | intent(inout) | :: | me | |||
| real(kind=wp), | intent(in) | :: | t |
time |
||
| real(kind=wp), | intent(in), | dimension(me%n) | :: | x |
state vector |
rk step function
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(rk_class), | intent(inout) | :: | me | |||
| real(kind=wp), | intent(in) | :: | t |
initial time |
||
| real(kind=wp), | intent(in), | dimension(me%n) | :: | x |
initial state vector |
|
| real(kind=wp), | intent(in) | :: | h |
time step |
||
| real(kind=wp), | intent(out), | dimension(me%n) | :: | xf |
final state vector |
main integration class:
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer, | public | :: | n | = | 0 |
user specified number of variables |
|
| procedure(deriv_func), | public, | pointer | :: | f | => | null() |
user-specified derivative function |
| procedure(report_func), | public, | pointer | :: | report | => | null() |
user-specified report function |
| procedure(event_func), | public, | pointer | :: | g | => | null() |
event function (stop when this is zero) |
| procedure, public :: initialize | initialize the class (set n,f, and report) |
| procedure, public, non_overridable :: integrate | main integration routine |
| procedure, public, non_overridable :: integrate_to_event | integration with event finding |
| procedure(step_func), public, deferred :: step | the step routine for the rk method |
| procedure, public :: destroy | destructor |
4th order Runge-Kutta method.
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer, | public | :: | n | = | 0 |
user specified number of variables |
|
| procedure(deriv_func), | public, | pointer | :: | f | => | null() |
user-specified derivative function |
| procedure(report_func), | public, | pointer | :: | report | => | null() |
user-specified report function |
| procedure(event_func), | public, | pointer | :: | g | => | null() |
event function (stop when this is zero) |
| procedure, public :: initialize | initialize the class (set n,f, and report) |
| procedure, public, non_overridable :: integrate | main integration routine |
| procedure, public, non_overridable :: integrate_to_event | integration with event finding |
| procedure, public :: destroy | destructor |
| procedure, public :: step => rk4 |
8th order Runge-Kutta method.
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer, | public | :: | n | = | 0 |
user specified number of variables |
|
| procedure(deriv_func), | public, | pointer | :: | f | => | null() |
user-specified derivative function |
| procedure(report_func), | public, | pointer | :: | report | => | null() |
user-specified report function |
| procedure(event_func), | public, | pointer | :: | g | => | null() |
event function (stop when this is zero) |
| procedure, public :: initialize | initialize the class (set n,f, and report) |
| procedure, public, non_overridable :: integrate | main integration routine |
| procedure, public, non_overridable :: integrate_to_event | integration with event finding |
| procedure, public :: destroy | destructor |
| procedure, public :: step => rk8_10 |
Initialize the rk_class.
| Type | Intent | Optional | 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 |
Main integration routine for the rk_class.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(rk_class), | intent(inout) | :: | me | |||
| real(kind=wp), | intent(in) | :: | t0 |
initial time |
||
| real(kind=wp), | intent(in), | dimension(me%n) | :: | x0 |
initial state |
|
| real(kind=wp), | intent(in) | :: | h |
abs(time step) |
||
| real(kind=wp), | intent(in) | :: | tf |
final time |
||
| real(kind=wp), | intent(out), | dimension(me%n) | :: | xf |
final state |
Event-finding integration routine for the rk_class. Integrates until g(t,x)=0, or until t=tf (whichever happens first).
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(rk_class), | intent(inout) | :: | me | |||
| real(kind=wp), | intent(in) | :: | t0 |
initial time |
||
| real(kind=wp), | intent(in), | dimension(me%n) | :: | x0 |
initial state |
|
| real(kind=wp), | intent(in) | :: | h |
abs(time step) |
||
| real(kind=wp), | intent(in) | :: | tmax |
max final time if event not located |
||
| real(kind=wp), | intent(in) | :: | tol |
function tolerance for root finding |
||
| real(kind=wp), | intent(out) | :: | tf |
actual final time reached |
||
| real(kind=wp), | intent(out), | dimension(me%n) | :: | xf |
final state (at tf) |
|
| real(kind=wp), | intent(out) | :: | gf |
g value at tf |
Take one Runge Kutta 4 integration step: t -> t+h (x -> xf)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(rk4_class), | intent(inout) | :: | me | |||
| real(kind=wp), | intent(in) | :: | t |
initial time |
||
| real(kind=wp), | intent(in), | dimension(me%n) | :: | x |
initial state |
|
| real(kind=wp), | intent(in) | :: | h |
time step |
||
| real(kind=wp), | intent(out), | dimension(me%n) | :: | xf |
state at time |
Take one Runge Kutta 8 integration step: t -> t+h (x -> xf)
This is Formula (8-10) from Reference [1].
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(rk8_10_class), | intent(inout) | :: | me | |||
| real(kind=wp), | intent(in) | :: | t |
initial time |
||
| real(kind=wp), | intent(in), | dimension(me%n) | :: | x |
initial state |
|
| real(kind=wp), | intent(in) | :: | h |
time step |
||
| real(kind=wp), | intent(out), | dimension(me%n) | :: | xf |
state at time |