Example #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;
}
Example #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);
}