1 // Irregular packing example code
3 // Author : Chris H. Rycroft (LBL / UC Berkeley)
4 // Email : chr@alum.mit.edu
5 // Date : August 30th 2011
10 // Set up constants for the container geometry
11 const double x_min
=-15,x_max
=15;
12 const double y_min
=-7,y_max
=7;
13 const double z_min
=-15,z_max
=15;
15 // Golden ratio constants
16 const double Phi
=0.5*(1+sqrt(5.0));
17 const double phi
=0.5*(1-sqrt(5.0));
19 // Set up the number of blocks that the container is divided
21 const int n_x
=8,n_y
=8,n_z
=8;
23 // ID for dodecahedron faces
26 // Create a wall class that, whenever called, will replace the Voronoi cell
27 // with a prescribed shape, in this case a dodecahedron
28 class wall_initial_shape
: public wall
{
30 wall_initial_shape() {
32 // Create a dodecahedron with neighbor information all
34 v
.init(-2,2,-2,2,-2,2);
35 v
.nplane(0,Phi
,1,wid
);v
.nplane(0,-Phi
,1,wid
);v
.nplane(0,Phi
,-1,wid
);
36 v
.nplane(0,-Phi
,-1,wid
);v
.nplane(1,0,Phi
,wid
);v
.nplane(-1,0,Phi
,wid
);
37 v
.nplane(1,0,-Phi
,wid
);v
.nplane(-1,0,-Phi
,wid
);v
.nplane(Phi
,1,0,wid
);
38 v
.nplane(-Phi
,1,0,wid
);v
.nplane(Phi
,-1,0,wid
);v
.nplane(-Phi
,-1,0,wid
);
40 bool point_inside(double x
,double y
,double z
) {return true;}
41 bool cut_cell(voronoicell
&c
,double x
,double y
,double z
) {
43 // Just ignore this case
46 bool cut_cell(voronoicell_neighbor
&c
,double x
,double y
,double z
) {
48 // Set the cell to be equal to the dodecahedron
53 voronoicell_neighbor v
;
56 // Determines whether any of the sides in the neighbor information are from the
57 // initial dodecahedron
58 bool has_dodec_sides(vector
<int> &vi
) {
59 for(unsigned int i
=0;i
<vi
.size();i
++) if(vi
[i
]==wid
) return true;
65 // Create a container with the geometry given above. This is bigger
66 // than the particle packing itself.
67 container
con(x_min
,x_max
,y_min
,y_max
,z_min
,z_max
,n_x
,n_y
,n_z
,
70 // Create the "initial shape" wall class and add it to the container
71 wall_initial_shape(wis
);
74 // Import the irregular particle packing
75 con
.import("pack_semicircle");
77 // Open files to save the "inside" and "outside" particles
78 FILE *finside
=safe_fopen("finite_sys_in.pov","w"),
79 *foutside
=safe_fopen("finite_sys_out.pov","w");
81 // Loop over all particles
84 voronoicell_neighbor c
;
88 // Get particle position
91 // Remove half of the particles to see a cross-section
94 if(con
.compute_cell(c
,cl
)) {
96 // Get the neighboring IDs of all the faces
99 // Depending on whether any of the faces are
100 // from the original dodecahedron, print to
101 // the "inside" or "outside" file
102 fprintf(has_dodec_sides(vi
)?foutside
:finside
,
103 "sphere{<%g,%g,%g>,s}\n",x
,y
,z
);
107 // Close the output files