-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsim_validator.h
More file actions
77 lines (62 loc) · 2.94 KB
/
Copy pathsim_validator.h
File metadata and controls
77 lines (62 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#pragma once
#include <unordered_map>
#include <vector>
#include "io.h" // Include the shared header for Vec2 and Particle
class SimulationValidator {
public:
// Constructor
SimulationValidator(int num_particles, int square_size, int radius, int max_step);
// Destructor
~SimulationValidator();
// Initialize the first set of particles
void initialize(const std::vector<Particle>& initial_particles);
// Check the current step's particles vs. the previous step
void validate_step(const std::vector<Particle>& current_particles);
// Print output for visualization
void enable_viz_output(const std::string& filename);
private:
// Private helper functions
bool is_nearly_wall_overlap(Vec2 loc, int square_size, int radius) const;
bool is_nearly_particle_overlap(Vec2 loc1, Vec2 loc2, int radius) const;
bool is_definitely_wall_collision(Vec2 loc, Vec2 vel, int square_size, int radius) const;
double distance(Vec2 loc1, Vec2 loc2) const;
bool is_definitely_particle_overlap(Vec2 loc1, Vec2 loc2, int radius) const;
bool is_definitely_particle_moving_closer(Vec2 loc1, Vec2 vel1, Vec2 loc2, Vec2 vel2) const;
bool is_definitely_particle_collision(Vec2 loc1, Vec2 vel1, Vec2 loc2, Vec2 vel2, int radius) const;
bool exceedThreshold(double newValue, double oldValue) const;
void logParticle(const Particle& p, const char* prefix = "") const;
void logParticleGroup(const std::vector<Particle>& group, const char* prefix = "") const;
// Private energy and momentum calculations
double getEnergy(const std::vector<Particle>& particles) const;
Vec2 getMomentum(const std::vector<Particle>& particles) const;
// Private helpers
size_t hash(int pos) const;
int to_grid_pos(Vec2 loc) const;
void validate_step_firstpass(const std::vector<Particle>& current_particles);
void validate_step_secondpass();
bool bfs_group(int grid_pos, Particle particle);
void checkEnergyConservation(std::vector<Particle>& groupInPrevStep, std::vector<Particle>& groupInCurrStep) const;
void checkMomentumConservation(std::vector<Particle>& groupInPrevStep,
std::vector<Particle>& groupInCurrStep) const;
void checkUnhandledCollisions(std::vector<Particle>& groupInPrevStep, std::vector<Particle>& groupInCurrStep) const;
// Private member variables
int num_particles;
int square_size;
int radius;
double tile_size;
int tiles_in_square;
size_t grid_bits;
int step = 0;
int max_step = -1;
std::vector<Particle> previous_particles;
std::vector<Particle> current_particles_ordered;
std::vector<bool> seen_ids;
std::vector<int> all_pos;
std::vector<std::vector<Particle>> grid;
std::vector<bool> checked;
std::vector<std::pair<int, int>> group;
std::vector<Particle> groupInPrevStep;
std::vector<Particle> groupInCurrStep;
// For output file stream
std::ofstream viz_output;
};