From 98b437924518e57c453aea8f8ad705d00e25633b Mon Sep 17 00:00:00 2001 From: Sterling Harper Date: Thu, 4 Oct 2018 22:43:54 -0400 Subject: [PATCH] Add C++ TallyFilter::to_statepoint() --- include/openmc/tallies/tally_filter.h | 3 +++ include/openmc/tallies/tally_filter_cell.h | 10 ++++++++++ include/openmc/tallies/tally_filter_cellfrom.h | 10 ++++++++++ src/tallies/tally_filter.cpp | 3 +++ src/tallies/tally_filter_cell.F90 | 11 +---------- src/tallies/tally_filter_cellfrom.F90 | 11 +---------- src/tallies/tally_filter_header.F90 | 14 ++++++++++++++ 7 files changed, 42 insertions(+), 20 deletions(-) diff --git a/include/openmc/tallies/tally_filter.h b/include/openmc/tallies/tally_filter.h index 89ede592c2..6988ff31ba 100644 --- a/include/openmc/tallies/tally_filter.h +++ b/include/openmc/tallies/tally_filter.h @@ -4,6 +4,7 @@ #include #include +#include "openmc/hdf5_interface.h" #include "openmc/particle.h" #include "openmc/xml_interface.h" @@ -48,6 +49,8 @@ public: virtual void get_all_bins(Particle* p, int estimator, TallyFilterMatch& match) const = 0; + virtual void to_statepoint(hid_t filter_group) const {} + virtual void initialize() {} }; diff --git a/include/openmc/tallies/tally_filter_cell.h b/include/openmc/tallies/tally_filter_cell.h index c70fcbe30b..85f4cd911b 100644 --- a/include/openmc/tallies/tally_filter_cell.h +++ b/include/openmc/tallies/tally_filter_cell.h @@ -55,6 +55,16 @@ public: } } + virtual void + to_statepoint(hid_t filter_group) const override + { + write_dataset(filter_group, "type", "cell"); + write_dataset(filter_group, "n_bins", cells_.size()); + std::vector cell_ids; + for (auto c : cells_) cell_ids.push_back(cells[c]->id_); + write_dataset(filter_group, "bins", cell_ids); + } + protected: std::vector cells_; std::unordered_map map_; diff --git a/include/openmc/tallies/tally_filter_cellfrom.h b/include/openmc/tallies/tally_filter_cellfrom.h index ed7518bfe4..8bcc9a5afe 100644 --- a/include/openmc/tallies/tally_filter_cellfrom.h +++ b/include/openmc/tallies/tally_filter_cellfrom.h @@ -22,6 +22,16 @@ public: } } } + + virtual void + to_statepoint(hid_t filter_group) const override + { + write_dataset(filter_group, "type", "cellfrom"); + write_dataset(filter_group, "n_bins", cells_.size()); + std::vector cell_ids; + for (auto c : cells_) cell_ids.push_back(cells[c]->id_); + write_dataset(filter_group, "bins", cell_ids); + } }; } // namespace openmc diff --git a/src/tallies/tally_filter.cpp b/src/tallies/tally_filter.cpp index 1dae39782c..8754d5880c 100644 --- a/src/tallies/tally_filter.cpp +++ b/src/tallies/tally_filter.cpp @@ -101,6 +101,9 @@ extern "C" { filt->get_all_bins(p, estimator, *match); } + void filter_to_statepoint(TallyFilter* filt, hid_t group) + {filt->to_statepoint(group);} + void filter_initialize(TallyFilter* filt) {filt->initialize();} } diff --git a/src/tallies/tally_filter_cell.F90 b/src/tallies/tally_filter_cell.F90 index 16d146df88..647ed38e68 100644 --- a/src/tallies/tally_filter_cell.F90 +++ b/src/tallies/tally_filter_cell.F90 @@ -64,17 +64,8 @@ contains class(CellFilter), intent(in) :: this integer(HID_T), intent(in) :: filter_group - integer :: i - integer, allocatable :: cell_ids(:) + call this % to_statepoint_c(filter_group) - call write_dataset(filter_group, "type", "cell") - call write_dataset(filter_group, "n_bins", this % n_bins) - - allocate(cell_ids(size(this % cells))) - do i = 1, size(this % cells) - cell_ids(i) = cells(this % cells(i)) % id() - end do - call write_dataset(filter_group, "bins", cell_ids) end subroutine to_statepoint_cell subroutine initialize_cell(this) diff --git a/src/tallies/tally_filter_cellfrom.F90 b/src/tallies/tally_filter_cellfrom.F90 index 999a55bfd9..ebc063ac04 100644 --- a/src/tallies/tally_filter_cellfrom.F90 +++ b/src/tallies/tally_filter_cellfrom.F90 @@ -45,17 +45,8 @@ contains class(CellFromFilter), intent(in) :: this integer(HID_T), intent(in) :: filter_group - integer :: i - integer, allocatable :: cell_ids(:) + call this % to_statepoint_c(filter_group) - call write_dataset(filter_group, "type", "cellfrom") - call write_dataset(filter_group, "n_bins", this % n_bins) - - allocate(cell_ids(size(this % cells))) - do i = 1, size(this % cells) - cell_ids(i) = cells(this % cells(i)) % id() - end do - call write_dataset(filter_group, "bins", cell_ids) end subroutine to_statepoint_cell_from function text_label_cell_from(this, bin) result(label) diff --git a/src/tallies/tally_filter_header.F90 b/src/tallies/tally_filter_header.F90 index 1d0688bb1e..713fc405f4 100644 --- a/src/tallies/tally_filter_header.F90 +++ b/src/tallies/tally_filter_header.F90 @@ -132,6 +132,7 @@ module tally_filter_header contains procedure :: from_xml_c procedure :: get_all_bins_c + procedure :: to_statepoint_c procedure :: initialize_c end type CppTallyFilter @@ -308,6 +309,19 @@ contains call filter_get_all_bins(this % ptr, p, estimator, match % ptr) end subroutine get_all_bins_c + subroutine to_statepoint_c(this, filter_group) + class(CppTallyFilter), intent(in) :: this + integer(HID_T), intent(in) :: filter_group + interface + subroutine filter_to_statepoint(filt, filter_group) bind(C) + import C_PTR, HID_T + type(C_PTR), value :: filt + integer(HID_T), intent(in), value :: filter_group + end subroutine filter_to_statepoint + end interface + call filter_to_statepoint(this % ptr, filter_group) + end subroutine to_statepoint_c + subroutine initialize_c(this) class(CppTallyFilter), intent(inout) :: this interface