[Pomp-commits] r161 - pkg/src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Sep 21 19:53:38 CEST 2009


Author: kingaa
Date: 2009-09-21 19:53:38 +0200 (Mon, 21 Sep 2009)
New Revision: 161

Modified:
   pkg/src/euler.c
Log:
- fix bug that crops up when dt=0


Modified: pkg/src/euler.c
===================================================================
--- pkg/src/euler.c	2009-09-21 17:53:07 UTC (rev 160)
+++ pkg/src/euler.c	2009-09-21 17:53:38 UTC (rev 161)
@@ -48,7 +48,13 @@
     // It seems to work well, but is not guaranteed: 
     // suggestions would be appreciated.
 
-    if (t+dt >= times[step]) {
+    if (t > times[step]) {
+      error("'times' is not an increasing sequence");
+    }
+    else if (t == times[step]) {
+      dt = 0.0;
+      neuler = 0;
+    } else if (t+dt >= times[step]) {
       dt = times[step] - t; 
       neuler = 1;
     } else {
@@ -138,12 +144,13 @@
       // set some variables to zero
       for (k = 0; k < nzero; k++)
 	xp[zeroindex[k]] = 0.0;
-      
-      pp = &params[npar*p];
-      xp = &x[nvar*(p+nrep*step)];
 
-      (*estep)(xp,pp,stateindex,parindex,covindex,covdim,covar_fn,t,dt);
-      
+      if (t < times[step]) { //  call the simulator only if time elapses
+	pp = &params[npar*p];
+	xp = &x[nvar*(p+nrep*step)];
+	(*estep)(xp,pp,stateindex,parindex,covindex,covdim,covar_fn,t,dt);
+      }
+
     }
   }
 }



More information about the pomp-commits mailing list