changeset 3995:ee0304212be0

[project @ 2002-07-17 04:32:42 by jwe]
author jwe
date Wed, 17 Jul 2002 04:32:42 +0000
parents a41827ec5677
children 98107d72871c
files liboctave/ChangeLog liboctave/DASPK.cc liboctave/DASPK.h liboctave/DASRT.cc liboctave/DASRT.h liboctave/DASSL.cc liboctave/DASSL.h liboctave/LSODE.cc liboctave/LSODE.h liboctave/ODESSA.cc liboctave/ODESSA.h liboctave/base-dae.h liboctave/base-de.h
diffstat 13 files changed, 123 insertions(+), 250 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/ChangeLog
+++ b/liboctave/ChangeLog
@@ -1,5 +1,15 @@
 2002-07-16  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
+	* base-de.h (base_diff_eqn::stop_time,
+	base_diff_eqn::stop_time_set, base_diff_eqn::restart,
+	base_diff_eqn::integration_error): New data members.
+	(base_diff_eqn::set_stop_time, base_diff_eqn::clear_stop_time,
+	base_diff_eqn::force_restart, base_diff_eqn::integration_ok,
+	base_diff_eqn::error_message): New member functions.
+	* LSODE.h, LSODE.cc, DASSL.h, DASSL.cc, DASPK.h, DASPK.cc,
+	DASRT.h, DASRT.cc, ODESSA.h, ODESSA.cc: Delete corresponding data
+	members and functions.
+
 	* DASRT.h (DASRT::set_ng, DASRT::get_ng): Delete
 	* DASRT.cc (DASRT::DASRT): Set ng here.
 	(DASRT::integrate): Don't forget to set nn.
--- a/liboctave/DASPK.cc
+++ b/liboctave/DASPK.cc
@@ -64,9 +64,6 @@
 
 DASPK::DASPK (void) : DAE ()
 {
-  stop_time_set = 0;
-  stop_time = 0.0;
-
   sanity_checked = 0;
 
   info.resize (15);
@@ -80,9 +77,6 @@
 {
   n = size ();
 
-  stop_time_set = 0;
-  stop_time = 0.0;
-
   sanity_checked = 0;
 
   info.resize (20);
@@ -97,9 +91,6 @@
 {
   n = size ();
 
-  stop_time_set = 0;
-  stop_time = 0.0;
-
   DAEFunc::set_function (f.function ());
   DAEFunc::set_jacobian_function (f.jacobian_function ());
 
@@ -111,26 +102,6 @@
     info.elem (i) = 0;
 }
 
-void
-DASPK::force_restart (void)
-{
-  restart = 1;
-  integration_error = 0;
-}
-
-void
-DASPK::set_stop_time (double tt)
-{
-  stop_time_set = 1;
-  stop_time = tt;
-}
-
-void
-DASPK::clear_stop_time (void)
-{
-  stop_time_set = 0;
-}
-
 int
 ddaspk_f (const double& time, const double *state, const double *deriv,
 	  const double&, double *delta, int& ires, double *, int *)
@@ -207,7 +178,7 @@
 
   if (restart)
     {
-      restart = 0;
+      restart = false;
       info.elem (0) = 0;
     }
 
@@ -229,7 +200,7 @@
   if (rwork.length () != lrw)
     rwork.resize (lrw);
 
-  integration_error = 0;
+  integration_error = false;
 
   if (DAEFunc::jacobian_function ())
     info.elem (4) = 1;
@@ -254,7 +225,7 @@
 	  (*current_liboctave_error_handler)
 	    ("daspk: inconsistent sizes for state and residual vectors");
 
-	  integration_error = 1;
+	  integration_error = true;
 	  return retval;
 	}
 
@@ -304,7 +275,7 @@
 
   if (f77_exception_encountered)
     {
-      integration_error = 1;
+      integration_error = true;
       (*current_liboctave_error_handler) ("unrecoverable error in daspk");
     }
   else
@@ -346,7 +317,7 @@
 		  // and control is returned to the calling program. For
 		  // example, this occurs when invalid input is detected.
 	default:
-	  integration_error = 1;
+	  integration_error = true;
 	  break;
 	}
     }
