Exemple #1
0
void StructuredGrid::get_slice(const Geometry& geometry, std::vector<int>& indices) const {
	indices.clear();
	const int nedges = 14;
	const double edges[nedges][2][3] = {{{0,0,0},{0,0,1}},
			              {{0,0,0},{0,1,0}},
			              {{0,0,0},{1,0,0}},
			              {{0,0,1},{0,1,1}},
			              {{0,0,1},{1,0,0}},
			              {{0,1,0},{1,1,0}},
			              {{0,1,0},{0,1,1}},
			              {{1,0,0},{1,1,0}},
			              {{1,0,0},{1,0,1}},
			              {{0,1,1},{1,1,1}},
			              {{1,1,0},{1,1,1}},
			              {{1,0,1},{1,1,1}},
						  {{0,0,0},{0.5,0.5,0.5}},
						  {{0.5,0.5,0.5},{1,1,1}}};

	for (int i = 0; i < num_cells; ++i) {
		const Vect3d low_point = index_to_vect(i).cast<double>().cwiseProduct(cell_size)+low;
		for (int j = 0; j < nedges; ++j) {
			const Vect3d p1 = low_point + Vect3d(edges[j][0][0],edges[j][0][1],edges[j][0][2]).cwiseProduct(cell_size);
			const Vect3d p2 = low_point + Vect3d(edges[j][1][0],edges[j][1][1],edges[j][1][2]).cwiseProduct(cell_size);
			if (geometry.lineXsurface(p1,p2)) {
				indices.push_back(i);
				break;
			}

		}
	}
}
Exemple #2
0
void StructuredGrid::reset_domain(const Vect3d& _low, const Vect3d& _high, const Vect3d& max_grid_size) {
	high = _high;
	low = _low;
	domain_size = _high-_low;
	Vect3d new_max_grid_size = max_grid_size;
	for (int i = 0; i < 3; ++i) {
		if ((new_max_grid_size[i]<=0)||std::isnan(new_max_grid_size[i])) {
			new_max_grid_size[i] = 1.0;
		}
	}
	num_cells_along_axes = ((high-low).cwiseQuotient(new_max_grid_size) + Vect3d(0.5,0.5,0.5)).cast<int>();
	for (int i = 0; i < 3; ++i) {
		if (num_cells_along_axes[i]==0) {
			num_cells_along_axes[i] = 1.0;
			high[i] = low[i] + new_max_grid_size[i];
			domain_size[i] = high[i]-low[i];
		}
	}
	cell_size = (high-low).cwiseQuotient(num_cells_along_axes.cast<double>());
	tolerance = cell_size.minCoeff()/100000.0;
	cell_volume = cell_size.prod();
	inv_cell_size = Vect3d(1,1,1).cwiseQuotient(cell_size);
	num_cells_along_yz = num_cells_along_axes[2]*num_cells_along_axes[1];
	num_cells = num_cells_along_axes.prod();
	neighbours.resize(num_cells);
	neighbour_distances.resize(num_cells);
	calculate_neighbours();
}
Exemple #3
0
void Internode::Render()
{	
	glPushMatrix();

	glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, _specular);
	glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, _specular);
	glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, _specular);

	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

	GLUquadricObj *pInternode = gluNewQuadric(); // TODO: it is slow
	glPushMatrix();		

		glTranslatef(pos.x(), pos.y(), pos.z());
		
		Vect3d axis = Vect3d(0, 1, 0).Cross(vec);
		axis.Normalize();

		float a = acos(Vect3d(0, 1, 0).Dot(vec) / vec.Length()) * 180 / PI;
		glRotatef(a, axis.x(), axis.y(), axis.z());
		
		glRotatef(-90, 1, 0, 0);

        width = 0.02;//pow((GrownStep - nGrowthStep + 1) + 0.0, 0.5) * 0.04;//pow(sqrt(0.9), (int)(GrownStep - nGrowthStep)) * 0.04;
		gluCylinder(pInternode, width, width, vec.Length(), 15, 15);			
		gluDeleteQuadric(pInternode);

	glPopMatrix();	

	//	Render Buds
	if(iRenderBud != 0)
	{
		if(pTerminalBud != NULL)
		{
			pTerminalBud->Render();	
		}

		if(pAnxillaryBud != NULL)
		{
			pAnxillaryBud->Render();	
		}
	}
	////	Render Leaf
	if(pLeaf != NULL)
	{
		pLeaf->Render();	
	}
	//
	glPopMatrix();
}
Exemple #4
0
bool StructuredGrid::is_in(const Geometry& geometry, const int i) const {
	Vect3d low_point = index_to_vect(i).cast<double>().cwiseProduct(cell_size)+low;
	const Vect3d test_point = low_point + Vect3d(0.5,0.5,0.5).cwiseProduct(cell_size);
	if (geometry.is_in(test_point)) return true;
	for (int i = 0; i < 2; ++i) {
		for (int j = 0; j < 2; ++j) {
			for (int k = 0; k < 2; ++k) {
				const Vect3d test_point = low_point + Vect3d(i,j,k).cwiseProduct(cell_size);
				if (geometry.is_in(test_point)) {
					return true;
				}
			}
		}
	}
	return false;
}
Exemple #5
0
void StructuredGrid::get_overlap(const Vect3d& overlap_low, const Vect3d& overlap_high, std::vector<int>& indicies, std::vector<double>& volume) const {
	indicies.clear();
	volume.clear();
	if ((overlap_low.array() >= high.array()).any()) return;
	if ((overlap_high.array() <= low.array()).any()) return;
	Vect3d snap_low = overlap_low + Vect3d(tolerance,tolerance,tolerance);
	Vect3d snap_high = overlap_high - Vect3d(tolerance,tolerance,tolerance);
	for (int i = 0; i < 3; ++i) {
		if (snap_low[i] < low[i]) {
			snap_low[i] = low[i];
		}
		if (snap_high[i] > high[i]) {
			snap_high[i] = high[i]-tolerance;
		}
	}
	Vect3i lowi,highi;
	lowi = get_cell_index_vector(snap_low);
	highi = get_cell_index_vector(snap_high);


	const double inv_volume = 1.0/cell_size.prod();
	for (int i = lowi[0]; i <= highi[0]; ++i) {
		for (int j = lowi[1]; j <= highi[1]; ++j) {
			for (int k = lowi[2]; k <= highi[2]; ++k) {
				indicies.push_back(vect_to_index(i, j, k));
				Vect3d low_point = Vect3i(i,j,k).cast<double>().cwiseProduct(cell_size) + low;
				Vect3d high_point = low_point + cell_size;
				for (int i = 0; i < 3; ++i) {
					if (high_point[i] > overlap_high[i]) {
						high_point[i] = overlap_high[i];
					}
					if (low_point[i] < overlap_low[i]) {
						low_point[i] = overlap_low[i];
					}
				}
				volume.push_back((high_point-low_point).prod()*inv_volume);
			}
		}
	}
}
Exemple #6
0
void Diffusion::integrate(const double dt) {

	const int n = get_species().size();
	for (int i = 0; i < n; ++i) {
		Species &s = *(get_species()[i]);
		const Vect3d step_length = calc_step_length(s, dt);
		const int n = s.mols.size();
		for (int j = 0; j < n; ++j) {
			s.mols.r0[j] = s.mols.r[j];
			s.mols.r[j] += step_length.cwiseProduct(Vect3d(norm(),norm(),norm()));
		}
	}

}
Exemple #7
0
//----------------------------------------------//
void Curve::get_pos(Vect3d* dest, GLfloat t)
{
	if(dest == NULL)
	{
		std::cerr << "curve.cpp : dest pointer is null" << std::endl;
		exit(0);
	}

	//prepare polynomial coefficients
	GLfloat coeff[4];
	GLfloat t_cube = pow(t,3.0f), t_square = pow(t,2.0f);
	coeff[0] =   2.0 * t_cube - 3.0 * t_square + 1;
	coeff[1] = 		   t_cube - 2.0 * t_square + t;
	coeff[2] = -       t_cube +       t_square;
	coeff[3] = - 2.0 * t_cube + 3.0 * t_square;

	//dest is set to 0
	*dest = Vect3d(0.0, 0.0, 0.0);

	//dest = a*coeffA + b*coeffV + c*coeffC + d*coeffD
	for(int i=0;i<4;i++)
		*dest = *dest + (ctrl_pts[i]*coeff[i]);
}
int main(int argc, char* argv[]) {

   if (argc < 2) {
      std::cout << "Usage: simpleBD h" << std::endl;
      exit(-1);
   }

   const unsigned int num_particles = 1;
   const double h_in = atof(argv[1]);


   const double end_time = 1.0;
   //const double dt = 0.0001;
   const double dt = h_in*h_in/PI;

   /*
    * Create Compartments (a structured grid from r = (0,0,0) to r = (1,0.1,0.1). resolution = h = h_in for all dimensions)
    */
   StructuredGrid grid(Vect3d(0.25-h_in,0,0), Vect3d(0.75+h_in,1,1), Vect3d(h_in,h_in,h_in));

   /*
    * Create "red" species with D=1. Fill with a uniform distribution of particles
    */
   Species red(1, grid);


   /*
    * create diffusion operator and apply to red species
    */
   Diffusion bd; bd.add_species(red);

   /*
    * Create simulation boundary planes
    */
   xplane xlow(0,1),xhigh(1,-1);
   yplane ylow(0,1),yhigh(1,-1);
   zplane zlow(0,1),zhigh(1,-1);
   xplane couple_C_to_M_1(0.25,-1);
   xplane couple_C_to_M_2(0.75,1);

   xplane first_line_of_compartments(0.25-0.5*h_in,1);
   xplane second_line_of_compartments(0.25+0.5*h_in,1);
   xplane second_last_line_of_compartments(0.75-0.5*h_in,1);
   xplane last_line_of_compartments(0.75+0.5*h_in,1);



   /*
    * Create jump (periodic) boundaries
    */
   JumpBoundaryWithCorrection<xplane> jb1(xlow,xhigh-xlow); jb1.add_species(red);
   JumpBoundary<yplane> jb2(ylow,yhigh-ylow); jb2.add_species(red);
   JumpBoundary<zplane> jb3(zlow,zhigh-zlow); jb3.add_species(red);
   JumpBoundary<yplane> jb4(yhigh,ylow-yhigh); jb4.add_species(red);
   JumpBoundary<zplane> jb5(zhigh,zlow-zhigh); jb5.add_species(red);

   /*
    * Create reflective boundary
    */
   ReflectiveBoundary<xplane> rb(xhigh); rb.add_species(red);

   /*
    * create Next Subvolume Method operator. The constructor takes the compartment grid as input
    */
   NextSubvolumeMethod nsm(red.grid);

   // add diffusion equations to nsm
   //nsm.add_diffusion(red);
   nsm.add_diffusion(red, red.D/pow(h_in,2));


   /*
    * Setup reactions for coupling
    */

//   nsm.remove_diffusion_between(red, second_line_of_compartments, first_line_of_compartments);
//   nsm.remove_diffusion_between(red, second_last_line_of_compartments, last_line_of_compartments);
//   nsm.add_diffusion_between(red, (2.0*h_in/sqrt(PI*red.D*dt))*(red.D/pow(h_in,2)), second_line_of_compartments, first_line_of_compartments);
//   nsm.add_diffusion_between(red, (2.0*h_in/sqrt(PI*red.D*dt))*(red.D/pow(h_in,2)), second_last_line_of_compartments, last_line_of_compartments);

   nsm.add_diffusion_between(red,red.D/pow(h_in,2),ylow, yhigh);
   nsm.add_diffusion_between(red,red.D/pow(h_in,2),yhigh, ylow);
   nsm.add_diffusion_between(red,red.D/pow(h_in,2),zlow, zhigh);
   nsm.add_diffusion_between(red,red.D/pow(h_in,2),zhigh, zlow);

//   nsm.clear_reactions(first_line_of_compartments);
//   nsm.clear_reactions(last_line_of_compartments);

   nsm.list_reactions();



   /*
    * Create coupling boundaries between compartments and free-space
    */
   Intersection<xplane,xplane> compartment_volume(couple_C_to_M_1, couple_C_to_M_2);
   CouplingBoundary_C_to_M<Intersection<xplane,xplane> > c_to_m(compartment_volume, nsm); c_to_m.add_species(red, dt);
   CouplingBoundary_M_to_C<Intersection<xplane,xplane> > m_to_c(compartment_volume, nsm); m_to_c.add_species(red);


   std::vector<int> bins_m, bins_c;
   const int num_bins = 100;
   bins_m.assign(num_bins,0);
   bins_c.assign(red.grid.get_cells_along_axes()[0],0);

   for (int i = 0; i < 50000; ++i) {
	   std::cout << "doing iteration " << i << std::endl;
	   red.fill_uniform(Vect3d(0,0,0),Vect3d(1.0,1,1),num_particles);
	   // calculate next reaction times for all compartments
	   nsm.reset_all_priorities();

	   /*
	    * Run simulation until end_time with timestep dt
	    */
	   run(red, end_time, dt,  nsm, bd, jb1, jb2, jb3, jb4, jb5, rb,  m_to_c, c_to_m);

	   if (red.mols.size() > 0) {
		   const double scaled_position = (red.mols.r[0][0])*num_bins;
		   if ((scaled_position < 0) || (scaled_position > num_bins)) {
			   printf("outside area: position = (%f %f %f)\n",red.mols.r[0][0],red.mols.r[0][1],red.mols.r[0][2]);
		   }
		   const int index = int(scaled_position);
		   bins_m[index]++;
		   red.mols.delete_molecule(0);
	   }

	   const int nc = red.grid.size();
	   for(int i = 0; i < nc; i++) {
		   Vect3i cell_indices = red.grid.get_cell_indicies(i);
		   bins_c[cell_indices[0]] += red.copy_numbers[i];
		   red.copy_numbers[i] = 0;
	   }
   }




   std::ofstream f;
   f.open(("output/simpleBD_couple_single_mols_"+std::string(argv[1])+".dat").c_str());
   f << end_time << ' ';
   int count = 0;
   BOOST_FOREACH(int x,bins_m) {
      f << x <<' ';
      count += x;
   }
Exemple #9
0
Vect3d StructuredGrid::get_random_point(const int i) const {
	boost::variate_generator<base_generator_type&, boost::uniform_real<> > uni(generator,boost::uniform_real<>(0,1));
	return low + (index_to_vect(i).cast<double>() + Vect3d(uni(),uni(),uni())).cwiseProduct(cell_size);
}
Exemple #10
0
Rectangle StructuredGrid::get_face_between(const int i, const int j) const {
	Vect3i ii = index_to_vect(i);
	Vect3d clow = ii.cast<double>().cwiseProduct(cell_size) + low;
	const int diff = j-i;
	if (diff == num_cells_along_yz) {
		Vect3d lower_left = clow + Vect3d(cell_size[0],0,0);
		Vect3d upper_left = clow + Vect3d(cell_size[0],cell_size[1],0);
		Vect3d lower_right = clow + Vect3d(cell_size[0],0,cell_size[2]);
		return Rectangle(lower_left,upper_left,lower_right);
	} else if (diff == num_cells_along_axes[2]) {
		Vect3d lower_left = clow + Vect3d(0,cell_size[1],0);
		Vect3d lower_right = clow + Vect3d(cell_size[0],cell_size[1],0);
		Vect3d upper_left= clow + Vect3d(0,cell_size[1],cell_size[2]);
		return Rectangle(lower_left,upper_left,lower_right);
	} else if (diff == 1) {
		Vect3d lower_left = clow + Vect3d(0,0,cell_size[2]);
		Vect3d upper_left = clow + Vect3d(cell_size[0],0,cell_size[2]);
		Vect3d lower_right = clow + Vect3d(0,cell_size[1],cell_size[2]);
		return Rectangle(lower_left,upper_left,lower_right);
	} else if (diff == -num_cells_along_yz) {
		Vect3d lower_left = clow + Vect3d(0,0,0);
		Vect3d lower_right = clow + Vect3d(0,cell_size[1],0);
		Vect3d upper_left = clow + Vect3d(0,0,cell_size[2]);
		return Rectangle(lower_left,upper_left,lower_right);
	} else if (diff == -num_cells_along_axes[2]) {
		Vect3d lower_left = clow + Vect3d(0,0,0);
		Vect3d upper_left = clow + Vect3d(cell_size[0],0,0);
		Vect3d lower_right = clow + Vect3d(0,0,cell_size[2]);
		return Rectangle(lower_left,upper_left,lower_right);
	} else if (diff == -1) {
		Vect3d lower_left = clow + Vect3d(0,0,0);
		Vect3d lower_right = clow + Vect3d(cell_size[0],0,0);
		Vect3d upper_left = clow + Vect3d(0,cell_size[1],0);
		return Rectangle(lower_left,upper_left,lower_right);
	} else {
		ERROR("cells are not adjacent");
	}
	return Rectangle(Vect3d(),Vect3d(),Vect3d());
}
Vect3d Vect3d::operator -(Vect3d v)
{
	return Vect3d(x-v.GetX(), y-v.GetY(), z-v.GetZ());
}
Vect3d Vect3d::operator +(Vect3d v)
{
	return Vect3d(x+v.GetX(), y+v.GetY(), z+v.GetZ());
}
Exemple #13
0
int main(int argc, char* argv[]) {

   if (argc < 3) {
      std::cout << "Usage: simpleBD num_particles h" << std::endl;
      exit(-1);
   }

   const unsigned int num_particles = atoi(argv[1]);
   const double h_in = atof(argv[2]);

   std::ofstream tf;
   tf.open(("output/time_simpleBD_couple_"+std::string(argv[1])+"_"+std::string(argv[2])+".dat").c_str());
   boost::progress_timer t(tf);

   const double end_time = 1.0;
   //const double dt = 0.0001;
   const double dt = h_in*h_in/PI;

   /*
    * Create Compartments (a structured grid from r = (0,0,0) to r = (1,0.1,0.1). resolution = h = h_in for all dimensions)
    */
   StructuredGrid grid(Vect3d(0.25-h_in,0,0), Vect3d(0.75+h_in,1,1), Vect3d(h_in,h_in,h_in));

   /*
    * Create "red" species with D=1. Fill with a uniform distribution of particles
    */
   Species red(1, grid);
   red.fill_uniform(Vect3d(0,0,0),Vect3d(0.25,1,1),num_particles/4.0);
   red.fill_uniform(Vect3d(0.75,0,0),Vect3d(1.0,1,1),num_particles/4.0);
   //red.fill_uniform(Vect3d(0.75,0,0),Vect3d(1.0,0.1,0.1),1);
   red.fill_uniform(num_particles/2.0);

   /*
    * create diffusion operator and apply to red species
    */
   Diffusion bd; bd.add_species(red);

   /*
    * Create simulation boundary planes
    */
   xplane xlow(0,1),xhigh(1,-1);
   yplane ylow(0,1),yhigh(1,-1);
   zplane zlow(0,1),zhigh(1,-1);
   xplane couple_C_to_M_1(0.25,-1);
   xplane couple_C_to_M_2(0.75,1);

   xplane first_line_of_compartments(0.25-0.5*h_in,1);
   xplane second_line_of_compartments(0.25+0.5*h_in,1);
   xplane second_last_line_of_compartments(0.75-0.5*h_in,1);
   xplane last_line_of_compartments(0.75+0.5*h_in,1);



   /*
    * Create jump (periodic) boundaries
    */
   JumpBoundaryWithCorrection<xplane> jb1(xlow,xhigh-xlow); jb1.add_species(red);
   JumpBoundary<yplane> jb2(ylow,yhigh-ylow); jb2.add_species(red);
   JumpBoundary<zplane> jb3(zlow,zhigh-zlow); jb3.add_species(red);
   JumpBoundary<yplane> jb4(yhigh,ylow-yhigh); jb4.add_species(red);
   JumpBoundary<zplane> jb5(zhigh,zlow-zhigh); jb5.add_species(red);

   /*
    * Create reflective boundary
    */
   ReflectiveBoundary<xplane> rb(xhigh); rb.add_species(red);

   /*
    * create Next Subvolume Method operator. The constructor takes the compartment grid as input
    */
   NextSubvolumeMethod nsm(red.grid);

   // add diffusion equations to nsm
   //nsm.add_diffusion(red);
   nsm.add_diffusion(red, red.D/pow(h_in,2));


   /*
    * Setup reactions for coupling
    */

//   nsm.remove_diffusion_between(red, second_line_of_compartments, first_line_of_compartments);
//   nsm.remove_diffusion_between(red, second_last_line_of_compartments, last_line_of_compartments);
//   nsm.add_diffusion_between(red, (2.0*h_in/sqrt(PI*red.D*dt))*(red.D/pow(h_in,2)), second_line_of_compartments, first_line_of_compartments);
//   nsm.add_diffusion_between(red, (2.0*h_in/sqrt(PI*red.D*dt))*(red.D/pow(h_in,2)), second_last_line_of_compartments, last_line_of_compartments);

   nsm.add_diffusion_between(red,red.D/pow(h_in,2),ylow, yhigh);
   nsm.add_diffusion_between(red,red.D/pow(h_in,2),yhigh, ylow);
   nsm.add_diffusion_between(red,red.D/pow(h_in,2),zlow, zhigh);
   nsm.add_diffusion_between(red,red.D/pow(h_in,2),zhigh, zlow);

//   nsm.clear_reactions(first_line_of_compartments);
//   nsm.clear_reactions(last_line_of_compartments);

   nsm.list_reactions();

   // calculate next reaction times for all compartments
   nsm.reset_all_priorities();

   /*
    * Create coupling boundaries between compartments and free-space
    */
   Intersection<xplane,xplane> compartment_volume(couple_C_to_M_1, couple_C_to_M_2);
   CouplingBoundary_C_to_M<Intersection<xplane,xplane> > c_to_m(compartment_volume, nsm); c_to_m.add_species(red, dt);
   CouplingBoundary_M_to_C<Intersection<xplane,xplane> > m_to_c(compartment_volume, nsm); m_to_c.add_species(red);


   /*
    * Run simulation until end_time with timestep dt
    */
   run(red, end_time, dt,  nsm, bd, jb1, jb2, jb3, jb4, jb5, rb,  m_to_c, c_to_m);
   //nsm(dt/2);
   //run(red, end_time, dt, nsm, c_to_m, bd, jb1, jb2, jb3, jb4, jb5, rb,  m_to_c, output);

   std::vector<int> bins;
   make_histogram(bins,red,100, 0,1);

   std::ofstream f;
   f.open(("output/simpleBD_couple_mols_"+std::string(argv[1])+"_"+std::string(argv[2])+".dat").c_str());
   f << end_time << ' ';
   int count = 0;
   BOOST_FOREACH(int x,bins) {
      f << x <<' ';
      count += x;
   }
int main(int argc, char* argv[]) {

	if (argc < 2) {
		std::cout << "Usage: simpleReactWithJumpCorrection num_particles" << std::endl;
		exit(-1);
	}

	const unsigned int num_particles = atoi(argv[1]);

	std::ofstream tf;
	tf.open(("time_simpleReactWithJumpCorrection_"+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(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 (0 -> red) 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
	 */
	JumpBoundaryWithCorrection<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 iterations = end_time/dt;
	const double num_out = 100;
	const int it_per_out = int(iterations/num_out);

	/*
	 * Run simulation until end_time with timestep dt
	 */
	run(red, end_time, dt, bd, fb, jb1, jb2, jb3, jb4, jb5, rb, dr);

	std::vector<int> bins;
	make_histogram(bins,red,100, 0,1);

	std::ofstream f;
	f.open(("simpleReactWithJumpCorrection_"+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;
}
Exemple #15
0
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;
}