From 0084ae613b9ac6ddcdf098a76a1257fc35ee91e3 Mon Sep 17 00:00:00 2001 From: Sterling Harper Date: Wed, 19 Sep 2018 11:37:06 -0400 Subject: [PATCH] Move cell filter get_all_bins to C++ --- include/openmc/tallies/tally_filter.h | 5 +++++ include/openmc/tallies/tally_filter_cell.h | 19 ++++++++++++++++++- src/tallies/tally_filter.cpp | 7 +++++++ src/tallies/tally_filter_cell.F90 | 12 +----------- src/tallies/tally_filter_header.F90 | 18 ++++++++++++++++++ 5 files changed, 49 insertions(+), 12 deletions(-) diff --git a/include/openmc/tallies/tally_filter.h b/include/openmc/tallies/tally_filter.h index 190045ee8..d6cf72cd9 100644 --- a/include/openmc/tallies/tally_filter.h +++ b/include/openmc/tallies/tally_filter.h @@ -4,6 +4,7 @@ #include #include +#include "openmc/particle.h" #include "openmc/xml_interface.h" @@ -43,6 +44,10 @@ class TallyFilter { public: virtual void from_xml(pugi::xml_node node) = 0; + + virtual void + get_all_bins(Particle* p, int estimator, TallyFilterMatch& match) const = 0; + virtual void initialize() = 0; }; diff --git a/include/openmc/tallies/tally_filter_cell.h b/include/openmc/tallies/tally_filter_cell.h index f0a4bb430..21da79102 100644 --- a/include/openmc/tallies/tally_filter_cell.h +++ b/include/openmc/tallies/tally_filter_cell.h @@ -3,6 +3,7 @@ #include #include +#include #include #include "openmc/cell.h" @@ -35,11 +36,27 @@ public: } } - //TODO: mapping + for (int i = 0; i < cells_.size(); i++) { + map_[cells_[i]] = i; + } + } + + virtual void + get_all_bins(Particle* p, int estimator, TallyFilterMatch& match) const + { + for (int i = 0; i < p->n_coord; i++) { + auto search = map_.find(p->coord[i].cell); + if (search != map_.end()) { + // TODO: off-by-one + match.bins.push_back(search->second + 1); + match.weights.push_back(1); + } + } } protected: std::vector cells_; + std::unordered_map map_; }; } // namespace openmc diff --git a/src/tallies/tally_filter.cpp b/src/tallies/tally_filter.cpp index d869f6cc6..e936e8d50 100644 --- a/src/tallies/tally_filter.cpp +++ b/src/tallies/tally_filter.cpp @@ -69,6 +69,13 @@ extern "C" { void filter_from_xml(TallyFilter* filt, pugi::xml_node* node) {filt->from_xml(*node);} + void + filter_get_all_bins(TallyFilter* filt, Particle* p, int estimator, + TallyFilterMatch* match) + { + filt->get_all_bins(p, estimator, *match); + } + void filter_initialize(TallyFilter* filt) {filt->initialize();} } diff --git a/src/tallies/tally_filter_cell.F90 b/src/tallies/tally_filter_cell.F90 index 3f3706621..5bf594f2f 100644 --- a/src/tallies/tally_filter_cell.F90 +++ b/src/tallies/tally_filter_cell.F90 @@ -56,17 +56,7 @@ contains integer, intent(in) :: estimator type(TallyFilterMatch), intent(inout) :: match - integer :: i - integer :: val - - ! Iterate over coordinate levels to see with cells match - do i = 1, p % n_coord - val = this % map % get(p % coord(i) % cell + 1) - if (val /= EMPTY) then - call match % bins_push_back(val) - call match % weights_push_back(ONE) - end if - end do + call this % get_all_bins_c(p , estimator, match) end subroutine get_all_bins_cell diff --git a/src/tallies/tally_filter_header.F90 b/src/tallies/tally_filter_header.F90 index b1686235c..1d0688bb1 100644 --- a/src/tallies/tally_filter_header.F90 +++ b/src/tallies/tally_filter_header.F90 @@ -131,6 +131,7 @@ module tally_filter_header type(C_PTR) :: ptr contains procedure :: from_xml_c + procedure :: get_all_bins_c procedure :: initialize_c end type CppTallyFilter @@ -290,6 +291,23 @@ contains call filter_from_xml(this % ptr, node % ptr) end subroutine from_xml_c + subroutine get_all_bins_c(this, p, estimator, match) + class(CppTallyFilter), 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_c + subroutine initialize_c(this) class(CppTallyFilter), intent(inout) :: this interface