Skip to content

Commit

Permalink
Migration finally working, although caveat with updating salt value t…
Browse files Browse the repository at this point in the history
…o be resolved.
  • Loading branch information
highperformancecoder committed Sep 12, 2024
1 parent bc3a653 commit 39765f3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/GUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# list of windows to update each simulation step
windows=[]
runner=Tk()
runner.title('EcoLab')
statusBar=ttk.Label(runner,text='Not started')
statusBar.pack()

Expand Down
16 changes: 13 additions & 3 deletions models/ecolab_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,14 @@ void SpatialModel::setGrid(size_t nx, size_t ny)
numX=nx; numY=ny;
for (size_t i=0; i<numX; ++i)
for (size_t j=0; j<numY; ++j)
insertObject(makeId(i,j));
{
auto o=insertObject(makeId(i,j));
// wire up von Neumann neighborhood
o->neighbours.push_back(makeId(i-1,j));
o->neighbours.push_back(makeId(i+1,j));
o->neighbours.push_back(makeId(i,j-1));
o->neighbours.push_back(makeId(i,j+1));
}
rebuildPtrLists();
}

Expand All @@ -457,9 +464,12 @@ void SpatialModel::generate(unsigned niter)
void SpatialModel::migrate()
{
/* each cell gets a distinct random salt value */
for (auto& i: *this)
(*this)[i]->as<EcolabCell>()->salt=array_urand.rand();
// TODO why doesn't this loop work?
// for (auto& i: *this)
// (*this)[i]->as<EcolabCell>()->salt=array_urand.rand();

for (auto& o: objects) o->salt=array_urand.rand();

// prepareNeighbours

vector<array<int> > delta(size(), array<int>(species.size(),0));
Expand Down
3 changes: 2 additions & 1 deletion models/migration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
ecolab.partitionObjects()
ecolab.cell(4,4).density(nsp*[100])

ecolab.migration(nsp*[1e-5])
ecolab.migration(nsp*[0.5])

from plot import plot
from GUI import gui, statusBar, windows

ecolab.makeConsistent()
def step():
ecolab.migrate()
ecolab.tstep(ecolab.tstep()+1)
Expand Down

0 comments on commit 39765f3

Please sign in to comment.