From fccb266c893a8c390692aef81f60ccefeb782f65 Mon Sep 17 00:00:00 2001
From: liam <liam@a3d8a0fb-c1db-0310-ace7-a616afeb9e30>
Date: Tue, 25 Sep 2007 01:30:11 +0000
Subject: [PATCH] Define the Jacobian function and struct for the system.

git-svn-id: svn+ssh://pop/opt/space/mathematics/gsl/trunk@3228 a3d8a0fb-c1db-0310-ace7-a616afeb9e30
---
 ordinary-differential-equations.lisp | 41 +++++++++++++++++++++++-----
 1 file changed, 34 insertions(+), 7 deletions(-)

diff --git a/ordinary-differential-equations.lisp b/ordinary-differential-equations.lisp
index 71d22e97..18a46e41 100644
--- a/ordinary-differential-equations.lisp
+++ b/ordinary-differential-equations.lisp
@@ -3,18 +3,22 @@
 ; description: ODE initial value problems                
 ; date:        Sun Apr 15 2007 - 14:19                   
 ; author:      Liam Healy                                
-; modified:    Sat Sep 15 2007 - 19:24
+; modified:    Sun Sep 23 2007 - 18:26
 ;********************************************************
 ;;; $Id: $
 
 (in-package :gsl)
 
-(defun-gsl 
-    "gsl_odeiv_system"
+(cffi:defcstruct ode-system		; gsl_odeiv_system
+  ;; See /usr/include/gsl/gsl_odeiv.h
+  "The definition of an ordinary differential equation system for GSL."
+  (function :pointer)
+  (jacobian :pointer)
+  (dimension :size)
+  (parameters :pointer))
 
-)
+(export 'def-ode-function 'def-jacobian-function)
 
-(export 'def-ode-function)
 (defmacro def-ode-function (name time dependent derivatives &body body)
   "Define a function that will evaluate the right-hand sides (derivatives)
    defining a set of ordinary differential equations (ODE).
@@ -27,8 +31,8 @@
    using a lexical closure."
   `(cffi:defcallback ,name :int
     ((,time :double)
-     (,dependent :pointer)		; This needs to be a C array
-     (,derivatives :pointer)		; This needs to be a C array
+     (,dependent :pointer)
+     (,derivatives :pointer)
      (params :pointer))
     (declare (ignore params) (ignorable ,time))
     ,@body
@@ -41,3 +45,26 @@
   (setf (double-to-cl dydt 0) (- (double-to-cl y 1))
 	(double-to-cl dydt 1) (double-to-cl y 0)))
 |#
+
+(defmacro def-jacobian-function (name time dependent dfdy dfdt &body body)
+  "Define a function that will evaluate the Jacobian (partial derivative)
+   of the set of ordinary differential equations (ODE).
+   The function should take as input the time (a double-float) and
+   dependent variables (a vector of double-floats) and fill the
+   dfdy matrix and dfdt vector with double-floats.
+   It may refer to elements
+   of these vectors (arrays) using the macro double-to-cl.
+   This function may be passed to the GSL ODE integrators.
+   Parameters (non integration variables) may be passed by
+   using a lexical closure."
+  `(cffi:defcallback ,name :int
+    ((,time :double)
+     (,dependent :pointer)
+     (,dfdy :pointer)		; This is a vector but should be CL array
+     (,dfdt :pointer)
+     (params :pointer))
+    (declare (ignore params) (ignorable ,time))
+    ,@body
+    ;; Any errors or warnings should be signalled on the CL side;
+    ;; if the function completes, we will always return success.
+    (cffi:foreign-enum-value 'gsl-errorno :SUCCESS)))
-- 
GitLab