Minkowski test code.
[voro++.git] / trunk / examples / no_release / random_points_200.cc
blobb6ede7aac3a2e8228fb6334fa5b1e358602f0143
1 // Voronoi calculation example code
2 //
3 // Author : Chris H. Rycroft (LBL / UC Berkeley)
4 // Email : chr@alum.mit.edu
5 // Date : August 30th 2011
7 #include "voro++.hh"
8 #include <iostream>
9 #include <fstream>
10 using namespace voro;
12 // Set up constants for the container geometry
13 const double x_min=-1,x_max=1;
14 const double y_min=-1,y_max=1;
15 const double z_min=-1,z_max=1;
16 const double cvol=(x_max-x_min)*(y_max-y_min)*(x_max-x_min);
18 // Set up the number of blocks that the container is divided into
19 const int n_x=60,n_y=60,n_z=60;
21 // Set the number of particles that are going to be randomly introduced
22 //const int particles=20;
23 const int particles=200;
25 // This function returns a random double between 0 and 1
26 double rnd() {return double(rand())/RAND_MAX;}
28 int main() {
29 int i;
30 double x,y,z;
32 // Create a container with the geometry given above, and make it
33 // non-periodic in each of the three coordinates. Allocate space for
34 // eight particles within each computational block
35 container con(x_min,x_max,y_min,y_max,z_min,z_max,n_x,n_y,n_z,
36 false,false,false,8);
38 // Randomly add particles into the container
39 for(i=0;i<particles;i++) {
40 x=x_min+rnd()*(x_max-x_min);
41 y=y_min+rnd()*(y_max-y_min);
42 z=z_min+rnd()*(z_max-z_min);
43 con.put(i,x,y,z);
46 // Sum up the volumes, and check that this matches the container volume
47 double vvol=con.sum_cell_volumes();
48 printf("Container volume : %g\n"
49 "Voronoi volume : %g\n"
50 "Difference : %g\n",cvol,vvol,vvol-cvol);
52 // Output the particle positions in gnuplot format
53 con.draw_particles("random_points_p.gnu");
55 // Output the Voronoi cells in gnuplot format
56 con.draw_cells_gnuplot("random_points_v.gnu");
57 const char *vars = "%n";
58 con.print_custom(vars,"test.txt");