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
// check if we stick
if (checkStick()) {
if (checkStick() && this->rgen.random01() <= this->stickProbability) {
this->csv_out << frame << "," << lastP->pos[0] << "," << lastP->pos[1] << endl;
setParticleInactive(); // make the particle inactive (stuck)
updateClusterRadius(lastP->pos); // update the cluster radius, addCircle, etc.
@ -197,16 +197,17 @@ int DLASystem::checkStick() {
// 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;
endNum = 1000;
this->csv_out = std::move(csv_out);
// allocate memory for the grid, remember to free the memory in destructor
grid = new int *[gridSize];
for (int i = 0; i < gridSize; i++) {
grid[i] = new int[gridSize];
}
// reset initial parameters
Reset();

View File

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

View File

@ -16,7 +16,7 @@ int main(int argc, char **argv) {
std::ofstream csv_out("./out.csv");
// 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
int seed = 6;