diff --git a/src/geometry.cpp b/src/geometry.cpp index 22e3cbfe34..2c83e38366 100644 --- a/src/geometry.cpp +++ b/src/geometry.cpp @@ -108,33 +108,31 @@ find_cell(Particle* p, int search_surf) { // Find the distribcell instance number. if (c.material_.size() > 1 || c.sqrtkT_.size() > 1) { - //TODO: off-by-one indexing - int distribcell_index = c.distribcell_index_ - 1; int offset = 0; for (int i = 0; i < p->n_coord; i++) { Cell& c_i {*cells[p->coord[i].cell]}; if (c_i.type_ == FILL_UNIVERSE) { - offset += c_i.offset_[distribcell_index]; + offset += c_i.offset_[c.distribcell_index_]; } else if (c_i.type_ == FILL_LATTICE) { Lattice& lat {*lattices[p->coord[i+1].lattice-1]}; int i_xyz[3] {p->coord[i+1].lattice_x, p->coord[i+1].lattice_y, p->coord[i+1].lattice_z}; if (lat.are_valid_indices(i_xyz)) { - offset += lat.offset(distribcell_index, i_xyz); + offset += lat.offset(c.distribcell_index_, i_xyz); } } } - p->cell_instance = offset + 1; + p->cell_instance = offset; } else { - p->cell_instance = 1; + p->cell_instance = 0; } // Set the material and temperature. p->last_material = p->material; int32_t mat; if (c.material_.size() > 1) { - mat = c.material_[p->cell_instance-1]; + mat = c.material_[p->cell_instance]; } else { mat = c.material_[0]; } @@ -145,7 +143,7 @@ find_cell(Particle* p, int search_surf) { } p->last_sqrtkT = p->sqrtkT; if (c.sqrtkT_.size() > 1) { - p->sqrtkT = c.sqrtkT_[p->cell_instance-1]; + p->sqrtkT = c.sqrtkT_[p->cell_instance]; } else { p->sqrtkT = c.sqrtkT_[0]; } diff --git a/src/geometry_aux.cpp b/src/geometry_aux.cpp index 9c1d17b4d6..a304790125 100644 --- a/src/geometry_aux.cpp +++ b/src/geometry_aux.cpp @@ -220,8 +220,7 @@ prepare_distribcell(int32_t* filter_cell_list, int n) // Search through universes for distributed cells and assign each one a // unique distribcell array index. - //TODO: off-by-one - int distribcell_index = 1; + int distribcell_index = 0; std::vector target_univ_ids; for (Universe* u : universes) { for (auto cell_indx : u->cells_) { diff --git a/src/tallies/tally_filter_distribcell.F90 b/src/tallies/tally_filter_distribcell.F90 index ae4e09023d..f35ffc3ec4 100644 --- a/src/tallies/tally_filter_distribcell.F90 +++ b/src/tallies/tally_filter_distribcell.F90 @@ -59,14 +59,14 @@ contains do i = 1, p % n_coord if (cells(p % coord(i) % cell + 1) % type() == FILL_UNIVERSE) then offset = offset + cells(p % coord(i) % cell + 1) & - % offset(distribcell_index-1) + % offset(distribcell_index) elseif (cells(p % coord(i) % cell + 1) % type() == FILL_LATTICE) then if (lattices(p % coord(i + 1) % lattice) % are_valid_indices([& p % coord(i + 1) % lattice_x, & p % coord(i + 1) % lattice_y, & p % coord(i + 1) % lattice_z])) then offset = offset + lattices(p % coord(i + 1) % lattice) & - % offset(distribcell_index - 1, & + % offset(distribcell_index, & [p % coord(i + 1) % lattice_x, & p % coord(i + 1) % lattice_y, & p % coord(i + 1) % lattice_z]) @@ -155,10 +155,10 @@ contains ! Get the distribcell index for this cell map = cells(i_cell) % distribcell_index() - path_len = distribcell_path_len(i_cell-1, map-1, target_offset, & + path_len = distribcell_path_len(i_cell-1, map, target_offset, & root_universe) allocate(path_c(path_len)) - call distribcell_path(i_cell-1, map-1, target_offset, root_universe, & + call distribcell_path(i_cell-1, map, target_offset, root_universe, & path_c) do i = 1, min(path_len, MAX_LINE_LEN) if (path_c(i) == C_NULL_CHAR) exit