diff --git a/src/output.cpp b/src/output.cpp index 2a7a1c6a66..efc4ba5196 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -355,7 +355,8 @@ write_tallies() const auto& filt {*model::tally_filters[i_filt]}; auto& match {simulation::filter_matches[i_filt]}; tallies_out << std::string(indent+1, ' ') - << filt.text_label(match.i_bin_) << "\n"; + // TODO: off-by-one + << filt.text_label(match.i_bin_+1) << "\n"; } indent += 2; } diff --git a/src/simulation.F90 b/src/simulation.F90 index 3de296f9db..54cd9e6d51 100644 --- a/src/simulation.F90 +++ b/src/simulation.F90 @@ -4,7 +4,6 @@ module simulation use nuclide_header, only: micro_xs, n_nuclides use photon_header, only: micro_photon_xs, n_elements - use tally_filter_header, only: filter_matches, n_filters, filter_match_pointer implicit none private @@ -23,12 +22,6 @@ contains ! Allocate array for microscopic cross section cache allocate(micro_xs(n_nuclides)) allocate(micro_photon_xs(n_elements)) - - ! Allocate array for matching filter bins - allocate(filter_matches(n_filters)) - do i = 1, n_filters - filter_matches(i) % ptr = filter_match_pointer(i - 1) - end do !$omp end parallel end subroutine @@ -39,12 +32,10 @@ contains !=============================================================================== subroutine simulation_finalize_f() bind(C) - ! Free up simulation-specific memory !$omp parallel - deallocate(micro_xs, micro_photon_xs, filter_matches) + deallocate(micro_xs, micro_photon_xs) !$omp end parallel - end subroutine end module simulation diff --git a/src/tallies/filter.cpp b/src/tallies/filter.cpp index f331e63123..3733ebbf2e 100644 --- a/src/tallies/filter.cpp +++ b/src/tallies/filter.cpp @@ -50,22 +50,6 @@ std::vector> tally_filters; extern "C" { // filter_match_point moved to simulation.cpp - int - filter_match_get_i_bin(FilterMatch* match) - {return match->i_bin_;} - - int - filter_match_bins_data(FilterMatch* match, int indx) - {return match->bins_[indx-1];} - - double - filter_match_weights_data(FilterMatch* match, int indx) - {return match->weights_[indx-1];} - - void - filter_match_bins_set_data(FilterMatch* match, int indx, int val) - {match->bins_[indx-1] = val;} - Filter* allocate_filter(const char* type) { diff --git a/src/tallies/tally_filter_header.F90 b/src/tallies/tally_filter_header.F90 index 2c7daac3ba..65a223bef2 100644 --- a/src/tallies/tally_filter_header.F90 +++ b/src/tallies/tally_filter_header.F90 @@ -19,28 +19,6 @@ module tally_filter_header public :: openmc_filter_set_id public :: openmc_get_filter_index public :: openmc_get_filter_next_id - public :: filter_match_pointer - - interface - function filter_match_pointer(indx) bind(C) result(ptr) - import C_PTR, C_INT - integer(C_INT), intent(in), value :: indx - type(C_PTR) :: ptr - end function filter_match_pointer - end interface - -!=============================================================================== -! TALLYFILTERMATCH stores every valid bin and weight for a filter -!=============================================================================== - - type, public :: TallyFilterMatch - type(C_PTR) :: ptr - contains - procedure :: i_bin - procedure :: bins_data - procedure :: weights_data - procedure :: bins_set_data - end type TallyFilterMatch !=============================================================================== ! TALLYFILTER describes a filter that limits what events score to a tally. For @@ -54,9 +32,7 @@ module tally_filter_header type(C_PTR) :: ptr contains procedure :: from_xml - procedure :: get_all_bins procedure :: to_statepoint - procedure :: text_label procedure :: initialize procedure :: n_bins_cpp procedure :: from_xml_cpp @@ -138,8 +114,6 @@ module tally_filter_header integer(C_INT32_T), public, bind(C) :: n_filters = 0 ! # of filters type(TallyFilterContainer), public, allocatable, target :: filters(:) - type(TallyFilterMatch), public, allocatable :: filter_matches(:) -!$omp threadprivate(filter_matches) ! Dictionary that maps user IDs to indices in 'filters' type(DictIntInt), public :: filter_dict @@ -150,68 +124,6 @@ module tally_filter_header contains -!=============================================================================== -! TallyFilterMatch implementation -!=============================================================================== - - function i_bin(this) result(i) - class(TallyFilterMatch) :: this - integer :: i - interface - function filter_match_get_i_bin(ptr) result(i) bind(C) - import C_PTR, C_INT - type(C_PTR), value :: ptr - integer(C_INT) :: i - end function - end interface - i = filter_match_get_i_bin(this % ptr) - end function - - function bins_data(this, indx) result(val) - class(TallyFilterMatch), intent(inout) :: this - integer, intent(in) :: indx - integer :: val - interface - function filter_match_bins_data(ptr, indx) bind(C) result(val) - import C_PTR, C_INT - type(C_PTR), value :: ptr - integer(C_INT), intent(in), value :: indx - integer(C_INT) :: val - end function - end interface - val = filter_match_bins_data(this % ptr, indx) - end function bins_data - - function weights_data(this, indx) result(val) - class(TallyFilterMatch), intent(inout) :: this - integer, intent(in) :: indx - real(8) :: val - interface - function filter_match_weights_data(ptr, indx) bind(C) result(val) - import C_PTR, C_INT, C_DOUBLE - type(C_PTR), value :: ptr - integer(C_INT), intent(in), value :: indx - real(C_DOUBLE) :: val - end function - end interface - val = filter_match_weights_data(this % ptr, indx) - end function weights_data - - subroutine bins_set_data(this, indx, val) - class(TallyFilterMatch), intent(inout) :: this - integer, intent(in) :: indx - integer, intent(in) :: val - interface - subroutine filter_match_bins_set_data(ptr, indx, val) bind(C) - import C_PTR, C_INT - type(C_PTR), value :: ptr - integer(C_INT), value, intent(in) :: indx - integer(C_INT), value, intent(in) :: val - end subroutine - end interface - call filter_match_bins_set_data(this % ptr, indx, val) - end subroutine bins_set_data - !=============================================================================== ! TallyFilter implementation !=============================================================================== @@ -223,23 +135,6 @@ contains this % n_bins = this % n_bins_cpp() end subroutine from_xml - subroutine get_all_bins(this, p, estimator, match) - class(TallyFilter), intent(in) :: this - type(Particle), intent(in) :: p - integer, intent(in) :: estimator - type(TallyFilterMatch), intent(inout) :: match - interface - subroutine filter_get_all_bins(filt, p, estimator, match) bind(C) - import C_PTR, Particle, C_INT - type(C_PTR), value :: filt - type(Particle), intent(in) :: p - integer(C_INT), intent(in), value :: estimator - type(C_PTR), value :: match - end subroutine filter_get_all_bins - end interface - call filter_get_all_bins(this % ptr, p, estimator, match % ptr) - end subroutine get_all_bins - subroutine to_statepoint(this, filter_group) class(TallyFilter), intent(in) :: this integer(HID_T), intent(in) :: filter_group @@ -253,28 +148,6 @@ contains call filter_to_statepoint(this % ptr, filter_group) end subroutine to_statepoint - function text_label(this, bin) result(label) - class(TallyFilter), intent(in) :: this - integer, intent(in) :: bin - character(MAX_LINE_LEN) :: label - character(kind=C_CHAR) :: label_(MAX_LINE_LEN+1) - integer :: i - interface - subroutine filter_text_label(filt, bin, label) bind(C) - import C_PTR, C_INT, C_CHAR - type(C_PTR), value :: filt - integer(C_INT), value :: bin - character(kind=C_CHAR) :: label(*) - end subroutine filter_text_label - end interface - call filter_text_label(this % ptr, bin, label_) - label = " " - do i = 1, MAX_LINE_LEN - if (label_(i) == C_NULL_CHAR) exit - label(i:i) = label_(i) - end do - end function text_label - subroutine initialize(this) class(TallyFilter), intent(inout) :: this call this % initialize_cpp() diff --git a/src/tallies/tally_scoring.cpp b/src/tallies/tally_scoring.cpp index 770ab78681..77bfcd2738 100644 --- a/src/tallies/tally_scoring.cpp +++ b/src/tallies/tally_scoring.cpp @@ -45,7 +45,7 @@ FilterBinIter::FilterBinIter(const Tally& tally, Particle* p) } // Set the index of the bin used in the first filter combination - match.i_bin_ = 1; + match.i_bin_ = 0; } // Compute the initial index and weight. @@ -79,7 +79,7 @@ FilterBinIter::FilterBinIter(const Tally& tally, bool end) return; } - match.i_bin_ = 1; + match.i_bin_ = 0; } // Compute the initial index and weight. @@ -96,7 +96,7 @@ FilterBinIter::operator++() for (int i = tally_.filters().size()-1; i >= 0; --i) { auto i_filt = tally_.filters(i); auto& match {simulation::filter_matches[i_filt]}; - if (match.i_bin_< match.bins_.size()) { + if (match.i_bin_ < match.bins_.size()-1) { // The bin for this filter can be incremented. Increment it and do not // touch any of the remaining filters. ++match.i_bin_; @@ -105,7 +105,7 @@ FilterBinIter::operator++() } else { // This bin cannot be incremented so reset it and continue to the next // filter. - match.i_bin_ = 1; + match.i_bin_ = 0; } } @@ -131,8 +131,8 @@ FilterBinIter::compute_index_weight() 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); - weight_ *= match.weights_[i_bin-1]; + index_ += (match.bins_[i_bin] - 1) * tally_.strides(i); + weight_ *= match.weights_[i_bin]; } } @@ -150,8 +150,8 @@ score_fission_delayed_dg(int i_tally, int d_bin, double score, int score_index) auto i_filt = tally.filters(tally.delayedgroup_filter_); auto& dg_match {simulation::filter_matches[i_filt]}; auto i_bin = dg_match.i_bin_; - auto original_bin = dg_match.bins_[i_bin-1]; - dg_match.bins_[i_bin-1] = d_bin; + auto original_bin = dg_match.bins_[i_bin]; + dg_match.bins_[i_bin] = d_bin; // Determine the filter scoring index auto filter_index = 1; @@ -160,7 +160,7 @@ score_fission_delayed_dg(int i_tally, int d_bin, double score, int score_index) auto& match {simulation::filter_matches[i_filt]}; auto i_bin = match.i_bin_; //TODO: off-by-one - filter_index += (match.bins_[i_bin-1] - 1) * tally.strides(i); + filter_index += (match.bins_[i_bin] - 1) * tally.strides(i); } // Update the tally result @@ -170,7 +170,7 @@ score_fission_delayed_dg(int i_tally, int d_bin, double score, int score_index) results(filter_index-1, score_index, RESULT_VALUE) += score; // Reset the original delayed group bin - dg_match.bins_[i_bin-1] = original_bin; + dg_match.bins_[i_bin] = original_bin; } //! Helper function for nu-fission tallies with energyout filters. @@ -185,7 +185,7 @@ score_fission_eout(Particle* p, int i_tally, int i_score, int score_bin) auto results = tally_results(i_tally); auto i_eout_filt = tally.filters()[tally.energyout_filter_]; auto i_bin = simulation::filter_matches[i_eout_filt].i_bin_; - auto bin_energyout = simulation::filter_matches[i_eout_filt].bins_[i_bin-1]; + auto bin_energyout = simulation::filter_matches[i_eout_filt].bins_[i_bin]; const EnergyoutFilter& eo_filt {*dynamic_cast(model::tally_filters[i_eout_filt].get())}; @@ -222,7 +222,7 @@ score_fission_eout(Particle* p, int i_tally, int i_score, int score_bin) g_out = eo_filt.n_bins_ - g_out + 1; // change outgoing energy bin - simulation::filter_matches[i_eout_filt].bins_[i_bin-1] = g_out; + simulation::filter_matches[i_eout_filt].bins_[i_bin] = g_out; } else { @@ -240,7 +240,7 @@ score_fission_eout(Particle* p, int i_tally, int i_score, int score_bin) //TODO: off-by-one auto i_match = lower_bound_index(eo_filt.bins_.begin(), eo_filt.bins_.end(), E_out) + 1; - simulation::filter_matches[i_eout_filt].bins_[i_bin-1] = i_match; + simulation::filter_matches[i_eout_filt].bins_[i_bin] = i_match; } } @@ -256,7 +256,7 @@ score_fission_eout(Particle* p, int i_tally, int i_score, int score_bin) auto i_filt = tally.filters(j); auto& match {simulation::filter_matches[i_filt]}; auto i_bin = match.i_bin_; - filter_index += (match.bins_[i_bin-1] - 1) * tally.strides(j); + filter_index += (match.bins_[i_bin] - 1) * tally.strides(j); } // Update tally results @@ -284,8 +284,8 @@ score_fission_eout(Particle* p, int i_tally, int i_score, int score_bin) auto i_filt = tally.filters(j); auto& match {simulation::filter_matches[i_filt]}; auto i_bin = match.i_bin_; - filter_index += (match.bins_[i_bin-1] - 1) * tally.strides(j); - filter_weight *= match.weights_[i_bin-1]; + filter_index += (match.bins_[i_bin] - 1) * tally.strides(j); + filter_weight *= match.weights_[i_bin]; } score_fission_delayed_dg(i_tally, d_bin+1, score*filter_weight, @@ -303,8 +303,8 @@ score_fission_eout(Particle* p, int i_tally, int i_score, int score_bin) auto i_filt = tally.filters(j); auto& match {simulation::filter_matches[i_filt]}; auto i_bin = match.i_bin_; - filter_index += (match.bins_[i_bin-1] - 1) * tally.strides(j); - filter_weight *= match.weights_[i_bin-1]; + filter_index += (match.bins_[i_bin] - 1) * tally.strides(j); + filter_weight *= match.weights_[i_bin]; } // Update tally results @@ -315,7 +315,7 @@ score_fission_eout(Particle* p, int i_tally, int i_score, int score_bin) } // Reset outgoing energy bin and score index - simulation::filter_matches[i_eout_filt].bins_[i_bin-1] = bin_energyout; + simulation::filter_matches[i_eout_filt].bins_[i_bin] = bin_energyout; } //! Update tally results for continuous-energy tallies with any estimator.