From 629989f1967306246b6a2559ac16c60fabaae713 Mon Sep 17 00:00:00 2001 From: Joshua Coles Date: Wed, 1 Mar 2023 21:32:35 +0000 Subject: [PATCH] Add stickProbability --- DLASystem.cpp | 25 +++++++++---------------- DLASystem.h | 7 ++++++- mainDLA.cpp | 9 +++++---- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/DLASystem.cpp b/DLASystem.cpp index e006c10..f2b6f87 100644 --- a/DLASystem.cpp +++ b/DLASystem.cpp @@ -163,9 +163,7 @@ void DLASystem::moveLastParticle() { particleList.pop_back(); // remove particle from particleList numParticles--; setParticleInactive(); - } - // check if destination is empty - else if (readGrid(newpos) == 0) { + } else if (readGrid(newpos) == 0) { setGrid(lastP->pos, 0); // set the old grid site to empty // update the position particleList[numParticles - 1]->pos[0] = newpos[0]; @@ -178,37 +176,32 @@ void DLASystem::moveLastParticle() { setParticleInactive(); // make the particle inactive (stuck) 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) int DLASystem::checkStick() { Particle *lastP = particleList[numParticles - 1]; - int result = 0; // loop over neighbours for (int i = 0; i < 4; i++) { double checkpos[2]; setPosNeighbour(checkpos, lastP->pos, i); - // if the neighbour is occupied... - if (readGrid(checkpos) == 1) - result = 1; + // if the neighbour is occupied and the particle will stick probabilistically. + if (readGrid(checkpos) == 1 && rgen.random01() < stickProbability) { + return 1; + } } - return result; + + return 0; } // constructor -DLASystem::DLASystem(int maxParticles, string csvPath) { +DLASystem::DLASystem(const int maxParticles, const string &csvPath, const double stickProbability) { cerr << "creating system, gridSize " << gridSize << endl; numParticles = 0; endNum = maxParticles; + this->stickProbability = stickProbability; // allocate memory for the grid, remember to free the memory in destructor grid = new int *[gridSize]; diff --git a/DLASystem.h b/DLASystem.h index b305c92..b543e59 100644 --- a/DLASystem.h +++ b/DLASystem.h @@ -24,6 +24,11 @@ class DLASystem { vector particleList; int numParticles; + /* + * The probability that a particle will stick at a given site when adjacent. + * */ + double stickProbability; + // delete particles and clear the particle list void clearParticles(); @@ -66,7 +71,7 @@ class DLASystem { int lastParticleIsActive; // constructor - explicit DLASystem(int maxParticles, string csvPath); + explicit DLASystem(int maxParticles, const string &csvPath, double stickProbability); // destructor ~DLASystem(); diff --git a/mainDLA.cpp b/mainDLA.cpp index 0e427be..8f387e3 100644 --- a/mainDLA.cpp +++ b/mainDLA.cpp @@ -3,18 +3,19 @@ #include "DLASystem.h" int main(int argc, char **argv) { - if (argc != 4) { - cerr << "Usage " << argv[0] << " " << endl; + if (argc != 5) { + cerr << "Usage " << argv[0] << " " << endl; return 1; } int seed = std::stoi(argv[1]); int maxParticles = std::stoi(argv[2]); - string csvPath = argv[3]; + double stickProbability = std::stod(argv[3]); + string csvPath = argv[4]; std::cerr << "Setting seed " << seed << endl; // create the system - auto *sys = new DLASystem(maxParticles, csvPath); + auto *sys = new DLASystem(maxParticles, csvPath, stickProbability); sys->setSeed(seed); sys->running = true;