@@ -505,6 +476,21 @@
   return retval;
 }
 
+std::string
+DASPK::error_message (void) const
+{
+  std::string retval;
+
+  switch (idid)
+    {
+    default:
+      retval = "unknown error state";
+      break;
+    }
+
+  return retval;
+}
+
 /*
 ;;; Local Variables: ***
 ;;; mode: C++ ***
--- a/liboctave/DASPK.h
+++ b/liboctave/DASPK.h
@@ -120,11 +120,6 @@
 
   ~DASPK (void) { }
 
-  void force_restart (void);
-
-  void set_stop_time (double t);
-  void clear_stop_time (void);
-
   ColumnVector do_integrate (double t);
 
   Matrix do_integrate (const ColumnVector& tout);
@@ -136,14 +131,11 @@
   Matrix integrate (const ColumnVector& tout, Matrix& xdot_out,
 		    const ColumnVector& tcrit); 
 
+  std::string error_message (void) const;
+
 private:
 
-  double stop_time;
-  int stop_time_set;
-
   int n;
-  int integration_error;
-  int restart;
   int liw;  
   int lrw;
   int idid;
--- a/liboctave/DASRT.cc
+++ b/liboctave/DASRT.cc
@@ -147,10 +147,6 @@
   : DAERT ()
 {
   initialized = false;
-  restart = false;
-
-  stop_time_set = false;
-  stop_time = 0.0;
 
   sanity_checked = false;
 
@@ -168,10 +164,6 @@
   n = size ();
 
   initialized = false;
-  restart = false;
-
-  stop_time_set = false;
-  stop_time = 0.0;
 
   liw = 20 + n;
   lrw = 50 + 9*n + n*n;
@@ -200,10 +192,6 @@
   n = size ();
 
   initialized = false;
-  restart = false;
-
-  stop_time_set = false;
-  stop_time = 0.0;
 
   sanity_checked = false;
 
@@ -226,26 +214,6 @@
 }
 
 void
-DASRT::force_restart (void)
-{
-  restart = true;
-  integration_error = false;
-}
-
-void
-DASRT::set_stop_time (double t)
-{
-  stop_time_set = true;
-  stop_time = t;
-}
-
-void
-DASRT::clear_stop_time (void)
-{
-  stop_time_set = false;
-}
-
-void
 DASRT::integrate (double tout)
 {
   DASRT_result retval;
@@ -418,8 +386,6 @@
   Matrix xdot_out;
   ColumnVector t_out = tout;
 
-  int oldj = 0;
-
   int n_out = tout.capacity ();
 
   if (n_out > 0 && n > 0)
@@ -587,6 +553,21 @@
   return retval;
 }
 
+std::string
+DASRT::error_message (void) const
+{
+  std::string retval;
+
+  switch (idid)
+    {
+    default:
+      retval = "unknown error state";
+      break;
+    }
+
+  return retval;
+}
+
 /*
 ;;; Local Variables: ***
 ;;; mode: C++ ***
--- a/liboctave/DASRT.h
+++ b/liboctave/DASRT.h
@@ -165,29 +165,19 @@
 
   ~DASRT (void) { }
 
-  void force_restart (void);
-
-  void set_stop_time (double t);
-  void clear_stop_time (void);
-
   DASRT_result integrate (const ColumnVector& tout);
 
   DASRT_result integrate (const ColumnVector& tout,
 			  const ColumnVector& tcrit); 
 
+  std::string error_message (void) const;
+
 private:
 
   bool initialized;
 
   bool sanity_checked;
 
-  bool stop_time_set;
-  double stop_time;
-
-  bool restart;
-
-  bool integration_error;
-
   int liw;  
   int lrw;
   int idid;
--- a/liboctave/DASSL.cc
+++ b/liboctave/DASSL.cc
@@ -56,9 +56,6 @@
 
 DASSL::DASSL (void) : DAE ()
 {
-  stop_time_set = false;
-  stop_time = 0.0;
-
   liw = 0;
   lrw = 0;
 
@@ -75,9 +72,6 @@
 {
   n = size ();
 
-  stop_time_set = false;
-  stop_time = 0.0;
-
   liw = 20 + n;
   lrw = 40 + 9*n + n*n;
 
@@ -92,9 +86,6 @@
 {
   n = size ();
 
-  stop_time_set = false;
-  stop_time = 0.0;
-
   DAEFunc::set_function (f.function ());
   DAEFunc::set_jacobian_function (f.jacobian_function ());
 
@@ -109,26 +100,6 @@
     info.elem (i) = 0;
 }
 
-void
-DASSL::force_restart (void)
-{
-  restart = 1;
-  integration_error = false;
-}
-
-void
-DASSL::set_stop_time (double tt)
-{
-  stop_time_set = true;
-  stop_time = tt;
-}
-
-void
-DASSL::clear_stop_time (void)
-{
-  stop_time_set = false;
-}
-
 int
 ddassl_f (const double& time, const double *state, const double *deriv,
 	  double *delta, int& ires, double *, int *)
@@ -192,7 +163,7 @@
 
   if (restart)
     {
-      restart = 0;
+      restart = false;
       info.elem (0) = 0;
     }
 
@@ -477,6 +448,21 @@
   return retval;
 }
 
+std::string
+DASSL::error_message (void) const
+{
+  std::string retval;
+
+  switch (idid)
+    {
+    default:
+      retval = "unknown error state";
+      break;
+    }
+
+  return retval;
+}
+
 /*
 ;;; Local Variables: ***
 ;;; mode: C++ ***
--- a/liboctave/DASSL.h
+++ b/liboctave/DASSL.h
@@ -120,11 +120,6 @@
 
   ~DASSL (void) { }
 
-  void force_restart (void);
-
-  void set_stop_time (double t);
-  void clear_stop_time (void);
-
   ColumnVector do_integrate (double t);
 
   Matrix do_integrate (const ColumnVector& tout);
@@ -136,18 +131,15 @@
   Matrix integrate (const ColumnVector& tout, Matrix& xdot_out,
 		    const ColumnVector& tcrit); 
 
+  std::string error_message (void) const;
+
 private:
 
-  double stop_time;
-  int stop_time_set;
-
   int n;
-  int integration_error;
-  int restart;
   int liw;  
   int lrw;
   int idid;
-  int sanity_checked;
+  bool sanity_checked;
   Array<int> info;
   Array<int> iwork;
   Array<double> rwork;
--- a/liboctave/LSODE.cc
+++ b/liboctave/LSODE.cc
@@ -70,17 +70,11 @@
 {
   n = size ();
 
-  stop_time_set = 0;
-  stop_time = 0.0;
-
-  integration_error = 0;
-  restart = 1;
-
   istate = 1;
   itask = 1;
   iopt = 0;
 
-  sanity_checked = 0;
+  sanity_checked = false;
 }
 
 LSODE::LSODE (const ColumnVector& state, double time, const ODEFunc& f)
@@ -88,36 +82,11 @@
 {
   n = size ();
 
-  stop_time_set = 0;
-  stop_time = 0.0;
-
-  integration_error = 0;
-  restart = 1;
-
   istate = 1;
   itask = 1;
   iopt = 0;
 
-  sanity_checked = 0;
-}
-
-void
-LSODE::force_restart (void)
-{
-  restart = 1;
-}
-
-void
-LSODE::set_stop_time (double time)
-{
-  stop_time_set = 1;
-  stop_time = time;
-}
-
-void
-LSODE::clear_stop_time (void)
-{
-  stop_time_set = 0;
+  sanity_checked = false;
 }
 
 int
@@ -169,7 +138,7 @@
 
   if (restart)
     {
-      restart = 0;
+      restart = false;
       istate = 1;
     }
 
@@ -207,7 +176,7 @@
 	rwork.elem (i) = 0;
     }
 
-  integration_error = 0;
+  integration_error = false;
 
   double *xp = x.fortran_vec ();
 
@@ -228,11 +197,11 @@
 	  (*current_liboctave_error_handler)
 	    ("lsode: inconsistent sizes for state and derivative vectors");
 
-	  integration_error = 1;
+	  integration_error = true;
 	  return retval;
 	}
 
-      sanity_checked = 1;
+      sanity_checked = true;
     }
 
   if (stop_time_set)
@@ -263,7 +232,7 @@
       (*current_liboctave_error_handler)
 	("lsode: inconsistent sizes for state and absolute tolerance vectors");
 
-      integration_error = 1;
+      integration_error = true;
       return retval;
     }
 
@@ -301,14 +270,14 @@
 
   if (f77_exception_encountered)
     {
-      integration_error = 1;
+      integration_error = true;
       (*current_liboctave_error_handler) ("unrecoverable error in lsode");
     }
   else
     {
       switch (istate)
 	{
-	case -13: // Return requested in user-supplied function.
+	case -13: // return requested in user-supplied function.
 	case -6:  // error weight became zero during problem. (solution
 	          // component i vanished, and atol or atol(i) = 0.)
 	case -5:  // repeated convergence failures (perhaps bad jacobian
@@ -317,7 +286,7 @@
 	case -3:  // illegal input detected (see printed message).
 	case -2:  // excess accuracy requested (tolerances too small).
 	case -1:  // excess work done on this call (perhaps wrong mf).
-	  integration_error = 1;
+	  integration_error = true;
 	  break;
 
 	case 2:  // lsode was successful
@@ -443,7 +412,7 @@
 	  double next_out;
 	  while (i_out < n_out)
 	    {
-	      int do_restart = 0;
+	      bool do_restart = false;
 
 	      next_out = tout.elem (i_out);
 	      if (i_crit < n_crit)
@@ -459,7 +428,7 @@
 		  save_output = 1;
 		  i_out++;
 		  i_crit++;
-		  do_restart = 1;
+		  do_restart = true;
 		}
 	      else if (next_crit < next_out)
 		{
@@ -469,7 +438,7 @@
 		      t_out = next_crit;
 		      save_output = 0;
 		      i_crit++;
-		      do_restart = 1;
+		      do_restart = true;
 		    }
 		  else
 		    {
--- a/liboctave/LSODE.h
+++ b/liboctave/LSODE.h
@@ -153,11 +153,6 @@
 
   ~LSODE (void) { }
 
-  void force_restart (void);
-
-  void set_stop_time (double t);
-  void clear_stop_time (void);
-
   ColumnVector do_integrate (double t);
 
   Matrix do_integrate (const ColumnVector& tout);
@@ -166,18 +161,11 @@
 
   int integration_state (void) const { return istate; }
 
-  bool integration_ok (void) const { return ! integration_error; }
-
   std::string error_message (void) const;
 
 private:
 
-  double stop_time;
-  int stop_time_set;
-
   int n;
-  int integration_error;
-  int restart;
   int method_flag;
   Array<int> iwork;
   Array<double> rwork;
@@ -186,7 +174,7 @@
   int iopt;
   int liw;
   int lrw;
-  int sanity_checked;
+  bool sanity_checked;
 
   friend int lsode_f (int *neq, double *t, double *y, double *ydot);
 
--- a/liboctave/ODESSA.cc
+++ b/liboctave/ODESSA.cc
@@ -176,11 +176,6 @@
   neq.resize(2);
   n = size ();
 
-  stop_time_set = false;
-  stop_time = 0.0;
-
-  integration_error = false;
-  restart = true;
   iopt.resize(4);
 
   istate = 1;
@@ -201,14 +196,6 @@
   neq.resize(2);
   n = size ();
 
-  stop_time_set = false;
-  stop_time = 0.0;
- 
-  ODESFunc::operator = (f);
-
-  integration_error = false;
-  restart = true;
-
   iopt.resize(4);
   istate = 1;
   itask = 1;
@@ -230,7 +217,6 @@
   : ODES (state, theta, time, f)
 {
   initialized = false;
-  restart = false;
 
   neq.resize(2);
   n = state.length();
@@ -239,11 +225,6 @@
   neq(0) = n;
   neq(1) = npar;
 
-  stop_time_set = false;
-  stop_time = 0.0;
-
-  ODESFunc::operator = (f);
-
   sx0 = sensitivity_guess;
   par.resize (npar);
 
@@ -267,25 +248,6 @@
 }
 
 void
-ODESSA::force_restart (void)
-{
-  restart = true;
-}
-
-void
-ODESSA::set_stop_time (double time)
-{
-  stop_time_set = true;
-  stop_time = time;
-}
-
-void
-ODESSA::clear_stop_time (void)
-{
-  stop_time_set = 0;
-}
-
-void
 ODESSA::integrate (double tout)
 {
   ODESSA_result retval;
--- a/liboctave/ODESSA.h
+++ b/liboctave/ODESSA.h
@@ -192,11 +192,6 @@
 
   ~ODESSA (void) { }
 
-  void force_restart (void);
-
-  void set_stop_time (double t);
-  void clear_stop_time (void);
-
   ODESSA_result integrate (const ColumnVector& tout);
 
   ODESSA_result integrate (const ColumnVector& tout,
@@ -204,8 +199,6 @@
 
   int integration_state (void) const { return istate; }
 
-  bool integration_ok (void) const { return ! integration_error; }
-
   std::string error_message (void) const;
 
 private:
@@ -214,13 +207,6 @@
 
   bool sanity_checked;
 
-  bool stop_time_set;
-  double stop_time;
-
-  bool restart;
-
-  bool integration_error;
-
   int liw;  
   int lrw;
   int method_flag;
--- a/liboctave/base-dae.h
+++ b/liboctave/base-dae.h
@@ -58,8 +58,7 @@
   void initialize (const ColumnVector& x0, double t0)
     {
       base_diff_eqn::initialize (x0, t0);
-      xdot.resize (x0.length (), 0.0);
-      force_restart ();
+      xdot = ColumnVector (x0.length (), 0.0);
     }
 
   void initialize (const ColumnVector& x0, const ColumnVector& xdot0,
@@ -67,7 +66,6 @@
     {
       base_diff_eqn::initialize (x0, t0);
       xdot = xdot0;
-      force_restart ();
     }
 
   ColumnVector state_derivative (void) { return xdot; }
--- a/liboctave/base-de.h
+++ b/liboctave/base-de.h
@@ -23,6 +23,8 @@
 #if !defined (octave_base_de_h)
 #define octave_base_de_h 1
 
+#include <string>
+
 #include "dColVector.h"
 #include "dMatrix.h"
 
@@ -31,11 +33,17 @@
 {
 public:
 
-  base_diff_eqn (void) : x (), t (0.0) { }
+  base_diff_eqn (void)
+    : x (), t (0.0), stop_time (0.0), stop_time_set (false),
+      restart (true), integration_error (false) { } 
 
-  base_diff_eqn (const ColumnVector& xx, double tt) : x (xx), t (tt) { }
+  base_diff_eqn (const ColumnVector& xx, double tt)
+    : x (xx), t (tt), stop_time (0.0), stop_time_set (false),
+      restart (true), integration_error (false) { }
 
-  base_diff_eqn (const base_diff_eqn& a) : x (a.x), t (a.t) { }
+  base_diff_eqn (const base_diff_eqn& a)
+    : x (a.x), t (a.t), stop_time (0.0), stop_time_set (false),
+      restart (true), integration_error (false) { }
 
   virtual ~base_diff_eqn (void) { }
 
@@ -45,18 +53,20 @@
 	{
 	  x = a.x;
 	  t = a.t;
+	  stop_time = a.stop_time;
+	  stop_time_set = a.stop_time_set;
+	  restart = a.restart;
+	  integration_error = a.integration_error;
 	}
+
       return *this;
     }
 
-  // There must be a way for us to force the integration to restart.
-
-  virtual void force_restart (void) = 0;
-
   void initialize (const ColumnVector& x0, double t0)
     {
       x = x0;
       t = t0;
+      integration_error = false;
       force_restart ();
     }
 
@@ -66,10 +76,33 @@
 
   double time (void) const { return t; }
 
+  void set_stop_time (double t)
+    {
+      stop_time_set = true;
+      stop_time = t;
+    }
+
+  void clear_stop_time (void) { stop_time_set = false; }
+
+  virtual void force_restart (void) { restart = true; }
+
+  bool integration_ok (void) const { return ! integration_error; }
+
+  virtual std::string error_message (void) const = 0;
+
 protected:
 
   ColumnVector x;
+
   double t;
+
+  double stop_time;
+
+  bool stop_time_set;
+
+  bool restart;
+
+  bool integration_error;
 };
 
 #endif