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
|
#include <vector>
#include <random>
#include <iostream>
#include "particle.h"
#include "hard_sphere_overlap_index.h"
#include "random_positions_hard_spheres.h"
using namespace std;
//this function places N hard spheres of radius R on random coordinates in a [-0.5,0.5]^3 box
vector <particle> random_positions_hard_spheres (int N, double R){
vector <particle> positions;
static seed_seq seed_sequence { 100, 78639, 193, 55555, 3, 2348089, 6474367, 264441578 };
static mt19937 gen (seed_sequence);
uniform_real_distribution<double> random_double(-0.5, 0.5);
double x,y,z;
double d=2*R;
for(size_t i=0; i<N; ++i){
x=random_double(gen);
y=random_double(gen);
z=random_double(gen);
positions.push_back({x,y,z});
//find position with no overlap
int j=0;
while(overlap_index(positions, i, d)){
positions[i]={random_double(gen), random_double(gen), random_double(gen)};
++j;
}
cout <<"overlap was called "+to_string(j)+" times"<<endl;
cout <<"particle "+to_string(i)+" was placed"<<endl;
}
return positions;
}
|