diff --git a/src/geometry.cpp b/src/geometry.cpp index 1cbb74935..563e5467b 100644 --- a/src/geometry.cpp +++ b/src/geometry.cpp @@ -66,11 +66,16 @@ bool check_cell_overlap(Particle& p, bool error) //============================================================================== int cell_instance_at_level(const Particle& p, int level) { + // throw error if the requested level is too deep for the geometry if (level > p.n_coord()) { fatal_error(fmt::format("Cell instance at level {} requested, but only {} levels exist in the model.", level, p.n_coord())); } + // determine the cell instance Cell& c {*model::cells[p.coord(level).cell]}; + + if (c.distribcell_index_ == C_NONE) return C_NONE; + int instance = 0; for (int i = 0; i < level; i++) { const auto& c_i {*model::cells[p.coord(i).cell]}; diff --git a/src/plot.cpp b/src/plot.cpp index 999cf3d29..c3ef36467 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -47,7 +47,7 @@ IdData::set_value(size_t y, size_t x, const Particle& p, int level) { data_(y, x, 1) = NOT_FOUND; } else { data_(y, x, 0) = model::cells.at(p.coord(level).cell)->id_; - data_(y, x, 1) = p.cell_instance(); + data_(y, x, 1) = level == p.n_coord() - 1 ? p.cell_instance() : cell_instance_at_level(p, level); } // set material data