This commit is contained in:
Joshua Coles 2023-02-09 12:41:41 +00:00
parent f79763eee4
commit 496c1022db
7 changed files with 428 additions and 404 deletions

View File

@ -90,8 +90,7 @@ int DLASystem::checkStop() {
cout << "STOP" << endl; cout << "STOP" << endl;
glutPostRedisplay(); // update display glutPostRedisplay(); // update display
return 1; return 1;
} } else return 0;
else return 0;
} }
// add a particle to the system at a specific position // add a particle to the system at a specific position
@ -213,8 +212,7 @@ void DLASystem::moveLastParticle() {
logfile << numParticles << " " << clusterRadius << endl; logfile << numParticles << " " << clusterRadius << endl;
} }
} }
} } else {
else {
// if we get to here then we are trying to move to an occupied site // 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) // (this should never happen as long as the sticking probability is 1.0)
cout << "reject " << rr << endl; cout << "reject " << rr << endl;
@ -279,7 +277,6 @@ DLASystem::~DLASystem() {
} }
// this draws the system // this draws the system
void DLASystem::DrawSquares() { void DLASystem::DrawSquares() {

View File

@ -5,7 +5,9 @@
#include <fstream> #include <fstream>
#include <stdio.h> #include <stdio.h>
#include <vector> #include <vector>
#define _USE_MATH_DEFINES #define _USE_MATH_DEFINES
#include <math.h> #include <math.h>
#include <random> #include <random>
#include <string> #include <string>
@ -81,6 +83,7 @@ class DLASystem {
// constructor // constructor
DLASystem(Window *set_win); DLASystem(Window *set_win);
// destructor // destructor
~DLASystem(); ~DLASystem();
@ -95,16 +98,23 @@ class DLASystem {
// stop/start the algorithm // stop/start the algorithm
void setRunning() { if (checkStop() == 0) running = 1; } void setRunning() { if (checkStop() == 0) running = 1; }
void pauseRunning() { running = 0; } void pauseRunning() { running = 0; }
// set whether it runs fast or slow // set whether it runs fast or slow
void setSlow() { slowNotFast = 1; } void setSlow() { slowNotFast = 1; }
void setFast() { slowNotFast = 0; } void setFast() { slowNotFast = 0; }
void setSuperFast() { slowNotFast = -1; } void setSuperFast() { slowNotFast = -1; }
// set which part of the grid is visible on the screen // set which part of the grid is visible on the screen
// basically the screen shows co-ordinates -vv < x < vv // basically the screen shows co-ordinates -vv < x < vv
// where vv is the input value // where vv is the input value
void setViewSize(double vv) { viewSize = vv; drawScale = 2.0/viewSize; } void setViewSize(double vv) {
viewSize = vv;
drawScale = 2.0 / viewSize;
}
// if the killcircle is almost as big as the view then increase the view // if the killcircle is almost as big as the view then increase the view
void updateViewSize(); void updateViewSize();
@ -117,6 +127,7 @@ class DLASystem {
// set and read grid entries associated with a given position // set and read grid entries associated with a given position
void setGrid(double pos[], int val); void setGrid(double pos[], int val);
int readGrid(double pos[]); int readGrid(double pos[]);
// return the distance of a given point from the origin // return the distance of a given point from the origin
@ -126,10 +137,12 @@ class DLASystem {
// set whether there is an active particle in the system or not // set whether there is an active particle in the system or not
void setParticleActive() { lastParticleIsActive = 1; } void setParticleActive() { lastParticleIsActive = 1; }
void setParticleInactive() { lastParticleIsActive = 0; } void setParticleInactive() { lastParticleIsActive = 0; }
// add a particle at pos // add a particle at pos
void addParticle(double pos[]); void addParticle(double pos[]);
// add a particle at a random point on the addCircle // add a particle at a random point on the addCircle
void addParticleOnAddCircle(); void addParticleOnAddCircle();
@ -150,5 +163,6 @@ class DLASystem {
// it would be better for an OOP philosophy to make these member functions for the Window class // it would be better for an OOP philosophy to make these member functions for the Window class
// but we are being a bit lazy here // but we are being a bit lazy here
void setWinBackgroundWhite() { glClearColor(1.0, 1.0, 1.0, 1.0); } void setWinBackgroundWhite() { glClearColor(1.0, 1.0, 1.0, 1.0); }
void setWinBackgroundBlack() { glClearColor(0.0, 0.0, 0.0, 0.0); } void setWinBackgroundBlack() { glClearColor(0.0, 0.0, 0.0, 0.0); }
}; };

View File

@ -9,12 +9,14 @@ class Particle {
Particle() { Particle() {
pos = new double[dim]; pos = new double[dim];
} }
// constructor, with a specified initial position // constructor, with a specified initial position
Particle(double set_pos[]) { Particle(double set_pos[]) {
pos = new double[dim]; pos = new double[dim];
for (int d = 0; d < dim; d++) for (int d = 0; d < dim; d++)
pos[d] = set_pos[d]; pos[d] = set_pos[d];
} }
// destructor // destructor
~Particle() { delete[] pos; } ~Particle() { delete[] pos; }
}; };

View File

@ -2,7 +2,8 @@
// constructor // constructor
Window::Window(int set_size[], string &set_title) { Window::Window(int set_size[], string &set_title) {
size[0]=set_size[0]; size[1]=set_size[1]; size[0] = set_size[0];
size[1] = set_size[1];
title = set_title; title = set_title;
locateOnScreen(); locateOnScreen();

View File

@ -13,8 +13,11 @@ using namespace std;
// functions which are needed for openGL go into a namespace so that we can identify them // functions which are needed for openGL go into a namespace so that we can identify them
namespace drawFuncs { namespace drawFuncs {
void handleKeypress(unsigned char key, int x, int y); void handleKeypress(unsigned char key, int x, int y);
void display(void); void display(void);
void update(int val); void update(int val);
void introMessage(); void introMessage();
} }

9
rnd.h
View File

@ -1,4 +1,5 @@
#pragma once #pragma once
#include <random> #include <random>
// ... don't worry how this all works // ... don't worry how this all works
@ -22,12 +23,18 @@ public:
intmax = new std::uniform_int_distribution<int>(0, genMax); intmax = new std::uniform_int_distribution<int>(0, genMax);
real01 = new std::uniform_real_distribution<double>(0.0, 1.0); real01 = new std::uniform_real_distribution<double>(0.0, 1.0);
} }
// destructor // destructor
~rnd() { delete intmax; delete real01; } ~rnd() {
delete intmax;
delete real01;
}
// set the random seed // set the random seed
void setSeed(int seed) { generator.seed(seed); } void setSeed(int seed) { generator.seed(seed); }
// member functions for generating random double in [0,1] and random integer in [0,max-1] // member functions for generating random double in [0,1] and random integer in [0,max-1]
double random01() { return (*real01)(generator); } double random01() { return (*real01)(generator); }
int randomInt(int max) { return (*intmax)(generator) % max; } int randomInt(int max) { return (*intmax)(generator) % max; }
}; };