Skip to content

Commit

Permalink
progress towards first moveKernel test
Browse files Browse the repository at this point in the history
  • Loading branch information
TheoPannetier committed Jan 12, 2024
1 parent 3f4ac87 commit 528de11
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 20 deletions.
59 changes: 41 additions & 18 deletions Individual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -864,8 +864,7 @@ void Individual::moveto(Cell* newCell) {
// Move to a new cell by sampling a dispersal distance from a single or double
// negative exponential kernel
// Returns 1 if still dispersing (including having found a potential patch), otherwise 0
int Individual::moveKernel(Landscape* pLandscape, Species* pSpecies,
const short repType, const bool absorbing)
int Individual::moveKernel(Landscape* pLandscape, Species* pSpecies, const bool absorbing)
{

intptr patch;
Expand Down Expand Up @@ -1815,7 +1814,9 @@ double cauchy(double location, double scale) {
//---------------------------------------------------------------------------

#if RSDEBUG

Cell* Individual::getCurrCell() const {
return pCurrCell;
}

void testIndividual() {

Expand Down Expand Up @@ -1851,30 +1852,52 @@ void testIndividual() {
// Transfers
// Kernel transfer
{
// Landscape ls = createLandscapeFromCells(ls_params, cells, pSp);

// Set up landscape
Landscape ls;
// Simple cell-based landscape layout
// oo
// oo
landParams ls_params;
ls_params.dimX = ls_params.dimY = 100;
ls.setLandParams(ls_params, true);

ls_params.dimX = ls_params.dimY = 2;
vector <Cell*> cells{ new Cell(0, 0, 0, 0), new Cell(1, 1, 0, 0) };
// Set up species for habitat codes
Species sp;
sp.createHabK(1);
sp.setHabK(0, 100.0); // one habitat with K = 100

// Add cells
ls.setCellArray();
vector <Cell*> cells{new Cell(1, 1, 0, 0), new Cell(98, 98, 0, 0)};
for (auto c : cells) {
ls.addCellToLand(c);
}
ls.allocatePatches(&sp);
// Landscape ls = createLandscapeFromCells(cells, ls_params, sp);
Landscape ls;
ls.setLandParams(ls_params, true);
// Add cells
ls.setCellArray();
for (auto c : cells) {
ls.addCellToLand(c);
}
ls.allocatePatches(&sp);

Cell* c = new Cell(1, 1, 0, 0);
Patch* p = (Patch*)cells[0]->getPatch();
Individual ind(cells[0], p, 1, 0, 0, 0.0, false, 0);
Cell* init_cell = ind.getCurrCell();

// ind.status
// land.resol
// species.trfrKernTraits.meanDist1
// species.useFullKernel
// pathData *path; ?
// land.minX etc. dimX dimY
// patch.localK
// bool species.stageStruct
// species trfrMortParams m; m.fixedMort = fixedMort; m.mortAlpha = mortAlpha; m.mortBeta = mortBeta;

int isDispersing = ind.moveKernel(&ls, &sp, false);

// After movement, individual should be...
// in a different cell
Cell* curr_cell = ind.getCurrCell();
// not in a no-data cell
assert(curr_cell != 0);
assert(curr_cell != init_cell);
// (non-absorbing) still within landscape boundaries



// Arrival cell

Expand Down
5 changes: 4 additions & 1 deletion Individual.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ class Individual {
int moveKernel(
Landscape*, // pointer to Landscape
Species*, // pointer to Species
const short, // reproduction type (see Species)
const bool // absorbing boundaries?
);
// Make a single movement step according to a mechanistic movement model
Expand Down Expand Up @@ -252,6 +251,10 @@ class Individual {
const int // year
);
#endif
#if RSDEBUG
// Testing utilities
Cell* getCurrCell() const;
#endif

private:
int indId;
Expand Down
20 changes: 20 additions & 0 deletions Landscape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2644,8 +2644,28 @@ void Landscape::outVisits(int rep, int landNr) {
//---------------------------------------------------------------------------

#if RSDEBUG
// Debug only: shortcut setup utilities

Landscape createLandscapeFromCells(vector<Cell*> cells, const landParams& lp, Species sp) {
// Set up landscape
Landscape ls;
ls.setLandParams(lp, true);
// Add cells
ls.setCellArray();
for (auto c : cells) {
ls.addCellToLand(c);
}
ls.allocatePatches(&sp);
return ls;
}

void testLandscape() {
// test coordinate system
Landscape ls;
landParams ls_params;
ls_params.dimX = ls_params.dimY = 100;
ls.setLandParams(ls_params, true);

}
#endif // RSDEBUG

Expand Down
1 change: 1 addition & 0 deletions Landscape.h
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ extern RSrandom *pRandom;
#if RSDEBUG
extern ofstream DEBUGLOG;
extern void DebugGUI(string);
Landscape createLandscapeFromCells(vector<Cell*> cells, const landParams& lp, Species sp);
void testLandscape();
#endif

Expand Down
2 changes: 1 addition & 1 deletion Population.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ int Population::transfer(Landscape* pLandscape, short landIx)
disperser = inds[i]->moveStep(pLandscape, pSpecies, landIx, sim.absorbing);
}
else {
disperser = inds[i]->moveKernel(pLandscape, pSpecies, reptype, sim.absorbing);
disperser = inds[i]->moveKernel(pLandscape, pSpecies, sim.absorbing);
}
ndispersers += disperser;
if (disperser) {
Expand Down

0 comments on commit 528de11

Please sign in to comment.