From 92f9c09a816501b1fa623781c206028fccda44a6 Mon Sep 17 00:00:00 2001 From: Sterling Harper Date: Fri, 24 Aug 2018 17:56:49 -0400 Subject: [PATCH] Use 0-based indexing for cells in LocalCoord --- src/api.F90 | 2 +- src/geometry.cpp | 12 +++++------- src/output.F90 | 4 ++-- src/particle.cpp | 6 +++--- src/plot.F90 | 6 +++--- src/tallies/tally_filter_cell.F90 | 2 +- src/tallies/tally_filter_cellborn.F90 | 2 +- src/tallies/tally_filter_cellfrom.F90 | 2 +- src/tallies/tally_filter_distribcell.F90 | 8 ++++---- src/tracking.F90 | 8 ++++---- src/volume_calc.F90 | 2 +- 11 files changed, 26 insertions(+), 28 deletions(-) diff --git a/src/api.F90 b/src/api.F90 index c8bea6583f..72acec064c 100644 --- a/src/api.F90 +++ b/src/api.F90 @@ -206,7 +206,7 @@ contains if (found) then if (rtype == 1) then - id = cells(p % coord(p % n_coord) % cell) % id() + id = cells(p % coord(p % n_coord) % cell + 1) % id() elseif (rtype == 2) then if (p % material == MATERIAL_VOID) then id = 0 diff --git a/src/geometry.cpp b/src/geometry.cpp index c7c9a4199a..9aac3f3143 100644 --- a/src/geometry.cpp +++ b/src/geometry.cpp @@ -34,11 +34,10 @@ check_cell_overlap(Particle* p) { Cell& c = *global_cells[index_cell]; if (c.contains(p->coord[j].xyz, p->coord[j].uvw, p->surface)) { - //TODO: off-by-one indexing - if (index_cell != p->coord[j].cell - 1) { + if (index_cell != p->coord[j].cell) { std::stringstream err_msg; err_msg << "Overlapping cells detected: " << c.id << ", " - << global_cells[p->coord[j].cell-1]->id << " on universe " + << global_cells[p->coord[j].cell]->id << " on universe " << univ.id; fatal_error(err_msg); } @@ -94,8 +93,7 @@ find_cell(Particle* p, int search_surf) { Direction u {p->coord[p->n_coord-1].uvw}; int32_t surf = p->surface; if (global_cells[i_cell]->contains(r, u, surf)) { - //TODO: off-by-one indexing - p->coord[p->n_coord-1].cell = i_cell + 1; + p->coord[p->n_coord-1].cell = i_cell; if (openmc_verbosity >= 10 || openmc_trace) { std::stringstream msg; @@ -119,7 +117,7 @@ find_cell(Particle* p, int search_surf) { int distribcell_index = c.distribcell_index - 1; int offset = 0; for (int i = 0; i < p->n_coord; i++) { - Cell& c_i {*global_cells[p->coord[i].cell-1]}; + Cell& c_i {*global_cells[p->coord[i].cell]}; if (c_i.type == FILL_UNIVERSE) { offset += c_i.offset[distribcell_index]; } else if (c_i.type == FILL_LATTICE) { @@ -334,7 +332,7 @@ distance_to_boundary(Particle* p, double* dist, int* surface_crossed, for (int i = 0; i < p->n_coord; i++) { Position r {p->coord[i].xyz}; Direction u {p->coord[i].uvw}; - Cell& c {*global_cells[p->coord[i].cell-1]}; + Cell& c {*global_cells[p->coord[i].cell]}; // Find the oncoming surface in this cell and the distance to it. auto surface_distance = c.distance(r, u, p->surface); diff --git a/src/output.F90 b/src/output.F90 index e45968ffc5..0f23c67bd8 100644 --- a/src/output.F90 +++ b/src/output.F90 @@ -231,8 +231,8 @@ contains write(ou,*) ' Level ' // trim(to_str(i - 1)) ! Print cell for this level - if (p % coord(i) % cell /= NONE) then - c => cells(p % coord(i) % cell) + if (p % coord(i) % cell /= C_NONE) then + c => cells(p % coord(i) % cell + 1) write(ou,*) ' Cell = ' // trim(to_str(c % id())) end if diff --git a/src/particle.cpp b/src/particle.cpp index e46d06c011..5dbfb2483c 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -19,8 +19,8 @@ namespace openmc { void LocalCoord::reset() { - cell = 0; - universe = 0; + cell = C_NONE; + universe = C_NONE; lattice = 0; lattice_x = 0; lattice_y = 0; @@ -67,7 +67,7 @@ Particle::initialize() // clear attributes surface = 0; - cell_born = 0; + cell_born = C_NONE; material = 0; last_material = 0; last_sqrtkT = 0; diff --git a/src/plot.F90 b/src/plot.F90 index 2fd898206c..517c27fa17 100644 --- a/src/plot.F90 +++ b/src/plot.F90 @@ -84,7 +84,7 @@ contains else if (pl % color_by == PLOT_COLOR_MATS) then ! Assign color based on material - associate (c => cells(p % coord(j) % cell)) + associate (c => cells(p % coord(j) % cell + 1)) if (c % type() == FILL_UNIVERSE) then ! If we stopped on a middle universe level, treat as if not found rgb = pl % not_found % rgb @@ -100,8 +100,8 @@ contains end associate else if (pl % color_by == PLOT_COLOR_CELLS) then ! Assign color based on cell - rgb = pl % colors(p % coord(j) % cell) % rgb - id = cells(p % coord(j) % cell) % id() + rgb = pl % colors(p % coord(j) % cell + 1) % rgb + id = cells(p % coord(j) % cell + 1) % id() else rgb = 0 id = -1 diff --git a/src/tallies/tally_filter_cell.F90 b/src/tallies/tally_filter_cell.F90 index be37467073..a394ed122b 100644 --- a/src/tallies/tally_filter_cell.F90 +++ b/src/tallies/tally_filter_cell.F90 @@ -59,7 +59,7 @@ contains ! Iterate over coordinate levels to see with cells match do i = 1, p % n_coord - val = this % map % get(p % coord(i) % cell) + val = this % map % get(p % coord(i) % cell + 1) if (val /= EMPTY) then call match % bins % push_back(val) call match % weights % push_back(ONE) diff --git a/src/tallies/tally_filter_cellborn.F90 b/src/tallies/tally_filter_cellborn.F90 index a373c2d4e1..37bf042020 100644 --- a/src/tallies/tally_filter_cellborn.F90 +++ b/src/tallies/tally_filter_cellborn.F90 @@ -55,7 +55,7 @@ contains integer :: val - val = this % map % get(p % cell_born) + val = this % map % get(p % cell_born + 1) if (val /= EMPTY) then call match % bins % push_back(val) call match % weights % push_back(ONE) diff --git a/src/tallies/tally_filter_cellfrom.F90 b/src/tallies/tally_filter_cellfrom.F90 index 83a3179d26..a99aa68832 100644 --- a/src/tallies/tally_filter_cellfrom.F90 +++ b/src/tallies/tally_filter_cellfrom.F90 @@ -42,7 +42,7 @@ contains ! Starting one coordinate level deeper, find the next bin. do i = 1, p % last_n_coord - val = this % map % get(p % last_cell(i)) + val = this % map % get(p % last_cell(i) + 1) if (val /= EMPTY) then call match % bins % push_back(val) call match % weights % push_back(ONE) diff --git a/src/tallies/tally_filter_distribcell.F90 b/src/tallies/tally_filter_distribcell.F90 index f59d155ea4..48b223a439 100644 --- a/src/tallies/tally_filter_distribcell.F90 +++ b/src/tallies/tally_filter_distribcell.F90 @@ -57,10 +57,10 @@ contains distribcell_index = cells(this % cell) % distribcell_index() offset = 0 do i = 1, p % n_coord - if (cells(p % coord(i) % cell) % type() == FILL_UNIVERSE) then - offset = offset + cells(p % coord(i) % cell) & + if (cells(p % coord(i) % cell + 1) % type() == FILL_UNIVERSE) then + offset = offset + cells(p % coord(i) % cell + 1) & % offset(distribcell_index-1) - elseif (cells(p % coord(i) % cell) % type() == FILL_LATTICE) then + elseif (cells(p % coord(i) % cell + 1) % type() == FILL_LATTICE) then if (lattices(p % coord(i + 1) % lattice) % obj & % are_valid_indices([& p % coord(i + 1) % lattice_x, & @@ -73,7 +73,7 @@ contains p % coord(i + 1) % lattice_z]) end if end if - if (this % cell == p % coord(i) % cell) then + if (this % cell == p % coord(i) % cell + 1) then call match % bins % push_back(offset + 1) call match % weights % push_back(ONE) return diff --git a/src/tracking.F90 b/src/tracking.F90 index e9568fe54a..d93ac9ab97 100644 --- a/src/tracking.F90 +++ b/src/tracking.F90 @@ -91,7 +91,7 @@ contains ! If the cell hasn't been determined based on the particle's location, ! initiate a search for the current cell. This generally happens at the ! beginning of the history and again for any secondary particles - if (p % coord(p % n_coord) % cell == NONE) then + if (p % coord(p % n_coord) % cell == C_NONE) then call find_cell(p, found_cell) if (.not. found_cell) then call particle_mark_as_lost(p, "Could not find the cell containing" & @@ -100,7 +100,7 @@ contains end if ! set birth cell attribute - if (p % cell_born == NONE) p % cell_born = p % coord(p % n_coord) % cell + if (p % cell_born == C_NONE) p % cell_born = p % coord(p % n_coord) % cell end if ! Write particle track. @@ -183,7 +183,7 @@ contains end do p % last_n_coord = p % n_coord - p % coord(p % n_coord) % cell = NONE + p % coord(p % n_coord) % cell = C_NONE if (any(lattice_translation /= 0)) then ! Particle crosses lattice boundary p % surface = ERROR_INT @@ -251,7 +251,7 @@ contains do j = 1, p % n_coord - 1 if (p % coord(j + 1) % rotated) then ! If next level is rotated, apply rotation matrix - p % coord(j + 1) % uvw = matmul(cells(p % coord(j) % cell) % & + p % coord(j + 1) % uvw = matmul(cells(p % coord(j) % cell + 1) % & rotation_matrix, p % coord(j) % uvw) else ! Otherwise, copy this level's direction diff --git a/src/volume_calc.F90 b/src/volume_calc.F90 index c291f1ff75..f7ded73611 100644 --- a/src/volume_calc.F90 +++ b/src/volume_calc.F90 @@ -205,7 +205,7 @@ contains elseif (this % domain_type == FILTER_CELL) THEN do level = 1, p % n_coord do i_domain = 1, size(this % domain_id) - if (cells(p % coord(level) % cell) % id() & + if (cells(p % coord(level) % cell + 1) % id() & == this % domain_id(i_domain)) then i_material = p % material call check_hit(i_domain, i_material, indices, hits, n_mat)