From: Dariusz Murakowski Date: Fri, 1 May 2015 02:47:26 +0000 (-0400) Subject: Fix subtle rare bug involving next timestep = infinity. Also prevent first rxn firing... X-Git-Url: http://src.murakowski.org/?a=commitdiff_plain;h=d5c5d7081885406871152dd10379c1015710566e;p=VirEvoDyn.git Fix subtle rare bug involving next timestep = infinity. Also prevent first rxn firing with zero propensity. --- 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