1 // Example code demonstrating the loop classes
3 // Author : Chris H. Rycroft (LBL / UC Berkeley)
4 // Email : chr@alum.mit.edu
5 // Date : August 30th 2011
10 // Constants determining the configuration of the tori
11 const double dis
=1.25,mjrad
=2.5,mirad
=0.95,trad
=mjrad
+mirad
;
13 // Set the number of particles that are going to be randomly introduced
14 const int particles
=100000;
16 // This function returns a random double between 0 and 1
17 double rnd() {return double(rand())/RAND_MAX
;}
24 // Create a container as a non-periodic 10 by 10 by 10 box
25 container
con(-5,5,-5,5,-5,5,26,26,26,false,false,false,8);
28 // Randomly add particles into the container
29 for(i
=0;i
<particles
;i
++) {
34 // If the particle lies within the first torus, store it in the
35 // ordering class when adding to the container
36 r
=sqrt((x
-dis
)*(x
-dis
)+y
*y
);
37 if((r
-mjrad
)*(r
-mjrad
)+z
*z
<mirad
) con
.put(po
,i
,x
,y
,z
);
38 else con
.put(i
,x
,y
,z
);
41 // Compute Voronoi cells for the first torus. Here, the points
42 // previously stored in the ordering class are looped over.
43 FILE *f1
=safe_fopen("loops1_m.pov","w");
44 FILE *f2
=safe_fopen("loops1_v.pov","w");
45 c_loop_order
clo(con
,po
);
46 if(clo
.start()) do if(con
.compute_cell(c
,clo
)) {
48 // Get the position of the current particle under consideration
51 // Save a POV-Ray mesh to one file and a cylinder/sphere
52 // representation to the other file
53 c
.draw_pov_mesh(x
,y
,z
,f1
);
59 // Compute Voronoi cells for the second torus. Here, the subset loop is
60 // used to search over the blocks overlapping the torus, and then each
61 // particle is individually tested.
62 f1
=safe_fopen("loops2_m.pov","w");
63 f2
=safe_fopen("loops2_v.pov","w");
64 c_loop_subset
cls(con
);
65 cls
.setup_box(-dis
-trad
,-dis
+trad
,-mirad
,mirad
,-trad
,trad
,false);
68 // Get the position of the current particle under consideration
71 // Test whether this point is within the torus, and if so,
72 // compute and save the Voronoi cell
73 r
=sqrt((x
+dis
)*(x
+dis
)+z
*z
);
74 if((r
-mjrad
)*(r
-mjrad
)+y
*y
<mirad
&&con
.compute_cell(c
,cls
)) {
75 c
.draw_pov_mesh(x
,y
,z
,f1
);