Plot the protein amount in each cell and think about the model you've created. After the first division, both cells have the same value. So at exactly the same time, you have an event fire. The "maximum" (whichever index is lower, so 1) will split, while 2 will keep growing above 1. But now that u[2] > 1
, the rootfinding condition 1-maximum(u)
will never hit zero again, and thus no more splits will occur. This means you'll have two splits total, i.e. 3 cells.
Remember, programs will do exactly what you tell them to. I assume that what you meant was, as your effect, split any
cells that are greater than or equal to 1. If that's the affect!
that you wanted, then you'd have to write it:
function affect!(integrator)
u = integrator.u
idxs = findall(x->x>=1-eps(eltype(u)),u)
resize!(integrator,length(u)+length(idxs))
u[idxs] ./ 2
u[end-idxs:end] = 0.5
nothing
end
would be one way to do it, and of course there are many others.