Esempio n. 1
0
bool compare_ensembles( swarm::ensemble& e1, swarm::ensemble &e2 , double & pos_diff, double & vel_diff, double & time_diff ) {
	if (e1.nsys() != e2.nsys() || e1.nbod() != e2.nbod() ) return false;

	pos_diff = vel_diff = time_diff = 0;

	for(int i = 0; i < e1.nsys(); i++) {
		for(int j = 0; j < e1.nbod() ; j++){

			// Distance between body position in ensemble e1 and e2
			double dp = sqrt( 
					  square ( e1[i][j][0].pos() - e2[i][j][0].pos() ) 
					+ square ( e1[i][j][1].pos() - e2[i][j][1].pos() ) 
					+ square ( e1[i][j][2].pos() - e2[i][j][2].pos() ) ) ;

			// Average magnitude of the position in e1 and e2
			double ap = sqrt( 
					  square ( e1[i][j][0].pos() + e2[i][j][0].pos() ) 
					+ square ( e1[i][j][1].pos() + e2[i][j][1].pos() ) 
					+ square ( e1[i][j][2].pos() + e2[i][j][2].pos() ) ) / 2.0 ;

			// Difference between body velocities in ensemble e1 and e2
			double dv = sqrt( 
					  square ( e1[i][j][0].vel() - e2[i][j][0].vel() ) 
					+ square ( e1[i][j][1].vel() - e2[i][j][1].vel() ) 
					+ square ( e1[i][j][2].vel() - e2[i][j][2].vel() ) ) ;

			// Average magnitude of the velocity in e1 and e2
			double av = sqrt( 
					  square ( e1[i][j][0].vel() + e2[i][j][0].vel() ) 
					+ square ( e1[i][j][1].vel() + e2[i][j][1].vel() ) 
					+ square ( e1[i][j][2].vel() + e2[i][j][2].vel() ) ) / 2.0 ;

			if ( dp > pos_diff ) pos_diff = dp;
			if ( dv > vel_diff ) vel_diff = dv;

		}

		// Difference between time divided by average of the two
		double dt = fabs(e1[i].time() - e2[i].time())
			/(e1[i].time() + e2[i].time())*2;
		if ( dt > time_diff ) time_diff = dt;

	}
	return true;
}
Esempio n. 2
0
void print_selected_systems_for_demo(swarm::ensemble& ens, unsigned int nprint, std::ostream &os = std::cout)
{
  if(nprint>ens.nsys()) nprint = ens.nsys();
  for(unsigned int systemid = 0; systemid< nprint; ++systemid)
      print_system(ens,systemid,os);
}
Esempio n. 3
0
void print_system(const swarm::ensemble& ens, const int systemid, std::ostream &os = std::cout)
{
  enum {
    JACOBI, BARYCENTRIC, ASTROCENTRIC
  } COORDINATE_SYSTEM = BARYCENTRIC;
  const bool use_jacobi = cfg.optional("use_jacobi", 0);  
  if(use_jacobi) COORDINATE_SYSTEM = JACOBI;

  

  std::streamsize cout_precision_old = os.precision();
  os.precision(10);
  os << "sys_idx= " << systemid << " sys_id= " << ens[systemid].id() << " time= " << ens.time(systemid) << "\n";
      double star_mass = ens.mass(systemid,0);
      double mass_effective = star_mass;
      double bx, by, bz, bvx, bvy, bvz;
      switch(COORDINATE_SYSTEM) 
	{
	case JACOBI:
	  ens.get_barycenter(systemid,bx,by,bz,bvx,bvy,bvz,0);
	  break;
	  
	case BARYCENTRIC:
	  ens.get_barycenter(systemid,bx,by,bz,bvx,bvy,bvz);
	  break;
	  
	case ASTROCENTRIC:
	  ens.get_body(systemid,0,star_mass,bx,by,bz,bvx,bvy,bvz);
	  break;
	}
      
      for(unsigned int bod=1;bod<ens.nbod();++bod) // Skip star since printing orbits
	{
	  //	  std::cout << "pos= (" << ens.x(systemid, bod) << ", " <<  ens.y(systemid, bod) << ", " << ens.z(systemid, bod) << ") vel= (" << ens.vx(systemid, bod) << ", " <<  ens.vy(systemid, bod) << ", " << ens.vz(systemid, bod) << ").\n";
	  double mass = ens.mass(systemid,bod);
	  
	  switch(COORDINATE_SYSTEM) 
	    {
	    case JACOBI:
	      ens.get_barycenter(systemid,bx,by,bz,bvx,bvy,bvz,bod-1);
	      mass_effective += mass;
	      break;
	      
	    case BARYCENTRIC:
	      mass_effective = star_mass + mass;
	      break;
	      
	    case ASTROCENTRIC:
	      mass_effective = star_mass + mass;
	      break;
	    }
	  double x = ens.x(systemid,bod)-bx;
	  double y = ens.y(systemid,bod)-by;
	  double z = ens.z(systemid,bod)-bz;
	  double vx = ens.vx(systemid,bod)-bvx;
	  double vy = ens.vy(systemid,bod)-bvy;
	  double vz = ens.vz(systemid,bod)-bvz;
	  
	  double a, e, i, O, w, M;
	  calc_keplerian_for_cartesian(a,e,i,O,w,M, x,y,z,vx,vy,vz, mass_effective);
	  i *= 180/M_PI;
	  O *= 180/M_PI;
	  w *= 180/M_PI;
	  M *= 180/M_PI;
	  //	  os << " b= " << bod << " m= " << mass << " a= " << a << " e= " << e << " i= " << i << " Omega= " << O << " omega= " << w << " M= " << M << "\n";
	  os << ens[systemid].id() << " " << bod << " " << mass << " " << a << " " << e << " " << i << " " << O << " " << w << " " << M << "\n";
	}

  os.precision(cout_precision_old);
  os << std::flush;
}