ode-initval/step.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.
;;;
;;; -------------------------------------------------------------------
;;;
;;; Version  Date      Description

(provide (all-defined-out))

(define-struct ode-step-type
               (name
                can-use-dydt-in?
                gives-exact-dydt-out?
                make
                apply
                reset
                order))

;(define-struct ode-step
;               (type
;                dimension
;                state))
(define-values (struct:ode-step
                ode-step-constructor
                ode-step?
                ode-step-field-ref
                set-ode-step-field!)
  (make-struct-type 'ode-step #f 3 0))

(define (make-ode-step step-type dim)
  (ode-step-constructor
   step-type
   dim
   ((ode-step-type-make step-type) dim)))

(define ode-step-step-type
  (make-struct-field-accessor ode-step-field-ref 0 'step-type))
(define set-ode-stepper-step-type!
  (make-struct-field-mutator set-ode-step-field! 0 'step-type))

(define ode-step-dimension
  (make-struct-field-accessor ode-step-field-ref 1 'dimension))
(define set-ode-step-dimension!
  (make-struct-field-mutator set-ode-step-field! 1 'dimension))

(define ode-step-state
  (make-struct-field-accessor ode-step-field-ref 2 'state))
(define set-ode-step-state!
  (make-struct-field-mutator set-ode-step-field! 2 'state))

;; ode-step-name: ode-step -> string
(define (ode-step-name step)
  (ode-step-type-name (ode-step-step-type step)))

;; ode-step-order: ode-step -> integer
(define (ode-step-order step)
  ((ode-step-type-order (ode-step-step-type step))
   (ode-step-state step)))

;; ode-step-apply:
;;   ode-step x real x real x vector of real x vector of real x
;;   vector of real x vector of real x ode-system  -> void
(define (ode-step-apply step t h y y-err dydt-in dydt-out dydt)
  ((ode-step-type-apply (ode-step-step-type step))
   (ode-step-state step) (ode-step-dimension step)
   t h y y-err dydt-in dydt-out dydt))

;; ode-step-reset: ode-step -> void
(define (ode-step-reset step)
  ((ode-step-type-reset (ode-step-step-type step))
   (ode-step-state step) (ode-step-dimension step)))