ode-initval.ss
#lang scheme/base
;;; PLT Scheme Science Collection
;;; ode-initval.ss
;;; Copyright (c) 2004-2008 M. Douglas Williams
;;;
;;; This library is free software; you can redistribute it and/or
;;; modify it under the terms of the GNU Lesser General Public
;;; License as published by the Free Software Foundation; either
;;; version 2.1 of the License, or (at your option) any later version.
;;;
;;; This library is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;;; Lesser General Public License for more details.
;;;
;;; You should have received a copy of the GNU Lesser General Public
;;; License along with this library; if not, write to the Free
;;; Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
;;; 02111-1307 USA.
;;;
;;; -------------------------------------------------------------------
;;;
;;; This module provides an ordinary differential equation solver
;;; capability for PLT Scheme. 
;;;
;;; Version  Date      Description
;;; 2.0.0    11/19/07  Added header.  (Doug Williams)
;;; 2.0.1    01/29/08  Added contracts.  (Doug Williams)
;;; 2.1.0    06/07/08  Changed the components to be separate modules
;;;                    with this one providing the contracts.  Made
;;;                    changes required for V4.0.  (Doug Williams)
;;; 2.1.1    06/14/08  Add unchecked procedures.  (Doug Williams)
  
(require (lib "contract.ss"))
(require (lib "include.ss"))

(require "ode-initval/system.ss"
         "ode-initval/step.ss"
         "ode-initval/control.ss"
         "ode-initval/standard-control.ss"
         "ode-initval/evolve.ss")

(provide
 (rename-out (ode-system-function-eval unchecked-ode-system-function-eval)
             (ode-system-jacobian-eval unchecked-ode-system-jacobian-eval)
             (ode-step-apply unchecked-ode-step-apply)
             (ode-step-reset unchecked-ode-step-reset)
             (ode-evolve-apply unchecked-ode-evolve-apply)
             (ode-evolve-reset unchecked-ode-evolve-reset)))

;;; Contracts

(provide/contract
 (ode-system?
  (-> any/c boolean?))
 (make-ode-system
  (-> procedure? (or/c procedure? false/c) natural-number/c list? ode-system?))
 (ode-system-function
  (-> ode-system? procedure?))
 (ode-system-jacobian
  (-> ode-system? (or/c procedure? false/c)))
 (ode-system-dimension
  (-> ode-system? natural-number/c))
 (ode-system-params
  (-> ode-system? list?))
 (ode-system-function-eval
  (-> ode-system? real? (vectorof real?) (vectorof real?) void?))
 (ode-system-jacobian-eval
  (-> ode-system? real? (vectorof real?) (vectorof real?) (vectorof real?) void?))
 (ode-step-type?
  (-> any/c boolean?))
 (make-ode-step-type
  (-> string? boolean? boolean? procedure? procedure? procedure? procedure? ode-step-type?))
 (ode-step-type-name
  (-> ode-step-type? string?))
 (ode-step-type-can-use-dydt-in?
  (-> ode-step-type? boolean?))
 (ode-step-type-gives-exact-dydt-out?
  (-> ode-step-type? boolean?))
 (ode-step-type-make
  (-> ode-step-type? procedure?))
 (ode-step-type-apply
  (-> ode-step-type? procedure?))
 (ode-step-type-reset
  (-> ode-step-type? procedure?))
 (ode-step-type-order
  (-> ode-step-type? procedure?))
 (ode-step?
  (-> any/c boolean?))
 (make-ode-step
  (-> ode-step-type? natural-number/c ode-step?))
 (ode-step-step-type
  (-> ode-step? ode-step-type?))
 (ode-step-dimension
  (-> ode-step? natural-number/c))
 (ode-step-state
  (-> ode-step? any))
 (ode-step-name
  (-> ode-step? string?))
 (ode-step-order
  (-> ode-step? natural-number/c))
 (ode-step-apply
  (-> ode-step? real? real? (vectorof real?) (vectorof real?)
      (vectorof real?) (vectorof real?) ode-system? any))
 (ode-step-reset
  (-> ode-step? void))
 (standard-control-state?
  (-> any/c boolean?))
 (make-standard-control-state
  (-> standard-control-state?))
 (standard-control-state-eps-abs
  (-> standard-control-state? real?))
 (standard-control-state-eps-rel
  (-> standard-control-state? real?))
 (standard-control-state-a_y
  (-> standard-control-state? real?))
 (standard-control-state-a_dydt
  (-> standard-control-state? real?))
 )

(provide
 make-ode-control
 make-ode-evolve
 ode-evolve-count
 ode-evolve-failed-steps
 standard-control-new
 control-y-new
 control-yp-new
 ode-evolve-reset
 ode-evolve-apply
 )

;;; Routines
;;; Include the predefined ODE solvers.

(include "ode-initval/rk2.ss")
(include "ode-initval/rk4.ss")
(include "ode-initval/rkf45.ss")

(provide 
 rk2-ode-type
 rk4-ode-type
 rkf45-ode-type)