diff --git a/include/openmc/hdf5_interface.h b/include/openmc/hdf5_interface.h index fa64605513..d3cc558bae 100644 --- a/include/openmc/hdf5_interface.h +++ b/include/openmc/hdf5_interface.h @@ -375,5 +375,11 @@ write_dataset(hid_t obj_id, const char* name, Position r) write_dataset(obj_id, name, buffer); } +inline void +write_dataset(hid_t obj_id, const char* name, std::string buffer) +{ + write_string(obj_id, name, buffer.c_str(), false); +} + } // namespace openmc #endif // OPENMC_HDF5_INTERFACE_H diff --git a/include/openmc/tallies/tally_filter.h b/include/openmc/tallies/tally_filter.h index e50e70fd10..73b8eda64e 100644 --- a/include/openmc/tallies/tally_filter.h +++ b/include/openmc/tallies/tally_filter.h @@ -32,10 +32,10 @@ extern std::vector tally_filters; class TallyFilterMatch { public: - int i_bin; + //int i_bin; std::vector bins; std::vector weights; - bool bins_present; + //bool bins_present; }; //============================================================================== @@ -45,6 +45,8 @@ public: class TallyFilter { public: + virtual std::string type() const = 0; + virtual ~TallyFilter() = 0; virtual void from_xml(pugi::xml_node node) = 0; @@ -52,7 +54,12 @@ 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 + to_statepoint(hid_t filter_group) const + { + write_dataset(filter_group, "type", type()); + write_dataset(filter_group, "n_bins", n_bins_); + } virtual std::string text_label(int bin) const = 0; diff --git a/include/openmc/tallies/tally_filter_cell.h b/include/openmc/tallies/tally_filter_cell.h index 972fafddb4..cdf9a00cf5 100644 --- a/include/openmc/tallies/tally_filter_cell.h +++ b/include/openmc/tallies/tally_filter_cell.h @@ -16,6 +16,8 @@ namespace openmc { class CellFilter : public TallyFilter { public: + virtual std::string type() const override {return "cell";} + virtual ~CellFilter() override = default; virtual void @@ -61,8 +63,7 @@ public: virtual void to_statepoint(hid_t filter_group) const override { - write_dataset(filter_group, "type", "cell"); - write_dataset(filter_group, "n_bins", n_bins_); + TallyFilter::to_statepoint(filter_group); std::vector cell_ids; for (auto c : cells_) cell_ids.push_back(cells[c]->id_); write_dataset(filter_group, "bins", cell_ids); diff --git a/include/openmc/tallies/tally_filter_cellborn.h b/include/openmc/tallies/tally_filter_cellborn.h index 814b4d6b9f..92e8721e77 100644 --- a/include/openmc/tallies/tally_filter_cellborn.h +++ b/include/openmc/tallies/tally_filter_cellborn.h @@ -8,6 +8,8 @@ namespace openmc { class CellbornFilter : public CellFilter { public: + virtual std::string type() const override {return "cellborn";} + virtual void get_all_bins(Particle* p, int estimator, TallyFilterMatch& match) const override @@ -20,16 +22,6 @@ public: } } - virtual void - to_statepoint(hid_t filter_group) const override - { - write_dataset(filter_group, "type", "cellborn"); - write_dataset(filter_group, "n_bins", n_bins_); - std::vector cell_ids; - 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 { diff --git a/include/openmc/tallies/tally_filter_cellfrom.h b/include/openmc/tallies/tally_filter_cellfrom.h index a0eca932ac..1b7e8f6db8 100644 --- a/include/openmc/tallies/tally_filter_cellfrom.h +++ b/include/openmc/tallies/tally_filter_cellfrom.h @@ -9,6 +9,8 @@ namespace openmc { class CellFromFilter : public CellFilter { public: + virtual std::string type() const override {return "cellfrom";} + virtual void get_all_bins(Particle* p, int estimator, TallyFilterMatch& match) const override @@ -23,16 +25,6 @@ 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); - } - virtual std::string text_label(int bin) const override { diff --git a/include/openmc/tallies/tally_filter_distribcell.h b/include/openmc/tallies/tally_filter_distribcell.h index b29520caa7..97a016bc46 100644 --- a/include/openmc/tallies/tally_filter_distribcell.h +++ b/include/openmc/tallies/tally_filter_distribcell.h @@ -15,6 +15,8 @@ namespace openmc { class DistribcellFilter : public TallyFilter { public: + virtual std::string type() const override {return "distribcell";} + virtual ~DistribcellFilter() override = default; virtual void @@ -72,8 +74,7 @@ public: virtual void to_statepoint(hid_t filter_group) const override { - write_dataset(filter_group, "type", "distribcell"); - write_dataset(filter_group, "n_bins", n_bins_); + TallyFilter::to_statepoint(filter_group); write_dataset(filter_group, "bins", cells[cell_]->id_); } diff --git a/include/openmc/tallies/tally_filter_mesh.h b/include/openmc/tallies/tally_filter_mesh.h index 01ffbae6f1..0fba1ca0cc 100644 --- a/include/openmc/tallies/tally_filter_mesh.h +++ b/include/openmc/tallies/tally_filter_mesh.h @@ -15,14 +15,18 @@ namespace openmc { class MeshFilter : public TallyFilter { public: + virtual std::string type() const override {return "mesh";} + virtual ~MeshFilter() override = default; virtual void from_xml(pugi::xml_node node) override { auto bins_ = get_node_array(node, "bins"); - if (bins_.size() != 1) - fatal_error("Only one mesh can be specified per mesh filter."); + if (bins_.size() != 1) { + fatal_error("Only one mesh can be specified per " + type() + + " mesh filter."); + } auto id = bins_[0]; auto search = mesh_map.find(id); @@ -56,8 +60,7 @@ public: virtual void to_statepoint(hid_t filter_group) const override { - write_dataset(filter_group, "type", "mesh"); - write_dataset(filter_group, "n_bins", n_bins_); + TallyFilter::to_statepoint(filter_group); write_dataset(filter_group, "bins", meshes[mesh_]->id_); } diff --git a/include/openmc/tallies/tally_filter_meshsurface.h b/include/openmc/tallies/tally_filter_meshsurface.h index 7b374b0a64..99a748481d 100644 --- a/include/openmc/tallies/tally_filter_meshsurface.h +++ b/include/openmc/tallies/tally_filter_meshsurface.h @@ -7,33 +7,20 @@ #include "openmc/constants.h" #include "openmc/error.h" #include "openmc/mesh.h" -#include "openmc/tallies/tally_filter.h" +#include "openmc/tallies/tally_filter_mesh.h" namespace openmc { -class MeshSurfaceFilter : public TallyFilter +class MeshSurfaceFilter : public MeshFilter { public: - virtual ~MeshSurfaceFilter() override = default; + virtual std::string type() const override {return "meshsurface";} virtual void from_xml(pugi::xml_node node) override { - auto bins_ = get_node_array(node, "bins"); - if (bins_.size() != 1) - fatal_error("Only one mesh can be specified per mesh filter."); - - auto id = bins_[0]; - auto search = mesh_map.find(id); - if (search != mesh_map.end()) { - mesh_ = search->second; - } else{ - std::stringstream err_msg; - err_msg << "Could not find cell " << id << " specified on tally filter."; - fatal_error(err_msg); - } - + MeshFilter::from_xml(node); n_bins_ = 4 * meshes[mesh_]->n_dimension_;; for (auto dim : meshes[mesh_]->shape_) n_bins_ *= dim; } @@ -46,14 +33,6 @@ public: for (auto b : match.bins) match.weights.push_back(1.0); } - virtual void - to_statepoint(hid_t filter_group) const override - { - write_dataset(filter_group, "type", "meshsurface"); - write_dataset(filter_group, "n_bins", n_bins_); - write_dataset(filter_group, "bins", meshes[mesh_]->id_); - } - virtual std::string text_label(int bin) const override { @@ -65,45 +44,37 @@ public: int i_surf = ((bin - 1) % (4 * n_dim)) + 1; // Get mesh index part of label. - int ijk[n_dim]; - mesh.get_indices_from_bin(i_mesh, ijk); - std::stringstream out; - out << "Mesh Index (" << ijk[0]; - if (n_dim > 1) out << ", " << ijk[1]; - if (n_dim > 2) out << ", " << ijk[2]; - out << ")"; + std::string out = MeshFilter::text_label(i_mesh); // Get surface part of label. if (i_surf == OUT_LEFT) { - out << " Outgoing, x-min"; + out += " Outgoing, x-min"; } else if (i_surf == IN_LEFT) { - out << " Incoming, x-min"; + out += " Incoming, x-min"; } else if (i_surf == OUT_RIGHT) { - out << " Outgoing, x-max"; + out += " Outgoing, x-max"; } else if (i_surf == IN_RIGHT) { - out << " Incoming, x-max"; + out += " Incoming, x-max"; } else if (i_surf == OUT_BACK) { - out << " Outgoing, y-min"; + out += " Outgoing, y-min"; } else if (i_surf == IN_BACK) { - out << " Incoming, y-min"; + out += " Incoming, y-min"; } else if (i_surf == OUT_FRONT) { - out << " Outgoing, y-max"; + out += " Outgoing, y-max"; } else if (i_surf == IN_FRONT) { - out << " Incoming, y-max"; + out += " Incoming, y-max"; } else if (i_surf == OUT_BOTTOM) { - out << " Outgoing, z-min"; + out += " Outgoing, z-min"; } else if (i_surf == IN_BOTTOM) { - out << " Incoming, z-min"; + out += " Incoming, z-min"; } else if (i_surf == OUT_TOP) { - out << " Outgoing, z-max"; + out += " Outgoing, z-max"; } else if (i_surf == IN_TOP) { - out << " Incoming, z-max"; + out += " Incoming, z-max"; } - return out.str(); + return out; } - - int32_t mesh_; }; } // namespace openmc diff --git a/src/geometry_aux.cpp b/src/geometry_aux.cpp index 1da7bd78b7..ee19497880 100644 --- a/src/geometry_aux.cpp +++ b/src/geometry_aux.cpp @@ -188,9 +188,8 @@ prepare_distribcell() // Find all cells listed in a DistribcellFilter. std::unordered_set distribcells; for (auto* filt : tally_filters) { - //TODO: replace this cast - auto* distrib_filt = dynamic_cast(filt); - if (distrib_filt) { + if (filt->type() == "distribcell") { + auto* distrib_filt = static_cast(filt); distribcells.insert(distrib_filt->cell_); } }