# Pattern for splitting the state vector over multiple objects

**URL:** https://discourse.julialang.org/t/pattern-for-splitting-the-state-vector-over-multiple-objects/121072
**Category:** Modelling & Simulations
**Created:** [October 8, 2024, 11:28pm UTC](https://discourse.julialang.org/t/pattern-for-splitting-the-state-vector-over-multiple-objects/121072 "2024-10-08T23:28:31Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![evan-wehi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/evan-wehi/32/32692_2.png) [@evan-wehi](https://discourse.julialang.org/u/evan-wehi)
#### Post date: [October 8, 2024, 11:28pm UTC](https://discourse.julialang.org/t/pattern-for-splitting-the-state-vector-over-multiple-objects/121072/1 "2024-10-08T23:28:31Z")

</div>

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:

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

```

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

```julia
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.
