Pattern for splitting the state vector over multiple objects

I’m writing a library that will be used to test ideas in immune cell population dynamics. A characteristic of this biology is that the population size, and hence the state vector length, can vary by orders of magnitude over the course of a simulation.

Ideally, users of the library will work with objects that (simplistically) look like:

struct Cell
  state::Vector{Float64}
  [other parameters]
end

The user RHS functions will be passed cells, i.e.

deriv = rhs(cell, ...)

The DE library works on a single state vector so my library will need to take care of wrapping and unwrapping the state and derivative vectors. The question is, is there a suggested pattern for these use cases?

The simplest option is to copy the state into the cell for each function evaluation - with obvious performance cost. Another option is to have the cell state as a view into the state vector. The problem with this is that when cells die, many views need will to be regenerated.

1 Like