-
Notifications
You must be signed in to change notification settings - Fork 0
/
SingleSpiral.cpp
46 lines (29 loc) · 1.37 KB
/
SingleSpiral.cpp
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
#include "../../include/distributors/SingleSpiral.h"
SingleSpiral::SingleSpiral(unsigned long seed, int numParticles) : Distributor(seed), numParticles(numParticles) {
confP = ConfigParser("config/SingleSpiral.info");
std::string description = confP.getVal<std::string>("description");
std::cout << "Description: " << description << std::endl;
R = confP.getVal<double>("R");
M = confP.getVal<double>("M");
rndRCube = std::uniform_real_distribution<double>(0., std::nextafter(1., std::numeric_limits<double>::max()));
rndPhi = std::uniform_real_distribution<double>(0., 2.*M_PI);
rndCosTheta = std::uniform_real_distribution<double>(-1., std::nextafter(1., std::numeric_limits<double>::max()));
}
Particle SingleSpiral::next(int i) {
Particle particle;
double r, phi, theta, vmag;
// generate uniformly distributed particles in a sphere
r = R * pow(rndRCube(gen), 1./3.);
phi = rndPhi(gen);
theta = acos(rndCosTheta(gen));
vmag = sqrt(G*M*r*r/(2.*R*R*R));
particle.pos = vec3{ r * cos(phi) * sin(theta),
r * sin(phi) * sin(theta),
r * cos(theta) };
particle.vel = vec3{ vmag * sin(phi),
-vmag * cos(phi),
0.};
particle.mass = M/numParticles;
//std::cout << "Particle.pos: " << particle.pos;
return particle;
}