-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatom.h
96 lines (82 loc) · 3.1 KB
/
atom.h
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#ifndef ATOM_H
#define ATOM_H
#include <algorithm>
#include <cassert>
#include <cmath> // For M_PI constant and other match functions such as round.
#include <chrono> // For logging every 500 ms
#include <cstdlib> // For rand()
#include <fstream>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <string>
#include <thread>
#include <vector>
#include "constants.h"
#include "logger.h"
#include "particle.h"
#include "thread_pool.h"
namespace sew {
class Atom {
public:
Particle * pars[kMaxParticles]; // par[ticle]s
int num_particles = 0;
volatile bool frame_draw_event_occurred;
// Only used for logging.
// If we are doing lots of calcs because electron close to proton, then we will wait for
// draw event before finishing calcs. That way we get maximum movement per frame.
// In other words: simulation is too damn slow, and we want speed up so use all of the
// compute budget per frame.
// Number of times per screen logging that MoveParticles() completed before
// next frame draw event.
volatile int n_times_per_screen_log_MoveParticles_completed_before_next_frame_draw_event = 0;
volatile int n_times_per_screen_log_MoveParticles_not_compl_before_next_frame_draw_event = 0;
// Delta time in seconds.
// SFloat dt = kShortDtSlow;
SFloat dt = kLongDtFast;
double time_ = 0; // We add tiny quantities of dt to this. Float doesn't do the job.
// Needs to be double. Float is only good for 7 digits of accuracy.
int count = 0; // Invocation count of moving particles.
SFloat total_potential_energy = 0;
SFloat total_kinetic_energy = 0;
SFloat total_energy = 0; // Total energy of all particles = potential energy + kinetic energy
// Energy of all particles when we had an escape. Above this energy we start dissipating energy.
SFloat total_energy_cap = 1;
SFloat potential_energy_average;
SFloat pot_energy_cycle[kEFrequencySubDivisions];
int pot_energy_cycle_index = 0;
SFloat sum_p_energy = 0; // Only used in below method.
Logger* logger;
int iter = 0; // Number of iterations to get significant movement.
SFloat long_dt;
SFloat short_dt;
// Lets not move faster than it would take an electron to go from center to edge,
// faster than two seconds.
constexpr static const SFloat kMaxPosChangeDesiredPerFrame = kBohrRadius / 60; // 60 fps
explicit Atom(int numParticles);
void MoveParticles();
void DtLoggingToggle();
void EnergyLoggingToggle();
void FastLoggingToggle();
void FrameDrawStatsLogToggle();
void IterationsLoggingToggle();
void PositionLoggingToggle();
void VelocityLoggingToggle();
void PercentEnergyDissipatedToggle();
void FastModeToggle();
void SlowMode();
void TimeLoggingToggle();
void WallClockLogToggle();
void ChargeLoggingToggle();
void DvModeToggle();
void VelocityComponentsLogToggle();
void TrailLoggingToggle();
private:
void CalcAveragePotentialEnergy();
void CalcEnergyOfAtom();
void AllForcesOnParticle(Particle * part_ptr);
void CalcForcesAndApply(Particle *part_ptr);
ThreadPool* thread_pool;
};
} // namespace
#endif // ATOM_H