Space Comps
 All Classes Files Functions Variables
algorithm.h
1 #ifndef ALGORITHM_H
2 #define ALGORITHM_H
3 #include "physics2d.h"
4 #include "multiqueue.h"
5 #include <mutex>
6 
16 class Algorithm
17 {
18 public:
30  Algorithm(double xIn, double yIn);
31 
44  Algorithm(double xIn, double yIn, double zIn);
45 
59  Algorithm(double xIn, double yIn, double zIn, double centerMass);
60 
61  virtual ~Algorithm();
62 
67  std::vector<Particle*> getParticles();
68 
81  std::queue<Collision*>* getCollisions();
82 
89 
94  std::mutex* getCollisionMutex();
95 
102 
107  int getNumParts();
108 
120  int getTimestep();
121 
126  double getSystemKE();
127 
132  double getSystemPE();
133 
138  Physics* getPhysics();
139 
144  void setNumParts(int numParticles);
145 
156  void createParticles2D(int numParticles);
157 
167  void createParticles3D(int numParticles);
168 
181  void createParticlesOrbit(int numParticles);
182 
183  // IS THIS SOMETHING WE WANT?
184  void respawnParticle(Particle* particle);
185 
197  void enqueueCollisions(std::vector<Collision*> collisions);
198 
209  void runOneTimestep();
210 
211  // WHAT do these actually do?
212  void run();
213  void stop();
214 
224  void stepTime();
225 
226 protected:
227  std::vector<Particle*> particles;
228 
229  std::queue<Collision*> collisionQueue;
230  std::mutex collisionMutex;
231 
232  MultiQueue* positionQueue;
233 
234  Physics* physics;
235  bool running;
236  int numParts;
237  int timestep;
238  double xWinSize;
239  double yWinSize;
240  double zWinSize;
241  double systemKE;
242  double systemPE;
243 
244  Particle* generateParticleIn2D(int i);
245  Particle* generateParticleIn3D(int i);
246  Particle* generateParticleInOrbit(int i);
247  void regenerateParticleInOrbit(Particle* p);
248  bool checkForOverlap(Particle* p);
249 
250  virtual void calculateNextTimestep() = 0;
251 
252  void enqueuePositions();
253 
254  void updateSystemKE();
255  void updateSystemPE();
256  void rescaleVelocities();
257 
258  void checkTimestep();
259 };
260 
261 #endif // ALGORITHM_H
The Algorithm class is a parent to all the specific Algorithms we test.
Definition: algorithm.h:16
void runOneTimestep()
Calculates the next timestep.
Definition: algorithm.cpp:343
void createParticlesOrbit(int numParticles)
Sets the number of Particles, then generates that many to track.
Definition: algorithm.cpp:233
Physics * getPhysics()
Returns the Physics object working for this Algorithm.
Definition: algorithm.cpp:298
void setNumParts(int numParticles)
Sets the number of Particles the Algorithm is tracking.
Definition: algorithm.cpp:302
double getSystemPE()
Returns system potential energy which is updated each timestep.
Definition: algorithm.cpp:294
int getTimestep()
Returns the timestep the Algorithm is currently calculating.
Definition: algorithm.cpp:276
void createParticles2D(int numParticles)
Sets the number of Particles, then generates that many to track.
Definition: algorithm.cpp:201
Definition: multiqueue.h:8
void enqueueCollisions(std::vector< Collision * > collisions)
Pushes Collisions from the most recent timestep onto the queue of upcoming Collision$s.
Definition: algorithm.cpp:332
The Physics class.
Definition: physics.h:15
int getNumParts()
Returns the number of Particles the Algorithm is tracking.
Definition: algorithm.cpp:271
void stepTime()
Calculates the next timestep and sets running to true.
Definition: algorithm.cpp:389
MultiQueue * getPositionQueue()
Returns the MultiQueue that contains upcoming Positions for each Particle.
Definition: algorithm.cpp:281
Definition: particle.h:12
std::mutex * getCollisionMutex()
Returns the Mutex locking the Collision queue.
Definition: algorithm.cpp:286
std::vector< Particle * > getParticles()
Returns the vector of Particles that the algorithm is tracking.
Definition: algorithm.cpp:263
void createParticles3D(int numParticles)
Sets the number of Particles, then generates that many to track.
Definition: algorithm.cpp:217
std::queue< Collision * > * getCollisions()
Returns the queue of Collisions that we haven't entered the warning window yet.
Definition: algorithm.cpp:267
double getSystemKE()
Returns the system kinetic energy which is updated each timestep.
Definition: algorithm.cpp:290
Particle * getCenterOfGravity()
Returns the massive Particle in the center responsible for Gravitation.
Definition: algorithm.cpp:61
Algorithm(double xIn, double yIn)
Constructs a 2 dimensional Algorithm.
Definition: algorithm.cpp:7