Add stickProbability

This commit is contained in:
Joshua Coles 2023-03-01 21:32:35 +00:00
parent 1366598409
commit 629989f196
3 changed files with 20 additions and 21 deletions

View File

@ -163,9 +163,7 @@ 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];
@ -178,37 +176,32 @@ 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... // if the neighbour is occupied and the particle will stick probabilistically.
if (readGrid(checkpos) == 1) if (readGrid(checkpos) == 1 && rgen.random01() < stickProbability) {
result = 1; return 1;
}
} }
return result;
return 0;
} }
// constructor // constructor
DLASystem::DLASystem(int maxParticles, string csvPath) { DLASystem::DLASystem(const int maxParticles, const string &csvPath, const double stickProbability) {
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,6 +24,11 @@ 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();
@ -66,7 +71,7 @@ class DLASystem {
int lastParticleIsActive; int lastParticleIsActive;
// constructor // constructor
explicit DLASystem(int maxParticles, string csvPath); explicit DLASystem(int maxParticles, const string &csvPath, double stickProbability);
// destructor // destructor
~DLASystem(); ~DLASystem();

View File

@ -3,18 +3,19 @@
#include "DLASystem.h" #include "DLASystem.h"
int main(int argc, char **argv) { int main(int argc, char **argv) {
if (argc != 4) { if (argc != 5) {
cerr << "Usage " << argv[0] << " <seed> <maxParticles> <csvPath>" << endl; cerr << "Usage " << argv[0] << " <seed> <maxParticles> <stickProbability> <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]);
string csvPath = argv[3]; double stickProbability = std::stod(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); auto *sys = new DLASystem(maxParticles, csvPath, stickProbability);
sys->setSeed(seed); sys->setSeed(seed);
sys->running = true; sys->running = true;