diff --git a/openmc/capi/filter.py b/openmc/capi/filter.py index 0b85e026ea..05ec85d010 100644 --- a/openmc/capi/filter.py +++ b/openmc/capi/filter.py @@ -402,7 +402,7 @@ class _FilterMapping(Mapping): def __iter__(self): for i in range(len(self)): - yield _get_filter(i + 1).id + yield _get_filter(i).id def __len__(self): return _dll.tally_filters_size() diff --git a/openmc/capi/tally.py b/openmc/capi/tally.py index b8ce0bee58..eec3a2b66b 100644 --- a/openmc/capi/tally.py +++ b/openmc/capi/tally.py @@ -251,13 +251,13 @@ class Tally(_FortranObjectWithID): filt_idx = POINTER(c_int32)() n = c_int() _dll.openmc_tally_get_filters(self._index, filt_idx, n) - return [_get_filter(filt_idx[i]+1) for i in range(n.value)] + return [_get_filter(filt_idx[i]) for i in range(n.value)] @filters.setter def filters(self, filters): # Get filter indices as int32_t[] n = len(filters) - indices = (c_int32*n)(*(f._index-1 for f in filters)) + indices = (c_int32*n)(*(f._index for f in filters)) _dll.openmc_tally_set_filters(self._index, n, indices) diff --git a/src/tallies/filter.cpp b/src/tallies/filter.cpp index 0351fd4dc7..e9aae53a7a 100644 --- a/src/tallies/filter.cpp +++ b/src/tallies/filter.cpp @@ -114,7 +114,7 @@ extern "C" size_t tally_filters_size() int verify_filter(int32_t index) { - if (index < 1 || index > model::tally_filters.size()) { + if (index < 0 || index >= model::tally_filters.size()) { set_errmsg("Filter index is out of bounds."); return OPENMC_E_OUT_OF_BOUNDS; } @@ -126,8 +126,7 @@ openmc_filter_get_id(int32_t index, int32_t* id) { if (int err = verify_filter(index)) return err; - // TODO: off-by-one - *id = model::tally_filters[index-1]->id_; + *id = model::tally_filters[index]->id_; return 0; } @@ -141,9 +140,8 @@ openmc_filter_set_id(int32_t index, int32_t id) return OPENMC_E_INVALID_ID; } - // TODO: off-by-one - model::tally_filters[index-1]->id_ = id; - model::filter_map[id] = index - 1; + model::tally_filters[index]->id_ = id; + model::filter_map[id] = index; return 0; } @@ -152,8 +150,7 @@ openmc_filter_get_type(int32_t index, char* type) { if (int err = verify_filter(index)) return err; - // TODO: off-by-one - std::strcpy(type, model::tally_filters[index-1]->type().c_str()); + std::strcpy(type, model::tally_filters[index]->type().c_str()); return 0; } @@ -166,8 +163,7 @@ openmc_get_filter_index(int32_t id, int32_t* index) return OPENMC_E_INVALID_ID; } - // TODO: off-by-one - *index = it->second + 1; + *index = it->second; return 0; } @@ -184,9 +180,8 @@ openmc_get_filter_next_id(int32_t* id) extern "C" int openmc_new_filter(const char* type, int32_t* index) { - allocate_filter(type); - // TODO: off-by-one *index = model::tally_filters.size(); + allocate_filter(type); return 0; } diff --git a/src/tallies/filter_cell.cpp b/src/tallies/filter_cell.cpp index 80b6678a51..4e25e8541b 100644 --- a/src/tallies/filter_cell.cpp +++ b/src/tallies/filter_cell.cpp @@ -76,8 +76,7 @@ openmc_cell_filter_get_bins(int32_t index, int32_t** cells, int32_t* n) { if (int err = verify_filter(index)) return err; - // TODO: off-by-one - const auto& filt = model::tally_filters[index-1].get(); + const auto& filt = model::tally_filters[index].get(); if (filt->type() != "cell") { set_errmsg("Tried to get cells from a non-cell filter."); return OPENMC_E_INVALID_TYPE; diff --git a/src/tallies/filter_energy.cpp b/src/tallies/filter_energy.cpp index bd1de4b462..90cd7b3bfe 100644 --- a/src/tallies/filter_energy.cpp +++ b/src/tallies/filter_energy.cpp @@ -123,7 +123,7 @@ openmc_energy_filter_get_bins(int32_t index, double** energies, int32_t* n) if (int err = verify_filter(index)) return err; // Get a pointer to the filter and downcast. - const auto& filt_base = model::tally_filters[index-1].get(); + const auto& filt_base = model::tally_filters[index].get(); auto* filt = dynamic_cast(filt_base); // Check the filter type. @@ -145,7 +145,7 @@ openmc_energy_filter_set_bins(int32_t index, int32_t n, const double* energies) if (int err = verify_filter(index)) return err; // Get a pointer to the filter and downcast. - const auto& filt_base = model::tally_filters[index-1].get(); + const auto& filt_base = model::tally_filters[index].get(); auto* filt = dynamic_cast(filt_base); // Check the filter type. diff --git a/src/tallies/filter_legendre.cpp b/src/tallies/filter_legendre.cpp index 55f225b777..a5f583a158 100644 --- a/src/tallies/filter_legendre.cpp +++ b/src/tallies/filter_legendre.cpp @@ -52,7 +52,7 @@ openmc_legendre_filter_get_order(int32_t index, int* order) if (int err = verify_filter(index)) return err; // Get a pointer to the filter and downcast. - const auto& filt_base = model::tally_filters[index-1].get(); + const auto& filt_base = model::tally_filters[index].get(); auto* filt = dynamic_cast(filt_base); // Check the filter type. @@ -73,7 +73,7 @@ openmc_legendre_filter_set_order(int32_t index, int order) if (int err = verify_filter(index)) return err; // Get a pointer to the filter and downcast. - const auto& filt_base = model::tally_filters[index-1].get(); + const auto& filt_base = model::tally_filters[index].get(); auto* filt = dynamic_cast(filt_base); // Check the filter type. diff --git a/src/tallies/filter_material.cpp b/src/tallies/filter_material.cpp index 0dee964def..488f962fa7 100644 --- a/src/tallies/filter_material.cpp +++ b/src/tallies/filter_material.cpp @@ -77,7 +77,7 @@ openmc_material_filter_get_bins(int32_t index, int32_t** bins, int32_t* n) if (int err = verify_filter(index)) return err; // Get a pointer to the filter and downcast. - const auto& filt_base = model::tally_filters[index-1].get(); + const auto& filt_base = model::tally_filters[index].get(); auto* filt = dynamic_cast(filt_base); // Check the filter type. @@ -99,7 +99,7 @@ openmc_material_filter_set_bins(int32_t index, int32_t n, const int32_t* bins) if (int err = verify_filter(index)) return err; // Get a pointer to the filter and downcast. - const auto& filt_base = model::tally_filters[index-1].get(); + const auto& filt_base = model::tally_filters[index].get(); auto* filt = dynamic_cast(filt_base); // Check the filter type. diff --git a/src/tallies/filter_mesh.cpp b/src/tallies/filter_mesh.cpp index c17055a9e0..324e38cc7b 100644 --- a/src/tallies/filter_mesh.cpp +++ b/src/tallies/filter_mesh.cpp @@ -90,7 +90,7 @@ openmc_mesh_filter_get_mesh(int32_t index, int32_t* index_mesh) if (int err = verify_filter(index)) return err; // Get a pointer to the filter and downcast. - const auto& filt_base = model::tally_filters[index-1].get(); + const auto& filt_base = model::tally_filters[index].get(); auto* filt = dynamic_cast(filt_base); // Check the filter type. @@ -111,7 +111,7 @@ openmc_mesh_filter_set_mesh(int32_t index, int32_t index_mesh) if (int err = verify_filter(index)) return err; // Get a pointer to the filter and downcast. - const auto& filt_base = model::tally_filters[index-1].get(); + const auto& filt_base = model::tally_filters[index].get(); auto* filt = dynamic_cast(filt_base); // Check the filter type. diff --git a/src/tallies/filter_sph_harm.cpp b/src/tallies/filter_sph_harm.cpp index c772d13ac2..d75be0f9d9 100644 --- a/src/tallies/filter_sph_harm.cpp +++ b/src/tallies/filter_sph_harm.cpp @@ -100,7 +100,7 @@ check_sphharm_filter(int32_t index) } // Get a pointer to the filter and downcast. - const auto& filt_base = model::tally_filters[index-1].get(); + const auto& filt_base = model::tally_filters[index].get(); auto* filt = dynamic_cast(filt_base); // Check the filter type. diff --git a/src/tallies/filter_sptl_legendre.cpp b/src/tallies/filter_sptl_legendre.cpp index 7757d1f697..b5d75f4d24 100644 --- a/src/tallies/filter_sptl_legendre.cpp +++ b/src/tallies/filter_sptl_legendre.cpp @@ -107,7 +107,7 @@ check_sptl_legendre_filter(int32_t index) } // Get a pointer to the filter and downcast. - const auto& filt_base = model::tally_filters[index-1].get(); + const auto& filt_base = model::tally_filters[index].get(); auto* filt = dynamic_cast(filt_base); // Check the filter type. diff --git a/src/tallies/filter_zernike.cpp b/src/tallies/filter_zernike.cpp index 467c64d65c..3ea4492388 100644 --- a/src/tallies/filter_zernike.cpp +++ b/src/tallies/filter_zernike.cpp @@ -132,7 +132,7 @@ check_zernike_filter(int32_t index) } // Get a pointer to the filter and downcast. - const auto& filt_base = model::tally_filters[index-1].get(); + const auto& filt_base = model::tally_filters[index].get(); auto* filt = dynamic_cast(filt_base); // Check the filter type.