Example #1
0
int main() {
  const char * Pname = "Ar";

  typedef chimp::RuntimeDB<> DB;
  DB db;
  db.addParticleType(Pname);

  std::cout << "Accessed with string index, each property individually:\n";
  std::cout << "\tp.name:  "   << db[Pname].name::value << std::endl;
  std::cout << "\tp.mass:  "   << db[Pname].mass::value << std::endl;
  std::cout << "\tp.charge:  " << db[Pname].charge::value << std::endl;

  int i = db.findParticleIndx(Pname);
  std::cout << "Accessed with integer index, each property individually:\n";
  std::cout << "\tp.name:  "   << db[i].name::value << std::endl;
  std::cout << "\tp.mass:  "   << db[i].mass::value << std::endl;
  std::cout << "\tp.charge:  " << db[i].charge::value << std::endl;

  std::cout << "Accessed with const reference:\n";
  const DB::Properties & p = db[Pname];
  std::cout << "Printing all properties by using stream insertion:\n";
  std::cout << "\t{" << p << '}' << std::endl;

  return 0;
}
Example #2
0
   void check_table( const DB & db, unsigned int cross_species_num ) {
     int i87Rb = db.findParticleIndx("87Rb");
     int i85Rb = db.findParticleIndx("85Rb");
 
     {/* 87Rb * 87Rb */
       const typename DB::Set & set = db(i87Rb,i87Rb);
 
       BOOST_CHECK_EQUAL( set.rhs.size(), 1u );
 
       typedef typename DB::Set::Equation::list::const_iterator EIter;
 
       {
         std::ostringstream estr;
         for ( EIter i = set.rhs.begin(); i != set.rhs.end(); ++i ) {
           i->print( estr, db ) << '\n';
           BOOST_CHECK_EQUAL( i->interaction->getLabel(), "elastic" );
         }
 
         BOOST_CHECK_EQUAL( estr.str(), "2 87Rb  -->  2 87Rb\n" );
       }
     }/* 87Rb * 87Rb */
 
     {/* 85Rb * 85Rb */
       const typename DB::Set & set = db(i85Rb,i85Rb);
 
       BOOST_CHECK_EQUAL( set.rhs.size(), 1u );
 
       typedef typename DB::Set::Equation::list::const_iterator EIter;
 
       {
         std::ostringstream estr;
         for ( EIter i = set.rhs.begin(); i != set.rhs.end(); ++i ) {
           i->print( estr, db ) << '\n';
           BOOST_CHECK_EQUAL( i->interaction->getLabel(), "elastic" );
         }
 
         BOOST_CHECK_EQUAL( estr.str(), "2 85Rb  -->  2 85Rb\n" );
       }
     }/* 85Rb * 85Rb */
 
     {/* 87Rb * 85Rb */
       const typename DB::Set & set = db(i85Rb,i87Rb);
 
       // These if-else statements are just to make error reports easier to
       // read
       if ( cross_species_num == 0u )
         BOOST_CHECK_EQUAL( set.rhs.size(), 0u );
       else if ( cross_species_num == 1u )
         BOOST_CHECK_EQUAL( set.rhs.size(), 1u );
       else
         BOOST_CHECK_EQUAL( set.rhs.size(), cross_species_num );
     }/* 85Rb * 85Rb */
   }