Add stick probability

This commit is contained in:
Joshua Coles 2023-02-19 18:22:12 +00:00
parent 863fd61d28
commit c1b4b6bab1
3 changed files with 8 additions and 5 deletions

View File

@ -167,7 +167,7 @@ void DLASystem::moveLastParticle() {
setGrid(lastP->pos, 1); // set the new grid site to be occupied setGrid(lastP->pos, 1); // set the new grid site to be occupied
// check if we stick // check if we stick
if (checkStick()) { if (checkStick() && this->rgen.random01() <= this->stickProbability) {
this->csv_out << frame << "," << lastP->pos[0] << "," << lastP->pos[1] << endl; this->csv_out << frame << "," << lastP->pos[0] << "," << lastP->pos[1] << endl;
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.
@ -197,16 +197,17 @@ int DLASystem::checkStick() {
// constructor // constructor
DLASystem::DLASystem(std::ofstream csv_out) { DLASystem::DLASystem(std::ofstream csv_out, double stickProbability)
: stickProbability(stickProbability), csv_out(std::move(csv_out)) {
cout << "creating system, gridSize " << gridSize << endl; cout << "creating system, gridSize " << gridSize << endl;
endNum = 1000; endNum = 1000;
this->csv_out = std::move(csv_out);
// 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];
for (int i = 0; i < gridSize; i++) { for (int i = 0; i < gridSize; i++) {
grid[i] = new int[gridSize]; grid[i] = new int[gridSize];
} }
// reset initial parameters // reset initial parameters
Reset(); Reset();

View File

@ -30,6 +30,8 @@ private:
double addCircle; double addCircle;
double killCircle; double killCircle;
double stickProbability;
// size of grid // size of grid
static const int gridSize = 1600; static const int gridSize = 1600;
int **grid; // this will be a 2d array that stores whether each site is occupied int **grid; // this will be a 2d array that stores whether each site is occupied
@ -64,7 +66,7 @@ public:
int lastParticleIsActive; int lastParticleIsActive;
// constructor // constructor
DLASystem(std::ofstream csv_out); DLASystem(std::ofstream csv_out, double stickProbability);
// destructor // destructor
~DLASystem(); ~DLASystem();

View File

@ -16,7 +16,7 @@ int main(int argc, char **argv) {
std::ofstream csv_out("./out.csv"); std::ofstream csv_out("./out.csv");
// create the system // create the system
sys = new DLASystem(std::move(csv_out)); sys = new DLASystem(std::move(csv_out), 0.5);
// this is the seed for the random numbers // this is the seed for the random numbers
int seed = 6; int seed = 6;