mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 14:15:42 -04:00
Use 0-based indexing for cells in LocalCoord
This commit is contained in:
parent
3be4e09e8e
commit
92f9c09a81
11 changed files with 26 additions and 28 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue