From d5c5d7081885406871152dd10379c1015710566e Mon Sep 17 00:00:00 2001 From: Dariusz Murakowski Date: Thu, 30 Apr 2015 22:47:26 -0400 Subject: [PATCH] Fix subtle rare bug involving next timestep = infinity. Also prevent first rxn firing with zero propensity. --- ss.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ss.cpp b/ss.cpp index ed39d8c..e6f4138 100644 --- a/ss.cpp +++ b/ss.cpp @@ -269,11 +269,11 @@ void simulate(Rxn_parray &reactions, Species_parray &species, double t_end, long // stop if time runs out or too many steps or no more reactions will occur for (; (max_steps == 0 || step < max_steps) && (t < t_end) && (total_propensity > 0.0); ++step) { - double rand = (1.0-gsl_rng_uniform_pos(rnd)) * total_propensity; // uniform on (0,R] + double rand = (1.0-gsl_rng_uniform(rnd)) * total_propensity; // uniform on (0,R], because reasons double a_sum = 0.0; // time to reaction - dt = -log(gsl_rng_uniform(rnd)) / total_propensity; + dt = -log(gsl_rng_uniform_pos(rnd)) / total_propensity; // disallow 0.0 when calculating log(r), r in (0,1) t += dt; // determine next reaction -- 2.7.4