diff --git a/include/openmc/constants.h b/include/openmc/constants.h index 9c96258fb5..042dd96684 100644 --- a/include/openmc/constants.h +++ b/include/openmc/constants.h @@ -62,6 +62,7 @@ constexpr int MAX_SAMPLE {100000}; // Maximum number of words in a single line, length of line, and length of // single word +constexpr int MAX_LINE_LEN {250}; constexpr int MAX_WORD_LEN {150}; // Maximum number of external source spatial resamples to encounter before an diff --git a/include/openmc/tallies/tally_filter.h b/include/openmc/tallies/tally_filter.h index b4d8a6e8d2..4713338d95 100644 --- a/include/openmc/tallies/tally_filter.h +++ b/include/openmc/tallies/tally_filter.h @@ -2,6 +2,7 @@ #define OPENMC_TALLY_FILTER_H #include +#include #include #include "openmc/hdf5_interface.h" @@ -53,6 +54,8 @@ public: virtual void to_statepoint(hid_t filter_group) const {} + virtual std::string text_label(int bin) const = 0; + virtual void initialize() {} }; diff --git a/include/openmc/tallies/tally_filter_cell.h b/include/openmc/tallies/tally_filter_cell.h index 8504a769b9..0d56752c7f 100644 --- a/include/openmc/tallies/tally_filter_cell.h +++ b/include/openmc/tallies/tally_filter_cell.h @@ -67,6 +67,12 @@ public: write_dataset(filter_group, "bins", cell_ids); } + virtual std::string + text_label(int bin) const override + { + return "Cell " + std::to_string(cells[cells_[bin-1]]->id_); + } + 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 8bcc9a5afe..a0eca932ac 100644 --- a/include/openmc/tallies/tally_filter_cellfrom.h +++ b/include/openmc/tallies/tally_filter_cellfrom.h @@ -32,6 +32,12 @@ public: for (auto c : cells_) cell_ids.push_back(cells[c]->id_); write_dataset(filter_group, "bins", cell_ids); } + + virtual std::string + text_label(int bin) const override + { + return "Cell from " + std::to_string(cells[cells_[bin-1]]->id_); + } }; } // namespace openmc diff --git a/include/openmc/tallies/tally_filter_mesh.h b/include/openmc/tallies/tally_filter_mesh.h index 632c123a65..3c13a7f245 100644 --- a/include/openmc/tallies/tally_filter_mesh.h +++ b/include/openmc/tallies/tally_filter_mesh.h @@ -49,6 +49,8 @@ public: } } + virtual std::string text_label(int bin) const {}; + protected: int32_t mesh_; }; diff --git a/include/openmc/tallies/tally_filter_meshsurface.h b/include/openmc/tallies/tally_filter_meshsurface.h index 0b638d7071..14eede2c7b 100644 --- a/include/openmc/tallies/tally_filter_meshsurface.h +++ b/include/openmc/tallies/tally_filter_meshsurface.h @@ -42,6 +42,8 @@ public: for (auto b : match.bins) match.weights.push_back(1.0); } + virtual std::string text_label(int bin) const {}; + protected: int32_t mesh_; }; diff --git a/src/tallies/tally_filter.cpp b/src/tallies/tally_filter.cpp index 8754d5880c..d2d10ceb34 100644 --- a/src/tallies/tally_filter.cpp +++ b/src/tallies/tally_filter.cpp @@ -2,6 +2,7 @@ #include +#include "openmc/constants.h" // for MAX_LINE_LEN; #include "openmc/tallies/tally_filter_cell.h" #include "openmc/tallies/tally_filter_cellfrom.h" #include "openmc/tallies/tally_filter_mesh.h" @@ -104,6 +105,15 @@ extern "C" { void filter_to_statepoint(TallyFilter* filt, hid_t group) {filt->to_statepoint(group);} + void filter_text_label(TallyFilter* filt, int bin, char* label) + { + std::string label_str = filt->text_label(bin); + int i = 0; + for (; i < label_str.size() && i < MAX_LINE_LEN; i++) + label[i] = label_str[i]; + label[i] = '\0'; + } + void filter_initialize(TallyFilter* filt) {filt->initialize();} } diff --git a/src/tallies/tally_filter_cell.F90 b/src/tallies/tally_filter_cell.F90 index 647ed38e68..984385a5b9 100644 --- a/src/tallies/tally_filter_cell.F90 +++ b/src/tallies/tally_filter_cell.F90 @@ -99,7 +99,7 @@ contains integer, intent(in) :: bin character(MAX_LINE_LEN) :: label - label = "Cell " // to_str(cells(this % cells(bin)) % id()) + label = this % text_label_c(bin) end function text_label_cell !=============================================================================== diff --git a/src/tallies/tally_filter_cellfrom.F90 b/src/tallies/tally_filter_cellfrom.F90 index ebc063ac04..94be061f7b 100644 --- a/src/tallies/tally_filter_cellfrom.F90 +++ b/src/tallies/tally_filter_cellfrom.F90 @@ -54,7 +54,7 @@ contains integer, intent(in) :: bin character(MAX_LINE_LEN) :: label - label = "Cell from " // to_str(cells(this % cells(bin)) % id()) + label = this % text_label_c(bin) end function text_label_cell_from end module tally_filter_cellfrom diff --git a/src/tallies/tally_filter_header.F90 b/src/tallies/tally_filter_header.F90 index 713fc405f4..63a6360761 100644 --- a/src/tallies/tally_filter_header.F90 +++ b/src/tallies/tally_filter_header.F90 @@ -133,6 +133,7 @@ module tally_filter_header procedure :: from_xml_c procedure :: get_all_bins_c procedure :: to_statepoint_c + procedure :: text_label_c procedure :: initialize_c end type CppTallyFilter @@ -322,6 +323,28 @@ contains call filter_to_statepoint(this % ptr, filter_group) end subroutine to_statepoint_c + function text_label_c(this, bin) result(label) + class(CppTallyFilter), 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_c + subroutine initialize_c(this) class(CppTallyFilter), intent(inout) :: this interface