00001
00002
00003
00004
00005
00006
00007 #include "voro++.cc"
00008
00009
00010 const int memory=8;
00011
00012
00013
00014 const int max_regions=16777216;
00015
00016
00017
00018 void help_message() {
00019 cout << "Voro++ version 0.2, by Chris H. Rycroft (UC Berkeley/LBL)\n\n";
00020 cout << "Syntax: voro++ [opts] <length_scale> <x_min> <x_max> <y_min>\n";
00021 cout << " <y_max> <z_min> <z_max> <filename>\n\n";
00022 cout << "<length_scale> should be set to a typical particle diameter,\n";
00023 cout << "or typical distance between particles. It is used to configure\n";
00024 cout << "the code for maximum efficiency.\n\n";
00025 cout << "Available options:\n";
00026 cout << " -g : Turn on the gnuplot output to <filename.gnu>\n";
00027 cout << " -h/--help : Print this information\n";
00028 cout << " -n : Turn on the neighbor tracking procedure\n";
00029 cout << " -p : Make container periodic in all three directions\n";
00030 cout << " -px : Make container periodic in the x direction\n";
00031 cout << " -py : Make container periodic in the y direction\n";
00032 cout << " -pz : Make container periodic in the z direction\n";
00033 cout << " -r : Assume the input file has an extra coordinate for radii\n";
00034 cout << " -wc [7] : Add a cylinder wall object, centered on (x1,x2,x3),\n";
00035 cout << " pointing in (x4,x5,x6), radius x7\n";
00036 cout << " -wo [7] : Add a conical wall object, apex at (x1,x2,x3), axis\n";
00037 cout << " along (x4,x5,x6), angle x7 in radians\n";
00038 cout << " -ws [4] : Add a sphere wall object, centered on (x1,x2,x3),\n";
00039 cout << " with radius x4\n";
00040 cout << " -wp [4] : Add a plane wall object, with normal (x1,x2,x3),\n";
00041 cout << " and displacement x4" << endl;
00042 }
00043
00044
00045
00046 void error_message() {
00047 cerr << "Unrecognized command line options; type \"voro++ -h\" for more information." << endl;
00048 }
00049
00050
00051
00052 int wall_mem=init_wall_size,wall_count=0;
00053
00054
00055 wall **wp;
00056
00057
00058 void add_wall_memory() {
00059 wall **nwp;
00060 wall_mem*=2;
00061 if (wall_mem>max_wall_size) cerr << "Too many walls allocated. Try recompiling by boosting the value of max_wall_size in config.hh" << endl;
00062 nwp=new wall*[wall_mem];
00063 for(int i=0;i<wall_count;i++) nwp[i]=wp[i];
00064 delete [] wp;
00065 wp=nwp;
00066 }
00067
00068
00069 void wall_deallocate() {
00070 for(int i=0;i<wall_count;i++) delete wp[i];
00071 delete [] wp;
00072 }
00073
00074 int main(int argc,char **argv) {
00075 int i=1,j=-7;
00076 bool gnuplot_output=false,neighbor_track=false,polydisperse=false;
00077 bool xperiodic=false,yperiodic=false,zperiodic=false;
00078 char buffer[256];
00079 wp=new wall*[init_wall_size];
00080
00081
00082
00083 if (argc==2) {
00084 if (strcmp(argv[1],"-h")==0||strcmp(argv[1],"--help")==0) {
00085 help_message();return 0;
00086 } else {
00087 error_message();return 1;
00088 }
00089 }
00090
00091
00092
00093 if (argc<9) {
00094 error_message();return 1;
00095 }
00096
00097
00098
00099 while(i+8<argc) {
00100 if (strcmp(argv[i],"-g")==0) {
00101 gnuplot_output=true;
00102 } else if (strcmp(argv[i],"-h")==0||strcmp(argv[i],"--help")==0) {
00103 help_message();return 0;
00104 } else if (strcmp(argv[i],"-n")==0) {
00105 neighbor_track=true;
00106 } else if (strcmp(argv[i],"-p")==0) {
00107 xperiodic=yperiodic=zperiodic=true;
00108 } else if (strcmp(argv[i],"-px")==0) {
00109 xperiodic=true;
00110 } else if (strcmp(argv[i],"-py")==0) {
00111 yperiodic=true;
00112 } else if (strcmp(argv[i],"-pz")==0) {
00113 zperiodic=true;
00114 } else if (strcmp(argv[i],"-r")==0) {
00115 polydisperse=true;
00116 } else if (strcmp(argv[i],"-ws")==0) {
00117 if (wall_count==wall_mem) add_wall_memory();
00118 i++;
00119 fpoint w0=atof(argv[i++]),w1=atof(argv[i++]);
00120 fpoint w2=atof(argv[i++]),w3=atof(argv[i]);
00121 wp[wall_count++]=new wall_sphere(w0,w1,w2,w3,j);
00122 cout << "Sphere" << w0 << " " << w1 << " " << w2 << " " << w3 << endl;
00123 j--;
00124 } else if (strcmp(argv[i],"-wp")==0) {
00125 if (wall_count==wall_mem) add_wall_memory();
00126 i++;
00127 fpoint w0=atof(argv[i++]),w1=atof(argv[i++]);
00128 fpoint w2=atof(argv[i++]),w3=atof(argv[i]);
00129 wp[wall_count++]=new wall_plane(w0,w1,w2,w3,j);
00130 j--;
00131 } else if (strcmp(argv[i],"-wc")==0) {
00132 if (wall_count==wall_mem) add_wall_memory();
00133 i++;
00134 fpoint w0=atof(argv[i++]),w1=atof(argv[i++]);
00135 fpoint w2=atof(argv[i++]),w3=atof(argv[i++]);
00136 fpoint w4=atof(argv[i++]),w5=atof(argv[i++]);
00137 fpoint w6=atof(argv[i]);
00138 wp[wall_count++]=new wall_cylinder(w0,w1,w2,w3,w4,w5,w6,j);
00139 j--;
00140 } else if (strcmp(argv[i],"-wo")==0) {
00141 if (wall_count==wall_mem) add_wall_memory();
00142 i++;
00143 fpoint w0=atof(argv[i++]),w1=atof(argv[i++]);
00144 fpoint w2=atof(argv[i++]),w3=atof(argv[i++]);
00145 fpoint w4=atof(argv[i++]),w5=atof(argv[i++]);
00146 fpoint w6=atof(argv[i]);
00147 wp[wall_count++]=new wall_cone(w0,w1,w2,w3,w4,w5,w6,j);
00148 j--;
00149 } else {
00150 error_message();return 1;
00151 }
00152 i++;
00153 }
00154
00155
00156
00157 fpoint ls=atof(argv[i]);
00158 fpoint xmin=atof(argv[i+1]),xmax=atof(argv[i+2]);
00159 fpoint ymin=atof(argv[i+3]),ymax=atof(argv[i+4]);
00160 fpoint zmin=atof(argv[i+5]),zmax=atof(argv[i+6]);
00161
00162
00163 if (ls<tolerance) {
00164 if (ls<0) {
00165 cerr << "The length scale must be positive" << endl;
00166 } else {
00167 cerr << "The length scale is smaller than the safe limit of " << tolerance << ".\n";
00168 cerr << "Either increase the particle length scale, or recompile with a\n";
00169 cerr << "different limit." << endl;
00170 }
00171 wall_deallocate();
00172 return 0;
00173 }
00174 ls=1.8/ls;
00175
00176
00177
00178
00179 int nx=int((xmax-xmin)*ls)+1;
00180 int ny=int((ymax-ymin)*ls)+1;
00181 int nz=int((zmax-zmin)*ls)+1;
00182 int nxyz=nx*ny*nz;
00183 if (nx*ny*nz>max_regions) {
00184 cerr << "Number of computational blocks (" << nxyz << ") exceeds the maximum\n";
00185 cerr << "allowed of " << max_regions << ". Either increase the particle\n";
00186 cerr << "length scale, or recompile with an increased maximum." << endl;
00187 wall_deallocate();
00188 return 0;
00189 }
00190
00191
00192 sprintf(buffer,"%s.vol",argv[i+7]);
00193
00194
00195 if (polydisperse) {
00196 container_poly con(xmin,xmax,ymin,ymax,zmin,zmax,nx,ny,nz,
00197 xperiodic,yperiodic,zperiodic,memory);
00198 for(j=0;j<wall_count;j++) con.add_wall(*wp[j]);
00199 con.import(argv[i+7]);
00200
00201 if (neighbor_track) con.print_all_neighbor(buffer);
00202 else con.print_all(buffer);
00203
00204 if (gnuplot_output) {
00205 sprintf(buffer,"%s.gnu",argv[i+7]);
00206 con.draw_cells_gnuplot(buffer);
00207 }
00208 } else {
00209 container con(xmin,xmax,ymin,ymax,zmin,zmax,nx,ny,nz,
00210 xperiodic,yperiodic,zperiodic,memory);
00211 for(j=0;j<wall_count;j++) con.add_wall(*wp[j]);
00212 con.import(argv[i+7]);
00213
00214 if (neighbor_track) con.print_all_neighbor(buffer);
00215 else con.print_all(buffer);
00216
00217 if (gnuplot_output) {
00218 sprintf(buffer,"%s.gnu",argv[i+7]);
00219 con.draw_cells_gnuplot(buffer);
00220 }
00221 }
00222 return 0;
00223 }