Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing #668 ODECsolver not handling bimolecular reactions correctly #673

Merged
merged 1 commit into from
Jan 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions gillespy2/solvers/cpp/c_base/ode_cpp_solver/ODESolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}
}
Expand Down