Compare commits
4 Commits
7041c6d485
...
39231f0d92
| Author | SHA1 | Date | |
|---|---|---|---|
| 39231f0d92 | |||
| 5f0f5c3820 | |||
| f7bfd64616 | |||
| 820323b53d |
4
.gitignore
vendored
4
.gitignore
vendored
@ -110,3 +110,7 @@ fabric.properties
|
||||
|
||||
# Android studio 3.1+ serialized cache file
|
||||
.idea/caches/build_file_checksums.ser
|
||||
|
||||
/run
|
||||
*.csv
|
||||
*.jl
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@ -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); }
|
||||
|
||||
|
||||
2
Makefile
2
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:
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
parallel "../run {1} {2} {3}" ::: $(seq 0 10) ::: $(seq 0 0.05 1) ::: 1000
|
||||
parallel "../run {1} {2} {3}" ::: $(seq 0 10) ::: $(seq 0 0.05 1) ::: $(seq 2000 1000 10000)
|
||||
|
||||
25
mainDLA.cpp
25
mainDLA.cpp
@ -1,7 +1,6 @@
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
#include <vector>
|
||||
#include <math.h>
|
||||
#include <cmath>
|
||||
#include <string>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user