Use 0-based indexing for distribcell

This commit is contained in:
Sterling Harper 2018-08-27 19:31:42 -04:00
parent 0e348e338b
commit fe24b640af
3 changed files with 11 additions and 14 deletions

View file

@ -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];
}

View file

@ -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<int32_t> target_univ_ids;
for (Universe* u : universes) {
for (auto cell_indx : u->cells_) {

View file

@ -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