-
Notifications
You must be signed in to change notification settings - Fork 0
/
Simulation.hpp
154 lines (128 loc) · 3.54 KB
/
Simulation.hpp
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: Simulation.hpp
* Author: dawid
*
* Created on February 3, 2016, 11:06 AM
*/
#ifndef SIMULATION_HPP
#define SIMULATION_HPP
#include "Eigen/Dense"
#include "SimulationParameters.h"
#include "Utilities.h"
#include <random>
#include <ctime>
#include <array>
#include <fstream>
#include <iostream>
typedef Eigen::Vector3d vec;
enum class PotentialTypes {
Harmonic,
Tapered,
Realistic
};
struct statistics {
size_t points = 0;
size_t allocated_size = 0;
size_t total_decays = 0;
Eigen::MatrixXd table;
Eigen::MatrixXd table2;
size_t runs = 0;
// averages
Eigen::RowVector3d avg_x, avg_x2, avg_v, avg_v2;
statistics(){
points = 0;
allocated_size = 0;
avg_v2.setZero();
avg_x = avg_x2 = avg_v = avg_v2;
}
void do_stats(vec &omegas, std::ostream& out);
};
class Simulation {
private:
std::random_device rd;
std::mt19937 rng{rd()};
std::normal_distribution<> normal{0,1};
std::uniform_real_distribution<> unif{0,1};
std::string fileName;
std::fstream outFile;
public:
Simulation();
~Simulation();
Physical phys;
Parameters sim;
// Init state with temperature T on all axes
double init_state(double T);
// Init state in elongation kick in all direction
double init_kick(double kick);
// Step forward one default time step
void step();
// Perform one laser interaction step
void laserXYZ();
// Calculate trap frequency on one axis
double trap_freq(int axis, double kick = 1e-5);
// Calculate ponderomotive frequencies by measuring them
void calibrateTrapFrequencies(bool verbose = true);
// Perform statistics
void do_statistics();
void initializeMatrices();
void collect_statistics(const Simulation & traj);
void ensemble_statistics();
// define the type of potential, switching below the accelerations below:
PotentialTypes potential;
// Calculate forces and energies
vec acceleration(double);
vec acceleration_taper(double time);
vec acceleration_microtaper(double time);
vec acceleration_harmonic(double time);
// Calculate energy
double energy();
// Random normal variable
double randn();
// Random double in [0,1]
double rand();
// Read state
void read_state(std::ostream & out = std::cout);
// Print state
void print_history();
// Run simulation from t = 0 to phys.end_time
void run();
void run(double time);
// Statistics of the simulation
struct statistics stats;
// current time
double t;
// current position
vec x;
// current speed
vec v;
// current acceleration
vec a;
vec energies;
vec omega;
// current timestep
size_t N;
// data written for later averaging
size_t printed;
// decays
size_t decays;
// acceleration at previous step
vec a_t;
// acceleration two steps behind
vec a_tm;
// scattering probabilities per laser beam
std::vector<double> probs;
// set up all laser parameters before the simulation
void setupLaserBeam();
// Noise giving function
std::function<double(double)> noiseFun = [](double ) -> double{return 1.0;};
};
// declare global parameters
extern Physical physical;
// global simulation parameters
extern Parameters simpar;
#endif /* SIMULATION_HPP */