mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-27 05:35:49 -04:00
Use 0-based indexing for Tally.filters_ values
This commit is contained in:
parent
53a0dc8d97
commit
3377241f4d
6 changed files with 45 additions and 55 deletions
|
|
@ -254,13 +254,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]) for i in range(n.value)]
|
||||
return [_get_filter(filt_idx[i]+1) 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 for f in filters))
|
||||
indices = (c_int32*n)(*(f._index-1 for f in filters))
|
||||
|
||||
_dll.openmc_tally_set_filters(self._index, n, indices)
|
||||
|
||||
|
|
|
|||
|
|
@ -679,7 +679,7 @@ contains
|
|||
end if
|
||||
|
||||
! Store the index of the filter
|
||||
temp_filter(j) = i_filt
|
||||
temp_filter(j) = i_filt - 1
|
||||
end do
|
||||
|
||||
! Set the filters
|
||||
|
|
@ -691,7 +691,7 @@ contains
|
|||
has_energyout = (t % energyout_filter() > 0)
|
||||
particle_filter_index = 0
|
||||
do j = 1, t % n_filters()
|
||||
select type (filt => filters(t % filter(j)) % obj)
|
||||
select type (filt => filters(t % filter(j) + 1) % obj)
|
||||
type is (ParticleFilter)
|
||||
particle_filter_index = j
|
||||
end select
|
||||
|
|
@ -699,7 +699,7 @@ contains
|
|||
|
||||
! Change the tally estimator if a filter demands it
|
||||
do j = 1, t % n_filters()
|
||||
select type (filt => filters(t % filter(j)) % obj)
|
||||
select type (filt => filters(t % filter(j) + 1) % obj)
|
||||
type is (EnergyoutFilter)
|
||||
call t % set_estimator(ESTIMATOR_ANALOG)
|
||||
type is (LegendreFilter)
|
||||
|
|
|
|||
|
|
@ -559,7 +559,7 @@ contains
|
|||
|
||||
! Initialize bins, filter level, and indentation
|
||||
do h = 1, t % n_filters()
|
||||
filter_bins(t % filter(h)) = 0
|
||||
filter_bins(t % filter(h) + 1) = 0
|
||||
end do
|
||||
j = 1
|
||||
indent = 0
|
||||
|
|
@ -570,17 +570,17 @@ contains
|
|||
if (t % n_filters() == 0) exit find_bin
|
||||
|
||||
! Increment bin combination
|
||||
filter_bins(t % filter(j)) = filter_bins(t % filter(j)) + 1
|
||||
filter_bins(t % filter(j) + 1) = filter_bins(t % filter(j) + 1) + 1
|
||||
|
||||
! =================================================================
|
||||
! REACHED END OF BINS FOR THIS FILTER, MOVE TO NEXT FILTER
|
||||
|
||||
if (filter_bins(t % filter(j)) > &
|
||||
filters(t % filter(j)) % obj % n_bins) then
|
||||
if (filter_bins(t % filter(j) + 1) > &
|
||||
filters(t % filter(j) + 1) % obj % n_bins) then
|
||||
! If this is the first filter, then exit
|
||||
if (j == 1) exit print_bin
|
||||
|
||||
filter_bins(t % filter(j)) = 0
|
||||
filter_bins(t % filter(j) + 1) = 0
|
||||
j = j - 1
|
||||
indent = indent - 2
|
||||
|
||||
|
|
@ -592,7 +592,7 @@ contains
|
|||
if (j == t % n_filters()) exit find_bin
|
||||
|
||||
! Print current filter information
|
||||
i_filt = t % filter(j)
|
||||
i_filt = t % filter(j) + 1
|
||||
write(UNIT=unit_tally, FMT='(1X,2A)') repeat(" ", indent), &
|
||||
trim(filters(i_filt) % obj % &
|
||||
text_label(filter_bins(i_filt)))
|
||||
|
|
@ -604,7 +604,7 @@ contains
|
|||
|
||||
! Print filter information
|
||||
if (t % n_filters() > 0) then
|
||||
i_filt = t % filter(j)
|
||||
i_filt = t % filter(j) + 1
|
||||
write(UNIT=unit_tally, FMT='(1X,2A)') repeat(" ", indent), &
|
||||
trim(filters(i_filt) % obj % &
|
||||
text_label(filter_bins(i_filt)))
|
||||
|
|
@ -617,7 +617,7 @@ contains
|
|||
filter_index = 1
|
||||
do h = 1, t % n_filters()
|
||||
filter_index = filter_index &
|
||||
+ (max(filter_bins(t % filter(h)) ,1) - 1) * t % stride(h)
|
||||
+ (max(filter_bins(t % filter(h)+1) ,1) - 1) * t % stride(h)
|
||||
end do
|
||||
|
||||
! Write results for this filter bin combination
|
||||
|
|
|
|||
|
|
@ -270,7 +270,7 @@ contains
|
|||
! Write IDs of filters
|
||||
allocate(id_array(tally % n_filters()))
|
||||
do j = 1, tally % n_filters()
|
||||
id_array(j) = filters(tally % filter(j)) % obj % id
|
||||
id_array(j) = filters(tally % filter(j) + 1) % obj % id
|
||||
end do
|
||||
call write_dataset(tally_group, "filters", id_array)
|
||||
deallocate(id_array)
|
||||
|
|
|
|||
|
|
@ -467,7 +467,7 @@ contains
|
|||
|
||||
! Check if the delayed group filter is present
|
||||
if (dg_filter > 0) then
|
||||
select type(filt => filters(t % filter(dg_filter)) % obj)
|
||||
select type(filt => filters(t % filter(dg_filter) + 1) % obj)
|
||||
type is (DelayedGroupFilter)
|
||||
|
||||
! Loop over all delayed group bins and tally to them
|
||||
|
|
@ -512,7 +512,7 @@ contains
|
|||
|
||||
! Check if the delayed group filter is present
|
||||
if (dg_filter > 0) then
|
||||
select type(filt => filters(t % filter(dg_filter)) % obj)
|
||||
select type(filt => filters(t % filter(dg_filter) + 1) % obj)
|
||||
type is (DelayedGroupFilter)
|
||||
|
||||
! Loop over all delayed group bins and tally to them
|
||||
|
|
@ -544,7 +544,7 @@ contains
|
|||
|
||||
! Check if the delayed group filter is present
|
||||
if (dg_filter > 0) then
|
||||
select type(filt => filters(t % filter(dg_filter)) % obj)
|
||||
select type(filt => filters(t % filter(dg_filter) + 1) % obj)
|
||||
type is (DelayedGroupFilter)
|
||||
|
||||
! Loop over all delayed group bins and tally to them
|
||||
|
|
@ -577,7 +577,7 @@ contains
|
|||
|
||||
! Check if the delayed group filter is present
|
||||
if (dg_filter > 0) then
|
||||
select type(filt => filters(t % filter(dg_filter)) % obj)
|
||||
select type(filt => filters(t % filter(dg_filter) + 1) % obj)
|
||||
type is (DelayedGroupFilter)
|
||||
|
||||
! Loop over all nuclides in the current material
|
||||
|
|
@ -650,7 +650,7 @@ contains
|
|||
|
||||
! Check if the delayed group filter is present
|
||||
if (dg_filter > 0) then
|
||||
select type(filt => filters(t % filter(dg_filter)) % obj)
|
||||
select type(filt => filters(t % filter(dg_filter) + 1) % obj)
|
||||
type is (DelayedGroupFilter)
|
||||
|
||||
! Loop over all delayed group bins and tally to them
|
||||
|
|
@ -745,7 +745,7 @@ contains
|
|||
if (dg_filter > 0) then
|
||||
|
||||
! declare the delayed group filter type
|
||||
select type(filt => filters(t % filter(dg_filter)) % obj)
|
||||
select type(filt => filters(t % filter(dg_filter) + 1) % obj)
|
||||
type is (DelayedGroupFilter)
|
||||
|
||||
! loop over delayed group bins until the corresponding bin
|
||||
|
|
@ -775,7 +775,7 @@ contains
|
|||
|
||||
! Check if the delayed group filter is present
|
||||
if (dg_filter > 0) then
|
||||
select type(filt => filters(t % filter(dg_filter)) % obj)
|
||||
select type(filt => filters(t % filter(dg_filter) + 1) % obj)
|
||||
type is (DelayedGroupFilter)
|
||||
|
||||
! Loop over all delayed group bins and tally to them
|
||||
|
|
@ -829,7 +829,7 @@ contains
|
|||
|
||||
! Check if the delayed group filter is present
|
||||
if (dg_filter > 0) then
|
||||
select type(filt => filters(t % filter(dg_filter)) % obj)
|
||||
select type(filt => filters(t % filter(dg_filter) + 1) % obj)
|
||||
type is (DelayedGroupFilter)
|
||||
|
||||
! Loop over all nuclides in the current material
|
||||
|
|
@ -1677,7 +1677,7 @@ contains
|
|||
if (get_macro_xs_c(p % material, MG_GET_XS_ABSORPTION, p_g) > ZERO) then
|
||||
|
||||
if (dg_filter > 0) then
|
||||
select type(filt => filters(t % filter(dg_filter)) % obj)
|
||||
select type(filt => filters(t % filter(dg_filter) + 1) % obj)
|
||||
type is (DelayedGroupFilter)
|
||||
|
||||
! Loop over all delayed group bins and tally to them
|
||||
|
|
@ -1726,7 +1726,7 @@ contains
|
|||
|
||||
! Check if the delayed group filter is present
|
||||
if (dg_filter > 0) then
|
||||
select type(filt => filters(t % filter(dg_filter)) % obj)
|
||||
select type(filt => filters(t % filter(dg_filter) + 1) % obj)
|
||||
type is (DelayedGroupFilter)
|
||||
|
||||
! Loop over all delayed group bins and tally to them
|
||||
|
|
@ -1762,7 +1762,7 @@ contains
|
|||
|
||||
! Check if the delayed group filter is present
|
||||
if (dg_filter > 0) then
|
||||
select type(filt => filters(t % filter(dg_filter)) % obj)
|
||||
select type(filt => filters(t % filter(dg_filter) + 1) % obj)
|
||||
type is (DelayedGroupFilter)
|
||||
|
||||
! Loop over all delayed group bins and tally to them
|
||||
|
|
@ -1809,7 +1809,7 @@ contains
|
|||
if (get_macro_xs_c(p % material, MG_GET_XS_ABSORPTION, p_g) > ZERO) then
|
||||
|
||||
if (dg_filter > 0) then
|
||||
select type(filt => filters(t % filter(dg_filter)) % obj)
|
||||
select type(filt => filters(t % filter(dg_filter) + 1) % obj)
|
||||
type is (DelayedGroupFilter)
|
||||
|
||||
! Loop over all delayed group bins and tally to them
|
||||
|
|
@ -1897,7 +1897,7 @@ contains
|
|||
if (dg_filter > 0) then
|
||||
|
||||
! declare the delayed group filter type
|
||||
select type(filt => filters(t % filter(dg_filter)) % obj)
|
||||
select type(filt => filters(t % filter(dg_filter) + 1) % obj)
|
||||
type is (DelayedGroupFilter)
|
||||
|
||||
! loop over delayed group bins until the corresponding bin
|
||||
|
|
@ -1930,7 +1930,7 @@ contains
|
|||
|
||||
! Check if the delayed group filter is present
|
||||
if (dg_filter > 0) then
|
||||
select type(filt => filters(t % filter(dg_filter)) % obj)
|
||||
select type(filt => filters(t % filter(dg_filter) + 1) % obj)
|
||||
type is (DelayedGroupFilter)
|
||||
|
||||
! Loop over all delayed group bins and tally to them
|
||||
|
|
@ -2109,7 +2109,7 @@ contains
|
|||
integer :: g_out ! energy group of fission bank site
|
||||
|
||||
! save original outgoing energy bin and score index
|
||||
i = t % filter(t % energyout_filter())
|
||||
i = t % filter(t % energyout_filter()) + 1
|
||||
i_bin = filter_matches(i) % i_bin()
|
||||
bin_energyout = filter_matches(i) % bins_data(i_bin)
|
||||
|
||||
|
|
@ -2174,8 +2174,8 @@ contains
|
|||
! determine scoring index and weight for this filter combination
|
||||
i_filter = 1
|
||||
do l = 1, t % n_filters()
|
||||
i_filter = i_filter + (filter_matches(t % filter(l)) &
|
||||
% bins_data(filter_matches(t % filter(l)) % i_bin()) - 1) * &
|
||||
i_filter = i_filter + (filter_matches(t % filter(l) + 1) &
|
||||
% bins_data(filter_matches(t % filter(l) + 1) % i_bin()) - 1) * &
|
||||
t % stride(l)
|
||||
end do
|
||||
|
||||
|
|
@ -2195,7 +2195,7 @@ contains
|
|||
if (j > 0) then
|
||||
|
||||
! declare the delayed group filter type
|
||||
select type(dg_filt => filters(t % filter(j)) % obj)
|
||||
select type(dg_filt => filters(t % filter(j) + 1) % obj)
|
||||
type is (DelayedGroupFilter)
|
||||
|
||||
! loop over delayed group bins until the corresponding bin is
|
||||
|
|
@ -2214,7 +2214,7 @@ contains
|
|||
! determine scoring index and weight for this filter
|
||||
! combination
|
||||
do l = 1, t % n_filters()
|
||||
f = t % filter(l)
|
||||
f = t % filter(l) + 1
|
||||
b = filter_matches(f) % i_bin()
|
||||
i_filter = i_filter + (filter_matches(f) &
|
||||
% bins_data(b) - 1) * t % stride(l)
|
||||
|
|
@ -2237,7 +2237,7 @@ contains
|
|||
|
||||
! determine scoring index and weight for this filter combination
|
||||
do l = 1, t % n_filters()
|
||||
f = t % filter(l)
|
||||
f = t % filter(l) + 1
|
||||
b = filter_matches(f) % i_bin()
|
||||
i_filter = i_filter + (filter_matches(f) % bins_data(b) - 1) &
|
||||
* t % stride(l)
|
||||
|
|
@ -2278,7 +2278,7 @@ contains
|
|||
integer :: filter_index ! index for matching filter bin combination
|
||||
|
||||
! save original delayed group bin
|
||||
i_filt = t % filter(t % delayedgroup_filter())
|
||||
i_filt = t % filter(t % delayedgroup_filter()) + 1
|
||||
i_bin = filter_matches(i_filt) % i_bin()
|
||||
bin_original = filter_matches(i_filt) % bins_data(i_bin)
|
||||
call filter_matches(i_filt) % bins_set_data(i_bin, d_bin)
|
||||
|
|
@ -2286,8 +2286,8 @@ contains
|
|||
! determine scoring index and weight on the modified matching bins
|
||||
filter_index = 1
|
||||
do i = 1, t % n_filters()
|
||||
filter_index = filter_index + (filter_matches(t % filter(i)) % &
|
||||
bins_data(filter_matches(t % filter(i)) % i_bin()) - 1) * t % stride(i)
|
||||
filter_index = filter_index + (filter_matches(t % filter(i) + 1) % &
|
||||
bins_data(filter_matches(t % filter(i) + 1) % i_bin()) - 1) * t % stride(i)
|
||||
end do
|
||||
|
||||
!$omp atomic
|
||||
|
|
|
|||
|
|
@ -91,14 +91,11 @@ public:
|
|||
// Find all valid bins in each relevant filter if they have not already been
|
||||
// found for this event.
|
||||
for (auto i_filt : tally_.filters()) {
|
||||
//TODO: off-by-one
|
||||
auto& match {simulation::filter_matches[i_filt-1]};
|
||||
auto& match {simulation::filter_matches[i_filt]};
|
||||
if (!match.bins_present_) {
|
||||
match.bins_.clear();
|
||||
match.weights_.clear();
|
||||
//TODO: off-by-one
|
||||
model::tally_filters[i_filt-1]
|
||||
->get_all_bins(p, tally_.estimator_, match);
|
||||
model::tally_filters[i_filt]->get_all_bins(p, tally_.estimator_, match);
|
||||
match.bins_present_ = true;
|
||||
}
|
||||
|
||||
|
|
@ -138,8 +135,7 @@ public:
|
|||
bool done_looping = true;
|
||||
for (int i = tally_.filters().size()-1; i >= 0; --i) {
|
||||
auto i_filt = tally_.filters(i);
|
||||
//TODO: off-by-one
|
||||
auto& match {simulation::filter_matches[i_filt-1]};
|
||||
auto& match {simulation::filter_matches[i_filt]};
|
||||
if (match.i_bin_< match.bins_.size()) {
|
||||
// The bin for this filter can be incremented. Increment it and do not
|
||||
// touch any of the remaining filters.
|
||||
|
|
@ -176,8 +172,7 @@ private:
|
|||
weight_ = 1.;
|
||||
for (auto i = 0; i < tally_.filters().size(); ++i) {
|
||||
auto i_filt = tally_.filters(i);
|
||||
//TODO: off-by-one
|
||||
auto& match {simulation::filter_matches[i_filt-1]};
|
||||
auto& match {simulation::filter_matches[i_filt]};
|
||||
auto i_bin = match.i_bin_;
|
||||
//TODO: off-by-one
|
||||
index_ += (match.bins_[i_bin-1] - 1) * tally_.strides(i);
|
||||
|
|
@ -360,14 +355,11 @@ Tally::set_filters(const int32_t filter_indices[], int n)
|
|||
|
||||
for (int i = 0; i < n; ++i) {
|
||||
auto i_filt = filters_[i];
|
||||
//TODO: off-by-one
|
||||
if (i_filt < 1 || i_filt > model::tally_filters.size())
|
||||
if (i_filt < 0 || i_filt >= model::tally_filters.size())
|
||||
throw std::out_of_range("Index in tally filter array out of bounds.");
|
||||
|
||||
//TODO: off-by-one
|
||||
const auto* filt = model::tally_filters[i_filt-1].get();
|
||||
|
||||
//TODO: off-by-one on each index
|
||||
const auto* filt = model::tally_filters[i_filt].get();
|
||||
if (dynamic_cast<const EnergyoutFilter*>(filt)) {
|
||||
energyout_filter_ = i + 1;
|
||||
} else if (dynamic_cast<const DelayedGroupFilter*>(filt)) {
|
||||
|
|
@ -382,8 +374,7 @@ Tally::set_filters(const int32_t filter_indices[], int n)
|
|||
int stride = 1;
|
||||
for (int i = n-1; i >= 0; --i) {
|
||||
strides_[i] = stride;
|
||||
//TODO: off-by-one
|
||||
stride *= model::tally_filters[filters_[i]-1]->n_bins_;
|
||||
stride *= model::tally_filters[filters_[i]]->n_bins_;
|
||||
}
|
||||
n_filter_bins_ = stride;
|
||||
}
|
||||
|
|
@ -415,8 +406,7 @@ Tally::set_scores(std::vector<std::string> scores)
|
|||
bool surface_present = false;
|
||||
bool meshsurface_present = false;
|
||||
for (auto i_filt : filters_) {
|
||||
//TODO: off-by-one
|
||||
const auto* filt {model::tally_filters[i_filt-1].get()};
|
||||
const auto* filt {model::tally_filters[i_filt].get()};
|
||||
if (dynamic_cast<const LegendreFilter*>(filt)) {
|
||||
legendre_present = true;
|
||||
} else if (dynamic_cast<const CellFromFilter*>(filt)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue