int main(int argc, char* argv[]) { assert(argc>1 && argc < 7); int nx = argc>2 ? std::atoi(argv[2]) : 2; int ny = argc>3 ? std::atoi(argv[3]) : 2; int nz = argc>4 ? std::atoi(argv[4]) : 2; std::ifstream in(argv[1]); Nef_polyhedron Nin; in >> Nin; Nin.transform(Aff_transformation_3(CGAL::SCALING,2,1)); std::ostringstream out1; ggen g(out1, Nin); g.print(nx,ny,nz); std::istringstream in1(out1.str()); Nef_polyhedron N1; in1 >> N1; RT s = g.size_x(); N1.transform(Aff_transformation_3(CGAL::TRANSLATION,Vector_3(s,s,s,2))); CGAL_assertion(N1.is_valid()); std::ostringstream out2; CGAL::Random r; if(argc>5) { tgen t2(out2,s,std::atoi(argv[5])); t2.create_tetrahedra(nx+1,ny+1,nz+1); } else { tgen t2(out2,s); t2.create_tetrahedra(nx+1,ny+1,nz+1); } std::istringstream in2(out2.str()); Nef_polyhedron N2; in2 >> N2; CGAL_assertion(N2.is_valid()); char* dir="nef3/"; char* tetrahedra="tetrahedra"; char* grid="grid"; char* suffix=".nef3"; char* us="_"; char* full_suffix = new char[strlen(argv[2])+strlen(argv[3])+strlen(argv[4])+strlen(argv[5])+strlen(suffix)+5]; strcpy(full_suffix, us); strcat(full_suffix, argv[2]); strcat(full_suffix, us); strcat(full_suffix, argv[3]); strcat(full_suffix, us); strcat(full_suffix, argv[4]); strcat(full_suffix, us); strcat(full_suffix, argv[5]); strcat(full_suffix, suffix); char* full_tetrahedra = new char[strlen(dir)+strlen(tetrahedra)+strlen(full_suffix)+1]; strcpy(full_tetrahedra, dir); strcat(full_tetrahedra, tetrahedra); strcat(full_tetrahedra, full_suffix); std::ofstream out_tetrahedra(full_tetrahedra); out_tetrahedra << N2; char* full_grid = new char[strlen(dir)+strlen(grid)+strlen(full_suffix)+1]; strcpy(full_grid, dir); strcat(full_grid, grid); strcat(full_grid, full_suffix); std::ofstream out_grid(full_grid); out_grid << N1; }
int main(int argc, char* argv[]) { if (argc < 2) { std::cout << "Usage: simpleReact num_particles" << std::endl; exit(-1); } const unsigned int num_particles = atoi(argv[1]); std::ofstream tf; tf.open(("output/time_simpleReact_"+std::string(argv[1])+".dat").c_str()); boost::progress_timer t(tf); const double end_time = 5.0; const double dt = 0.001; /* * Create "red" species with D=1 */ Species red(0.1); //red.fill_uniform(0.0,1.0,1); /* * create diffusion operator and apply to red species */ Diffusion bd; bd.add_species(red); /* * Create simulation boundary planes */ AxisAlignedPlane<0> xlow(0,1); AxisAlignedPlane<0> xhigh(1,-1); AxisAlignedPlane<1> ylow(0,1),yhigh(1,-1); AxisAlignedPlane<2> zlow(0,1),zhigh(1,-1); /* * Create input flux boundary */ FluxBoundary fb(Vect3d(1,0,0),Vect3d(0,1,0),Vect3d(0,0,1),num_particles); fb.add_species(red); /* * Create jump (periodic) boundaries */ //JumpBoundary<AxisAlignedPlane<0> > jb1(xlow,Vect3d(1,0,0)); jb1.add_species(red); JumpBoundary<AxisAlignedPlane<1> > jb2(ylow,Vect3d(0,1,0)); jb2.add_species(red); JumpBoundary<AxisAlignedPlane<2> > jb3(zlow,Vect3d(0,0,1)); jb3.add_species(red); JumpBoundary<AxisAlignedPlane<1> > jb4(yhigh,Vect3d(0,-1,0)); jb4.add_species(red); JumpBoundary<AxisAlignedPlane<2> > jb5(zhigh,Vect3d(0,0,-1)); jb5.add_species(red); /* * Create reflective boundary */ ReflectiveBoundary<AxisAlignedPlane<0> > rb(xhigh); rb.add_species(red); /* * Create unimolecular reaction operator (red -> 0) */ UniMolecularReaction dr(1,red >> 0); const double h_in = 0.1; StructuredGrid out_grid(Vect3d(0,0,0), Vect3d(1,1,1), Vect3d(h_in,1.0,1.0)); OutputConcentrations out_concen_1d("output/simpleReact_",end_time/100.0, out_grid);out_concen_1d.add_species(red); OutputCompareWithFunction<rmsError<MyFunction> > out_compare("output/simpleReact_error",end_time/100.0,0,1,out_grid, rmsError<MyFunction>(MyFunction(num_particles,red.D))); out_compare.add_species(red); Plot2d plot(0,out_concen_1d.get_data("x"),out_concen_1d.get_data("Concentration"),"x","Concentration","My first plot"); Visualisation vis(0);vis.add_species(red); vis.add_geometry(xlow); vis.add_geometry(xhigh); vis.add_geometry(ylow); vis.add_geometry(yhigh); vis.add_geometry(zlow); vis.add_geometry(zhigh); /* * Run simulation until end_time with timestep dt */ run(red, end_time, dt, bd, fb, jb2, jb3, jb4, jb5, rb, dr, out_concen_1d, out_compare, vis,plot); std::vector<int> bins; make_histogram(bins,red,100, 0,1); std::ofstream f; f.open(("output/simpleReact_"+std::string(argv[1])+".dat").c_str()); f << end_time << ' '; BOOST_FOREACH(int x,bins) { f << x <<' '; } f << std::endl; f.close(); return EXIT_SUCCESS; }