From b27242e726efd2f4d681824e31578f167690ea6a Mon Sep 17 00:00:00 2001 From: Sterling Harper Date: Tue, 2 Oct 2018 22:11:55 -0400 Subject: [PATCH] Add C++ CellFromFilter --- .../openmc/tallies/tally_filter_cellfrom.h | 27 +++++++++++++++++++ src/tallies/tally_filter.F90 | 20 +++++++------- src/tallies/tally_filter.cpp | 5 +++- src/tallies/tally_filter_cellfrom.F90 | 13 +-------- 4 files changed, 43 insertions(+), 22 deletions(-) create mode 100644 include/openmc/tallies/tally_filter_cellfrom.h diff --git a/include/openmc/tallies/tally_filter_cellfrom.h b/include/openmc/tallies/tally_filter_cellfrom.h new file mode 100644 index 0000000000..ad9d54a5f8 --- /dev/null +++ b/include/openmc/tallies/tally_filter_cellfrom.h @@ -0,0 +1,27 @@ +#ifndef OPENMC_TALLY_FILTER_CELLFROM_H +#define OPENMC_TALLY_FILTER_CELLFROM_H + +#include "openmc/tallies/tally_filter_cell.h" + + +namespace openmc { + +class CellFromFilter : public CellFilter +{ +public: + virtual void + get_all_bins(Particle* p, int estimator, TallyFilterMatch& match) const + { + for (int i = 0; i < p->last_n_coord; i++) { + auto search = map_.find(p->last_cell[i]); + if (search != map_.end()) { + // TODO: off-by-one + match.bins.push_back(search->second + 1); + match.weights.push_back(1); + } + } + } +}; + +} // namespace openmc +#endif // OPENMC_TALLY_FILTER_CELLFROM_H diff --git a/src/tallies/tally_filter.F90 b/src/tallies/tally_filter.F90 index caa088e5a9..6a699e2e6b 100644 --- a/src/tallies/tally_filter.F90 +++ b/src/tallies/tally_filter.F90 @@ -136,18 +136,10 @@ contains allocate(AzimuthalFilter :: filters(index) % obj) case ('cell') allocate(CellFilter :: filters(index) % obj) - select type(filt => filters(index) % obj) - type is (CellFilter) - filt % ptr = allocate_filter(type) - if (.not. c_associated(filt % ptr)) then - err = E_UNASSIGNED - call set_errmsg("Could not allocate C++ tally filter") - end if - end select case ('cellborn') allocate(CellbornFilter :: filters(index) % obj) case ('cellfrom') - allocate(CellfromFilter :: filters(index) % obj) + allocate(CellFromFilter :: filters(index) % obj) case ('delayedgroup') allocate(DelayedGroupFilter :: filters(index) % obj) case ('distribcell') @@ -188,6 +180,16 @@ contains err = E_UNASSIGNED call set_errmsg("Unknown filter type: " // trim(type_)) end select + + select type(filt => filters(index) % obj) + class is (CppTallyFilter) + filt % ptr = allocate_filter(type) + if (.not. c_associated(filt % ptr)) then + err = E_UNASSIGNED + call set_errmsg("Could not allocate C++ tally filter") + end if + end select + end if else err = E_OUT_OF_BOUNDS diff --git a/src/tallies/tally_filter.cpp b/src/tallies/tally_filter.cpp index e936e8d501..660178cbf6 100644 --- a/src/tallies/tally_filter.cpp +++ b/src/tallies/tally_filter.cpp @@ -3,6 +3,7 @@ #include #include "openmc/tallies/tally_filter_cell.h" +#include "openmc/tallies/tally_filter_cellfrom.h" namespace openmc { @@ -60,10 +61,12 @@ extern "C" { std::string type_ {type}; if (type_ == "cell") { tally_filters.push_back(new CellFilter()); - return tally_filters.back(); + } else if (type_ == "cellfrom") { + tally_filters.push_back(new CellFromFilter()); } else { return nullptr; } + return tally_filters.back(); } void filter_from_xml(TallyFilter* filt, pugi::xml_node* node) diff --git a/src/tallies/tally_filter_cellfrom.F90 b/src/tallies/tally_filter_cellfrom.F90 index e8048ecbe7..999a55bfd9 100644 --- a/src/tallies/tally_filter_cellfrom.F90 +++ b/src/tallies/tally_filter_cellfrom.F90 @@ -37,18 +37,7 @@ contains integer, intent(in) :: estimator type(TallyFilterMatch), intent(inout) :: match - integer :: i - integer :: val - - ! Starting one coordinate level deeper, find the next bin. - do i = 1, p % last_n_coord - val = this % map % get(p % last_cell(i) + 1) - if (val /= EMPTY) then - call match % bins_push_back(val) - call match % weights_push_back(ONE) - exit - end if - end do + call this % get_all_bins_c(p, estimator, match) end subroutine get_all_bins_cell_from