menu

Populating the grid

Initialising the model itself

To initialise your grid, simply use:
    let config = { ncol:100, nrow:100, title="MyModel", ... }
    sim = new Simulation(config)
followed by
    sim.makeGridmodel("modelname")

Initialise the grid points with numbers

If your model is simple, you can simply represent different "species" or "individuals" as integer numbers (1,2,3,...,n). Similarly, you may want to represent resource concentrations with simple floating point numbers (0.02,1.29,482.1). To do so (after you have made your GridModel), use either:
    initialiseGrid(@Gridmodel, statename, 1st_number, 1st_fraction, 2nd_number, 2nd_fraction, ...)
    OR
    initialSpot(@Gridmodel, statename, number, spotsize, x, y)

Use cases:

  • In cheater.html: set species '1', '2', and '3', to 33% occupancy each
    sim.initialGrid(sim.cheater, 'species', 1, 0.33, 2, 0.33, 3, 0.33)
  • In petridish.html: inoculate the middle of the grid with 'alive' cells
    sim.initialSpot(sim.cells, 'alive', 1, 2, sim.cells.nr / 2, sim.cells.nc / 2)
  • In tutorial_colony.html: give 100% of grid points external resources (set to 1)
    sim.initialGrid(sim.growth,'external_resources',1000.0,1.0)

Populating the grid points with custom individuals

If your model is a bit more complex, you may want to first define what your individuals look like. To do this, there are two functions analogous to the ones above, but which you can pass a configuration-object with many more options.

First, define your individual(s):
    let individuals = [{alive:1, age:1, name: 'Cacatoo'},{alive:1, age:20, name: 'Cash'}]
And then call the functions "populateSpot" or "populateGrid":
    populateGrid(@Gridmodel, individuals, frequencies)
    OR
    populateSpot(@Gridmodel, individuals, frequencies, size, x, y)

Use cases:

  • In cooperation.html: populate with 'cooperators' and 'cheaters'
    let init_individuals = [{alive:1, helping_rate: helper_rate_cooperator}, {alive:1,helping_rate: helper_rate_cheater}]
    sim.populateSpot(sim.coop, init_individuals, [0.5,0.5], 100, config.ncol/2, config.nrow/2)
  • In tutorial_colony.html: populate with species with different uptake rates
    let species = [{species:1,uptake_rate:0.5,internal_resources:1}, {species:2,uptake_rate:5.0,internal_resources:1}, {species:3,uptake_rate:50.0,internal_resources:1}]
    sim.populateSpot(sim.growth, species, [0.33,0.33,0.33], 15, config.ncol/2, config.nrow/2)

Manually setting the grid points

If you want even more freedom, it's probably best to loop over all the grid points and set them yourself. Here's an example of that, from "spirals.html":

    for (let i = 0; i < sim.spirals.nc; i++) // i are columns
      for (let j = 0; j < sim.spirals.nr; j++) // j are rows
           sim.spirals.grid[i][j]['colour'] = Math.ceil(sim.rng.genrand_real1() * n_species)


or another example from "ode_turing.html":

    for (let i = 0; i < sim.turing.nc; i++) // i are columns
       for (let j = 0; j < sim.turing.nr; j++) // j are rows
            sim.turing.grid[i][j].turingeq.state = [1 + sim.rng.genrand_real1(), 1]