Compare commits

..

No commits in common. "main" and "minimal-viable-alteration" have entirely different histories.

3 changed files with 21 additions and 20 deletions

View File

@ -163,7 +163,9 @@ void DLASystem::moveLastParticle() {
particleList.pop_back(); // remove particle from particleList particleList.pop_back(); // remove particle from particleList
numParticles--; numParticles--;
setParticleInactive(); setParticleInactive();
} else if (readGrid(newpos) == 0) { }
// check if destination is empty
else if (readGrid(newpos) == 0) {
setGrid(lastP->pos, 0); // set the old grid site to empty setGrid(lastP->pos, 0); // set the old grid site to empty
// update the position // update the position
particleList[numParticles - 1]->pos[0] = newpos[0]; particleList[numParticles - 1]->pos[0] = newpos[0];
@ -176,32 +178,37 @@ void DLASystem::moveLastParticle() {
setParticleInactive(); // make the particle inactive (stuck) setParticleInactive(); // make the particle inactive (stuck)
updateClusterRadius(lastP->pos); // update the cluster radius, addCircle, etc. updateClusterRadius(lastP->pos); // update the cluster radius, addCircle, etc.
} }
} else {
// if we get to here then we are trying to move to an occupied site
// (this should never happen as long as the sticking probability is 1.0)
cerr << "reject " << rr << endl;
cerr << lastP->pos[0] << " " << lastP->pos[1] << endl;
//cerr << newpos[0] << " " << newpos[1] << " " << (int)newpos[0] << endl;
//printOccupied();
} }
} }
// check if the last particle should stick (to a neighbour) // check if the last particle should stick (to a neighbour)
int DLASystem::checkStick() { int DLASystem::checkStick() {
Particle *lastP = particleList[numParticles - 1]; Particle *lastP = particleList[numParticles - 1];
int result = 0;
// loop over neighbours // loop over neighbours
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
double checkpos[2]; double checkpos[2];
setPosNeighbour(checkpos, lastP->pos, i); setPosNeighbour(checkpos, lastP->pos, i);
// if the neighbour is occupied and the particle will stick probabilistically. // if the neighbour is occupied...
if (readGrid(checkpos) == 1 && rgen.random01() < stickProbability) { if (readGrid(checkpos) == 1)
return 1; result = 1;
}
} }
return result;
return 0;
} }
// constructor // constructor
DLASystem::DLASystem(const int maxParticles, const string &csvPath, const double stickProbability) { DLASystem::DLASystem(int maxParticles, string csvPath) {
cerr << "creating system, gridSize " << gridSize << endl; cerr << "creating system, gridSize " << gridSize << endl;
numParticles = 0; numParticles = 0;
endNum = maxParticles; endNum = maxParticles;
this->stickProbability = stickProbability;
// allocate memory for the grid, remember to free the memory in destructor // allocate memory for the grid, remember to free the memory in destructor
grid = new int *[gridSize]; grid = new int *[gridSize];

View File

@ -24,11 +24,6 @@ class DLASystem {
vector<Particle*> particleList; vector<Particle*> particleList;
int numParticles; int numParticles;
/*
* The probability that a particle will stick at a given site when adjacent.
* */
double stickProbability;
// delete particles and clear the particle list // delete particles and clear the particle list
void clearParticles(); void clearParticles();
@ -71,7 +66,7 @@ class DLASystem {
int lastParticleIsActive; int lastParticleIsActive;
// constructor // constructor
explicit DLASystem(int maxParticles, const string &csvPath, double stickProbability); explicit DLASystem(int maxParticles, string csvPath);
// destructor // destructor
~DLASystem(); ~DLASystem();

View File

@ -3,19 +3,18 @@
#include "DLASystem.h" #include "DLASystem.h"
int main(int argc, char **argv) { int main(int argc, char **argv) {
if (argc != 5) { if (argc != 4) {
cerr << "Usage " << argv[0] << " <seed> <maxParticles> <stickProbability> <csvPath>" << endl; cerr << "Usage " << argv[0] << " <seed> <maxParticles> <csvPath>" << endl;
return 1; return 1;
} }
int seed = std::stoi(argv[1]); int seed = std::stoi(argv[1]);
int maxParticles = std::stoi(argv[2]); int maxParticles = std::stoi(argv[2]);
double stickProbability = std::stod(argv[3]); string csvPath = argv[3];
string csvPath = argv[4];
std::cerr << "Setting seed " << seed << endl; std::cerr << "Setting seed " << seed << endl;
// create the system // create the system
auto *sys = new DLASystem(maxParticles, csvPath, stickProbability); auto *sys = new DLASystem(maxParticles, csvPath);
sys->setSeed(seed); sys->setSeed(seed);
sys->running = true; sys->running = true;