Skip to content

Commit

Permalink
core: particle_data: Skip empty cells when searching for particle.
Browse files Browse the repository at this point in the history
  • Loading branch information
fweik committed Dec 8, 2018
1 parent 9619172 commit 7ccd8eb
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/core/particle_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -844,16 +844,16 @@ int remove_particle(int p_id) {
}

namespace {
std::pair<Cell *, size_t> find_particle(const Particle *p, Cell *c) {
const auto n = p - c->part;
if ((n >= 0) && (n < c->n)) {
std::pair<Cell *, size_t> find_particle(Particle *p, Cell *c) {
const auto n = (c->n > 0) ? std::distance(c->part, p) : -1;
if ((n >= 0) && (n < c->n) && ((c->part + n) == p)) {
return {c, n};
} else {
return {nullptr, 0};
}
}

std::pair<Cell *, size_t> find_particle(const Particle *p, CellPList cells) {
std::pair<Cell *, size_t> find_particle(Particle *p, CellPList cells) {
for (auto &c : cells) {
auto res = find_particle(p, c);
if (res.first) {
Expand All @@ -866,7 +866,7 @@ std::pair<Cell *, size_t> find_particle(const Particle *p, CellPList cells) {
} // namespace

void local_remove_particle(int part) {
const Particle *p = local_particles[part];
Particle *p = local_particles[part];
assert(p);
assert(not p->l.ghost);

Expand All @@ -884,7 +884,7 @@ void local_remove_particle(int part) {
std::tie(cell, n) = find_particle(p, local_cells);
}

assert(cell);
assert(cell && cell->part && (n < cell->n) && ((cell->part + n) == p));

Particle p_destroy = extract_indexed_particle(cell, n);
}
Expand Down

0 comments on commit 7ccd8eb

Please sign in to comment.