Add stickProbability
This commit is contained in:
parent
1366598409
commit
629989f196
@ -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];
|
||||
|
||||
@ -24,6 +24,11 @@ class DLASystem {
|
||||
vector<Particle*> 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();
|
||||
|
||||
|
||||
@ -3,18 +3,19 @@
|
||||
#include "DLASystem.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
if (argc != 4) {
|
||||
cerr << "Usage " << argv[0] << " <seed> <maxParticles> <csvPath>" << endl;
|
||||
if (argc != 5) {
|
||||
cerr << "Usage " << argv[0] << " <seed> <maxParticles> <stickProbability> <csvPath>" << 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;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user