mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 06:05:58 -04:00
Use 0-based indices for filters
This commit is contained in:
parent
392fbd7b98
commit
eeaa38c2ab
11 changed files with 22 additions and 28 deletions
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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<EnergyFilter*>(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<EnergyFilter*>(filt_base);
|
||||
|
||||
// Check the filter type.
|
||||
|
|
|
|||
|
|
@ -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<LegendreFilter*>(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<LegendreFilter*>(filt_base);
|
||||
|
||||
// Check the filter type.
|
||||
|
|
|
|||
|
|
@ -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<MaterialFilter*>(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<MaterialFilter*>(filt_base);
|
||||
|
||||
// Check the filter type.
|
||||
|
|
|
|||
|
|
@ -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<MeshFilter*>(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<MeshFilter*>(filt_base);
|
||||
|
||||
// Check the filter type.
|
||||
|
|
|
|||
|
|
@ -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<SphericalHarmonicsFilter*>(filt_base);
|
||||
|
||||
// Check the filter type.
|
||||
|
|
|
|||
|
|
@ -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<SpatialLegendreFilter*>(filt_base);
|
||||
|
||||
// Check the filter type.
|
||||
|
|
|
|||
|
|
@ -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<ZernikeFilter*>(filt_base);
|
||||
|
||||
// Check the filter type.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue