diff --git a/DLASystem.cpp b/DLASystem.cpp index fc592a6..b650aa5 100644 --- a/DLASystem.cpp +++ b/DLASystem.cpp @@ -31,32 +31,6 @@ void DLASystem::clearParticles() { particleList.clear(); } -// remove any existing particles and setup initial condition -void DLASystem::Reset() { - // stop running - running = false; - frame = 0; - - clearParticles(); - - lastParticleIsActive = 0; - - // set the grid to zero - for (int i = 0; i < gridSize; i++) { - for (int j = 0; j < gridSize; j++) { - grid[i][j] = 0; - } - } - - // setup initial condition and parameters - addCircle = 10; - killCircle = 2.0 * addCircle; - clusterRadius = 0.0; - // add a single particle at the origin - double pos[] = {0.0, 0.0}; - addParticle(pos); -} - // set the value of a grid cell for a particular position // note the position has the initial particle at (0,0) // but this corresponds to the middle of the grid array ie grid[ halfGrid ][ halfGrid ] @@ -194,23 +168,46 @@ int DLASystem::checkStick() { // constructor DLASystem::DLASystem(Config config) - : stickProbability(config.stickProbability), csv_out(std::move(config.csv)), endNum(config.maxParticles) { - cout << "creating system, gridSize " << gridSize << endl; + : stickProbability(config.stickProbability), + csv_out(std::move(config.csv)), + endNum(config.maxParticles), + frame(0), + running(false), + lastParticleIsActive(false) { + cout << "GridSize: " << gridSize << endl; rgen.setSeed(config.seed); - // allocate memory for the grid, remember to free the memory in destructor + /* + * Handle grid data structure. + * */ + grid = new int *[gridSize]; for (int i = 0; i < gridSize; i++) { grid[i] = new int[gridSize]; } - // reset initial parameters - Reset(); + // set the grid to zero + for (int i = 0; i < gridSize; i++) { + for (int j = 0; j < gridSize; j++) { + grid[i][j] = 0; + } + } + // Add particle to the centre of the grid to start + double pos[] = {0.0, 0.0}; + addParticle(pos); + + // Make sure to include the central location in our csv. this->csv_out << 0 << "," << 0 << "," << 0 << std::endl; + /* + * System behaviour parameters + * */ addRatio = 1.2; // how much bigger the addCircle should be, compared to cluster radius killRatio = 1.7; // how much bigger is the killCircle, compared to the addCircle + addCircle = 10; + killCircle = 2.0 * addCircle; + clusterRadius = 0.0; } // destructor @@ -222,9 +219,8 @@ DLASystem::~DLASystem() { delete[] grid[i]; delete[] grid; - csv_out.flush(); - if (csv_out.is_open()) { + csv_out.flush(); csv_out.close(); } } diff --git a/DLASystem.h b/DLASystem.h index e73f8d6..a1ad58e 100644 --- a/DLASystem.h +++ b/DLASystem.h @@ -80,9 +80,6 @@ public: // destructor ~DLASystem(); - // delete all particles and reset - void Reset(); - // this sets the seed for the random numbers void setSeed(int s) { rgen.setSeed(s); } diff --git a/Makefile b/Makefile index 1397565..6d820a8 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ CXXFLAGS = -Wall -Wextra -g -O0 -std=c++20 -stdlib=libc++ IFLAGS = -I/usr/local/include -I/usr/include -LFLAGS = -L/usr/local/lib -lm -framework OpenGL -framework GLUT +LFLAGS = -L/usr/local/lib -lm # ------------------------------------------ # FOR GENERIC MAKEFILE: diff --git a/mainDLA.cpp b/mainDLA.cpp index 418791e..487b433 100644 --- a/mainDLA.cpp +++ b/mainDLA.cpp @@ -1,7 +1,6 @@ #include -#include #include -#include +#include #include #include "DLASystem.h" @@ -9,9 +8,9 @@ using std::cout; using std::endl; -// this is a global pointer, which is how we access the system itself -DLASystem *sys; - +/* + * In a proper project I would write a better argument parser, don't care here, just exit with an error if it is wrong. + * */ Config::Config(int argc, char **argv) { if (argc != 4) { exit(1); @@ -30,26 +29,30 @@ Config::Config(int argc, char **argv) { std::ofstream csv_out(str.str()); this->csv = std::move(csv_out); + // Add headers to csv output this->csv << "frame" << "," << "x" << "," << "y" << std::endl; + + cout << + "seed: " << seed << ", " << + "stickProbability: " << stickProbability << ", " << + "maxParticles: " << maxParticles << + endl; } } int main(int argc, char **argv) { Config config(argc, argv); - cout << "Seed: " << config.seed << ", Stick P: " << config.stickProbability << endl; - // create the system - sys = new DLASystem(std::move(config)); + // Create the system + auto *sys = new DLASystem(std::move(config)); sys->setRunning(); /* - * NOTE: We run at max speed as rendering is handled by a different engine so we simply want to hjand + * NOTE: We run at max speed as rendering is handled by a different engine so we don't need to care. * */ while (sys->running) { sys->Update(); } - cout << "hey" << endl; - return 0; }