Use 0-based indexing for universes

This commit is contained in:
Sterling Harper 2018-08-24 17:14:11 -04:00
parent 7b31853066
commit 3be4e09e8e
8 changed files with 17 additions and 22 deletions

View file

@ -439,8 +439,7 @@ Cell::to_hdf5(hid_t cell_group) const
write_string(cell_group, "name", name, false);
}
//TODO: Fix the off-by-one indexing.
write_dataset(cell_group, "universe", global_universes[universe-1]->id);
write_dataset(cell_group, "universe", global_universes[universe]->id);
// Write the region specification.
if (!region.empty()) {

View file

@ -25,7 +25,7 @@ check_cell_overlap(Particle* p) {
// loop through each coordinate level
for (int j = 0; j < n_coord; j++) {
Universe& univ = *global_universes[p->coord[j].universe - 1];
Universe& univ = *global_universes[p->coord[j].universe];
int n = univ.cells.size();
// loop through each cell on this level
@ -64,8 +64,6 @@ find_cell(Particle* p, int search_surf) {
p->coord[p->n_coord-1].universe = openmc_root_universe;
i_universe = openmc_root_universe;
}
//TODO: off-by-one indexing
--i_universe;
// If a surface was indicated, only search cells from the neighbor list of
// that surface.
@ -90,8 +88,7 @@ find_cell(Particle* p, int search_surf) {
i_cell = search_cells[i];
// Make sure the search cell is in the same universe.
//TODO: off-by-one indexing
if (global_cells[i_cell]->universe - 1 != i_universe) continue;
if (global_cells[i_cell]->universe != i_universe) continue;
Position r {p->coord[p->n_coord-1].xyz};
Direction u {p->coord[p->n_coord-1].uvw};
@ -165,7 +162,7 @@ find_cell(Particle* p, int search_surf) {
//! Found a lower universe, update this coord level then search the next.
// Set the lower coordinate level universe.
p->coord[p->n_coord].universe = c.fill + 1;
p->coord[p->n_coord].universe = c.fill;
// Set the position and direction.
for (int i = 0; i < 3; i++) {
@ -234,10 +231,10 @@ find_cell(Particle* p, int search_surf) {
// Set the lower coordinate level universe.
if (lat.are_valid_indices(i_xyz)) {
p->coord[p->n_coord].universe = lat[i_xyz] + 1;
p->coord[p->n_coord].universe = lat[i_xyz];
} else {
if (lat.outer != NO_OUTER_UNIVERSE) {
p->coord[p->n_coord].universe = lat.outer + 1;
p->coord[p->n_coord].universe = lat.outer;
} else {
std::stringstream err_msg;
err_msg << "Particle " << p->id << " is outside lattice "
@ -300,7 +297,7 @@ cross_lattice(Particle* p, int lattice_translation[3])
} else {
// Find cell in next lattice element.
p->coord[p->n_coord-1].universe = lat[i_xyz] + 1;
p->coord[p->n_coord-1].universe = lat[i_xyz];
bool found = find_cell(p, 0);
if (!found) {

View file

@ -62,8 +62,7 @@ adjust_indices()
for (Cell* c : global_cells) {
auto search = universe_map.find(c->universe);
if (search != universe_map.end()) {
//TODO: Remove this off-by-one indexing.
c->universe = search->second + 1;
c->universe = search->second;
} else {
std::stringstream err_msg;
err_msg << "Could not find universe " << c->universe

View file

@ -170,7 +170,7 @@ contains
! Perform some final operations to set up the geometry
call adjust_indices()
call count_cell_instances(root_universe-1)
call count_cell_instances(root_universe)
! After reading input and basic geometry setup is complete, build lists of
! neighboring cells for efficient tracking
@ -185,7 +185,7 @@ contains
! Check to make sure there are not too many nested coordinate levels in the
! geometry since the coordinate list is statically allocated for performance
! reasons
if (maximum_levels(root_universe - 1) > MAX_COORD) then
if (maximum_levels(root_universe) > MAX_COORD) then
call fatal_error("Too many nested coordinate levels in the geometry. &
&Try increasing the maximum number of coordinate levels by &
&providing the CMake -Dmaxcoord= option.")
@ -1146,7 +1146,7 @@ contains
if (.not. cells_in_univ_dict % has(univ_id)) then
n_universes = n_universes + 1
n_cells_in_univ = 1
call universe_dict % set(univ_id, n_universes)
call universe_dict % set(univ_id, n_universes - 1)
call univ_ids % push_back(univ_id)
else
n_cells_in_univ = 1 + cells_in_univ_dict % get(univ_id)
@ -1205,7 +1205,7 @@ contains
! SETUP UNIVERSES
! Allocate universes, universe cell arrays, and assign base universe
root_universe = find_root_universe() + 1
root_universe = find_root_universe()
! Clear dictionary
call cells_in_univ_dict%clear()

View file

@ -239,7 +239,7 @@ contains
! Print universe for this level
if (p % coord(i) % universe /= NONE) then
write(ou,*) ' Universe = ' &
// trim(to_str(universe_id(p % coord(i) % universe-1)))
// trim(to_str(universe_id(p % coord(i) % universe)))
end if
! Print information on lattice

View file

@ -157,9 +157,9 @@ contains
map = cells(i_cell) % distribcell_index()
path_len = distribcell_path_len(i_cell-1, map-1, target_offset, &
root_universe-1)
root_universe)
allocate(path_c(path_len))
call distribcell_path(i_cell-1, map-1, target_offset, root_universe-1, &
call distribcell_path(i_cell-1, map-1, target_offset, root_universe, &
path_c)
do i = 1, min(path_len, MAX_LINE_LEN)
if (path_c(i) == C_NULL_CHAR) exit

View file

@ -112,7 +112,7 @@ contains
integer, intent(in) :: bin
character(MAX_LINE_LEN) :: label
label = "Universe " // to_str(universe_id(this % universes(bin)-1))
label = "Universe " // to_str(universe_id(this % universes(bin)))
end function text_label_universe
end module tally_filter_universe

View file

@ -216,7 +216,7 @@ contains
elseif (this % domain_type == FILTER_UNIVERSE) then
do level = 1, p % n_coord
do i_domain = 1, size(this % domain_id)
if (universe_id(p % coord(level) % universe - 1) == &
if (universe_id(p % coord(level) % universe) == &
this % domain_id(i_domain)) then
i_material = p % material
call check_hit(i_domain, i_material, indices, hits, n_mat)