Aboria

PrevUpHomeNext

ID Searching

As well as neighbourhood searching, Aboria has functionality to search by each particle's unique id. First, let's create a set of N particles and randomly rearrange their position in the vector

const size_t N = 100;
typedef Particles<> particle_type;
particle_type particles(N);
std::default_random_engine g;
std::shuffle(particles.begin(), particles.end(), g);

This will create a set of particles that each have a unique id between 0 and N-1 (but their positions in the vector particles is randomised). Now, we are going to turn on the id search capability for particles

particles.init_id_search();

Then we will try and find the particle with id equal to 2.

auto id_2 = particles.get_query().find(2);
assert(*get<id>(id_2) == 2);

Note that each find function (e.g. Aboria::CellListQuery::find) returns an iterator to the particle set. If we try and search for an id which doesn't exist, then this iterator will point to the end of the particle vector

auto id_2N = particles.get_query().find(2 * N);
assert(id_2N == iterator_to_raw_pointer(particles.end()));

Finally, a note on performance: The id search is done by internally creating vectors of id and indicies ordered by id. Keeping these vectors ordered at each call to Aboria::Particles::update_positions takes O(Nlog(N)). The call to find performs a binary search on the ordered vectors, with takes O(log(N)) time.


PrevUpHomeNext