Bugfix in search_for_outside_edge routine.
[voro++.git] / branches / exact / examples / extra / irregular.cc
blob3f9dd9df1bbab8b992eb9c49bfdff30a6655ac4c
1 // Irregular packing 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 using namespace voro;
10 // Set up constants for the container geometry
11 const double x_min=-6,x_max=6;
12 const double y_min=-6,y_max=6;
13 const double z_min=-3,z_max=9;
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
20 // into.
21 const int n_x=5,n_y=5,n_z=5;
23 // Create a wall class that, whenever called, will replace the Voronoi cell
24 // with a prescribed shape, in this case a dodecahedron
25 class wall_initial_shape : public wall {
26 public:
27 wall_initial_shape() {
29 // Create a dodecahedron
30 v.init(-2,2,-2,2,-2,2);
31 v.plane(0,Phi,1);v.plane(0,-Phi,1);v.plane(0,Phi,-1);
32 v.plane(0,-Phi,-1);v.plane(1,0,Phi);v.plane(-1,0,Phi);
33 v.plane(1,0,-Phi);v.plane(-1,0,-Phi);v.plane(Phi,1,0);
34 v.plane(-Phi,1,0);v.plane(Phi,-1,0);v.plane(-Phi,-1,0);
36 bool point_inside(double x,double y,double z) {return true;}
37 bool cut_cell(voronoicell &c,double x,double y,double z) {
39 // Set the cell to be equal to the dodecahedron
40 c=v;
41 return true;
43 bool cut_cell(voronoicell_neighbor &c,double x,double y,double z) {
45 // Set the cell to be equal to the dodecahedron
46 c=v;
47 return true;
49 private:
50 voronoicell v;
53 int main() {
55 // Create a container with the geometry given above. This is bigger
56 // than the particle packing itself.
57 container con(x_min,x_max,y_min,y_max,z_min,z_max,n_x,n_y,n_z,
58 false,false,false,8);
60 // Create the "initial shape" wall class and add it to the container
61 wall_initial_shape(wis);
62 con.add_wall(wis);
64 // Import the irregular particle packing
65 con.import("pack_irregular");
67 // Save the particles and Voronoi cells in POV-Ray format
68 con.draw_particles_pov("irregular_p.pov");
69 con.draw_cells_pov("irregular_v.pov");