From 08c019772e895e5af2539dabcece39545bb2abc3 Mon Sep 17 00:00:00 2001 From: Brian Drawert Date: Mon, 10 Jan 2022 13:56:30 -0800 Subject: [PATCH] Fixing #668 ODECsolver not handling bimolecular reactions correctly --- .../cpp/c_base/ode_cpp_solver/ODESolver.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/gillespy2/solvers/cpp/c_base/ode_cpp_solver/ODESolver.cpp b/gillespy2/solvers/cpp/c_base/ode_cpp_solver/ODESolver.cpp index 04ba23029..33016c3c6 100644 --- a/gillespy2/solvers/cpp/c_base/ode_cpp_solver/ODESolver.cpp +++ b/gillespy2/solvers/cpp/c_base/ode_cpp_solver/ODESolver.cpp @@ -169,16 +169,12 @@ namespace Gillespy for (sunindextype species_index = 0; species_index < number_species; species_index++) { - // If the species is a product of this reaction, add the propensity function. - if (model->reactions[reaction_index].species_change[species_index] > 0) + // If the species is a product (positive) or reactant (negativ) of this reaction, + // add the propensity function multiplied by the species_change value (e.g -2 for + // a bi-molecular reaction reactants). + if (model->reactions[reaction_index].species_change[species_index] != 0) { - dydata[species_index] += propensity[reaction_index]; - } - - // If the species is a reactant, subtract the propensity function. - else if (model->reactions[reaction_index].species_change[species_index] < 0) - { - dydata[species_index] -= propensity[reaction_index]; + dydata[species_index] += propensity[reaction_index] * model->reactions[reaction_index].species_change[species_index]; } } }