From 06fbf3fe014a1296dbc69ae8f8950fb945594039 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Sat, 5 Nov 2022 21:14:59 -0500 Subject: [PATCH] Switch to use of FilterType enum for comparisons --- include/openmc/tallies/filter.h | 18 ++++++++++-------- include/openmc/tallies/filter_azimuthal.h | 3 ++- include/openmc/tallies/filter_cell.h | 3 ++- include/openmc/tallies/filter_cell_instance.h | 3 ++- include/openmc/tallies/filter_cellborn.h | 3 ++- include/openmc/tallies/filter_cellfrom.h | 3 ++- include/openmc/tallies/filter_collision.h | 3 ++- include/openmc/tallies/filter_delayedgroup.h | 3 ++- include/openmc/tallies/filter_distribcell.h | 3 ++- include/openmc/tallies/filter_energy.h | 6 ++++-- include/openmc/tallies/filter_energyfunc.h | 3 ++- include/openmc/tallies/filter_legendre.h | 3 ++- include/openmc/tallies/filter_material.h | 3 ++- include/openmc/tallies/filter_mesh.h | 3 ++- include/openmc/tallies/filter_meshsurface.h | 3 ++- include/openmc/tallies/filter_mu.h | 3 ++- include/openmc/tallies/filter_particle.h | 3 ++- include/openmc/tallies/filter_polar.h | 3 ++- include/openmc/tallies/filter_sph_harm.h | 3 ++- include/openmc/tallies/filter_sptl_legendre.h | 3 ++- include/openmc/tallies/filter_surface.h | 3 ++- include/openmc/tallies/filter_time.h | 3 ++- include/openmc/tallies/filter_universe.h | 3 ++- include/openmc/tallies/filter_zernike.h | 6 ++++-- src/state_point.cpp | 2 +- src/tallies/filter.cpp | 2 +- src/tallies/filter_cell.cpp | 2 +- src/tallies/filter_mesh.cpp | 8 +++++--- src/tallies/tally.cpp | 12 +++++++----- 29 files changed, 75 insertions(+), 44 deletions(-) diff --git a/include/openmc/tallies/filter.h b/include/openmc/tallies/filter.h index 810ff371d..104a55e47 100644 --- a/include/openmc/tallies/filter.h +++ b/include/openmc/tallies/filter.h @@ -24,24 +24,25 @@ enum class FilterType { CELL, CELL_INSTANCE, COLLISION, - DELAYEDGROUP, + DELAYED_GROUP, DISTRIBCELL, - ENERGYFUNC, + ENERGY_FUNCTION, ENERGY, + ENERGY_OUT, LEGENDRE, - MATCH, MATERIAL, MESH, - MESHSURFACE, + MESH_SURFACE, MU, PARTICLE, POLAR, - SPH_HARM, - SPTL_LEGENDRE, + SPHERICAL_HARMONICS, + SPATIAL_LEGENDRE, SURFACE, TIME, UNIVERSE, ZERNIKE, + ZERNIKE_RADIAL }; //============================================================================== @@ -85,7 +86,8 @@ public: //---------------------------------------------------------------------------- // Methods - virtual std::string type() const = 0; + virtual std::string type_str() const = 0; + virtual FilterType type() const = 0; //! Matches a tally event to a set of filter bins and weights. //! @@ -99,7 +101,7 @@ public: //! Writes data describing this filter to an HDF5 statepoint group. virtual void to_statepoint(hid_t filter_group) const { - write_dataset(filter_group, "type", type()); + write_dataset(filter_group, "type", type_str()); write_dataset(filter_group, "n_bins", n_bins_); } diff --git a/include/openmc/tallies/filter_azimuthal.h b/include/openmc/tallies/filter_azimuthal.h index 2272b500a..37e1ef073 100644 --- a/include/openmc/tallies/filter_azimuthal.h +++ b/include/openmc/tallies/filter_azimuthal.h @@ -24,7 +24,8 @@ public: //---------------------------------------------------------------------------- // Methods - std::string type() const override { return "azimuthal"; } + std::string type_str() const override { return "azimuthal"; } + FilterType type() const override { return FilterType::AZIMUTHAL; } void from_xml(pugi::xml_node node) override; diff --git a/include/openmc/tallies/filter_cell.h b/include/openmc/tallies/filter_cell.h index 46d89811d..b7ea01ce6 100644 --- a/include/openmc/tallies/filter_cell.h +++ b/include/openmc/tallies/filter_cell.h @@ -25,7 +25,8 @@ public: //---------------------------------------------------------------------------- // Methods - std::string type() const override { return "cell"; } + std::string type_str() const override { return "cell"; } + FilterType type() const override { return FilterType::CELL; } void from_xml(pugi::xml_node node) override; diff --git a/include/openmc/tallies/filter_cell_instance.h b/include/openmc/tallies/filter_cell_instance.h index 4de3fcd29..f500f4889 100644 --- a/include/openmc/tallies/filter_cell_instance.h +++ b/include/openmc/tallies/filter_cell_instance.h @@ -28,7 +28,8 @@ public: //---------------------------------------------------------------------------- // Methods - std::string type() const override { return "cellinstance"; } + std::string type_str() const override { return "cellinstance"; } + FilterType type() const override { return FilterType::CELL_INSTANCE; } void from_xml(pugi::xml_node node) override; diff --git a/include/openmc/tallies/filter_cellborn.h b/include/openmc/tallies/filter_cellborn.h index 282854020..17102d971 100644 --- a/include/openmc/tallies/filter_cellborn.h +++ b/include/openmc/tallies/filter_cellborn.h @@ -16,7 +16,8 @@ public: //---------------------------------------------------------------------------- // Methods - std::string type() const override { return "cellborn"; } + std::string type_str() const override { return "cellborn"; } + FilterType type() const override { return FilterType::CELLBORN; } void get_all_bins(const Particle& p, TallyEstimator estimator, FilterMatch& match) const override; diff --git a/include/openmc/tallies/filter_cellfrom.h b/include/openmc/tallies/filter_cellfrom.h index 47abd0353..61ff50b05 100644 --- a/include/openmc/tallies/filter_cellfrom.h +++ b/include/openmc/tallies/filter_cellfrom.h @@ -16,7 +16,8 @@ public: //---------------------------------------------------------------------------- // Methods - std::string type() const override { return "cellfrom"; } + std::string type_str() const override { return "cellfrom"; } + FilterType type() const override { return FilterType::CELLFROM; } void get_all_bins(const Particle& p, TallyEstimator estimator, FilterMatch& match) const override; diff --git a/include/openmc/tallies/filter_collision.h b/include/openmc/tallies/filter_collision.h index 3724b06cf..d2dab70ca 100644 --- a/include/openmc/tallies/filter_collision.h +++ b/include/openmc/tallies/filter_collision.h @@ -23,7 +23,8 @@ public: //---------------------------------------------------------------------------- // Methods - std::string type() const override { return "collision"; } + std::string type_str() const override { return "collision"; } + FilterType type() const override { return FilterType::COLLISION; } void from_xml(pugi::xml_node node) override; diff --git a/include/openmc/tallies/filter_delayedgroup.h b/include/openmc/tallies/filter_delayedgroup.h index 72ffa1db5..71919b2ec 100644 --- a/include/openmc/tallies/filter_delayedgroup.h +++ b/include/openmc/tallies/filter_delayedgroup.h @@ -25,7 +25,8 @@ public: //---------------------------------------------------------------------------- // Methods - std::string type() const override { return "delayedgroup"; } + std::string type_str() const override { return "delayedgroup"; } + FilterType type() const override { return FilterType::DELAYED_GROUP; } void from_xml(pugi::xml_node node) override; diff --git a/include/openmc/tallies/filter_distribcell.h b/include/openmc/tallies/filter_distribcell.h index d72ae022f..b5cdcce84 100644 --- a/include/openmc/tallies/filter_distribcell.h +++ b/include/openmc/tallies/filter_distribcell.h @@ -21,7 +21,8 @@ public: //---------------------------------------------------------------------------- // Methods - std::string type() const override { return "distribcell"; } + std::string type_str() const override { return "distribcell"; } + FilterType type() const override { return FilterType::DISTRIBCELL; } void from_xml(pugi::xml_node node) override; diff --git a/include/openmc/tallies/filter_energy.h b/include/openmc/tallies/filter_energy.h index 000aaa28b..e35e01a6d 100644 --- a/include/openmc/tallies/filter_energy.h +++ b/include/openmc/tallies/filter_energy.h @@ -22,7 +22,8 @@ public: //---------------------------------------------------------------------------- // Methods - std::string type() const override { return "energy"; } + std::string type_str() const override { return "energy"; } + FilterType type() const override { return FilterType::ENERGY; } void from_xml(pugi::xml_node node) override; @@ -63,7 +64,8 @@ public: //---------------------------------------------------------------------------- // Methods - std::string type() const override { return "energyout"; } + std::string type_str() const override { return "energyout"; } + FilterType type() const override { return FilterType::ENERGY_OUT; } void get_all_bins(const Particle& p, TallyEstimator estimator, FilterMatch& match) const override; diff --git a/include/openmc/tallies/filter_energyfunc.h b/include/openmc/tallies/filter_energyfunc.h index 373fee8dd..d77ef0fa8 100644 --- a/include/openmc/tallies/filter_energyfunc.h +++ b/include/openmc/tallies/filter_energyfunc.h @@ -24,7 +24,8 @@ public: //---------------------------------------------------------------------------- // Methods - std::string type() const override { return "energyfunction"; } + std::string type_str() const override { return "energyfunction"; } + FilterType type() const override { return FilterType::ENERGY_FUNCTION; } void from_xml(pugi::xml_node node) override; diff --git a/include/openmc/tallies/filter_legendre.h b/include/openmc/tallies/filter_legendre.h index b1fac37c8..839fd77bf 100644 --- a/include/openmc/tallies/filter_legendre.h +++ b/include/openmc/tallies/filter_legendre.h @@ -21,7 +21,8 @@ public: //---------------------------------------------------------------------------- // Methods - std::string type() const override { return "legendre"; } + std::string type_str() const override { return "legendre"; } + FilterType type() const override { return FilterType::LEGENDRE; } void from_xml(pugi::xml_node node) override; diff --git a/include/openmc/tallies/filter_material.h b/include/openmc/tallies/filter_material.h index f58fc9938..5da556d5e 100644 --- a/include/openmc/tallies/filter_material.h +++ b/include/openmc/tallies/filter_material.h @@ -25,7 +25,8 @@ public: //---------------------------------------------------------------------------- // Methods - std::string type() const override { return "material"; } + std::string type_str() const override { return "material"; } + FilterType type() const override { return FilterType::MATERIAL; } void from_xml(pugi::xml_node node) override; diff --git a/include/openmc/tallies/filter_mesh.h b/include/openmc/tallies/filter_mesh.h index ef055b1a2..e3bcd7c20 100644 --- a/include/openmc/tallies/filter_mesh.h +++ b/include/openmc/tallies/filter_mesh.h @@ -24,7 +24,8 @@ public: //---------------------------------------------------------------------------- // Methods - std::string type() const override { return "mesh"; } + std::string type_str() const override { return "mesh"; } + FilterType type() const override { return FilterType::MESH; } void from_xml(pugi::xml_node node) override; diff --git a/include/openmc/tallies/filter_meshsurface.h b/include/openmc/tallies/filter_meshsurface.h index 28f4e265f..195995c69 100644 --- a/include/openmc/tallies/filter_meshsurface.h +++ b/include/openmc/tallies/filter_meshsurface.h @@ -10,7 +10,8 @@ public: //---------------------------------------------------------------------------- // Methods - std::string type() const override { return "meshsurface"; } + std::string type_str() const override { return "meshsurface"; } + FilterType type() const override { return FilterType::MESH_SURFACE; } void get_all_bins(const Particle& p, TallyEstimator estimator, FilterMatch& match) const override; diff --git a/include/openmc/tallies/filter_mu.h b/include/openmc/tallies/filter_mu.h index 5299f6dd4..942ee60c2 100644 --- a/include/openmc/tallies/filter_mu.h +++ b/include/openmc/tallies/filter_mu.h @@ -23,7 +23,8 @@ public: //---------------------------------------------------------------------------- // Methods - std::string type() const override { return "mu"; } + std::string type_str() const override { return "mu"; } + FilterType type() const override { return FilterType::MU; } void from_xml(pugi::xml_node node) override; diff --git a/include/openmc/tallies/filter_particle.h b/include/openmc/tallies/filter_particle.h index cd4c5d413..a181d5cee 100644 --- a/include/openmc/tallies/filter_particle.h +++ b/include/openmc/tallies/filter_particle.h @@ -21,7 +21,8 @@ public: //---------------------------------------------------------------------------- // Methods - std::string type() const override { return "particle"; } + std::string type_str() const override { return "particle"; } + FilterType type() const override { return FilterType::PARTICLE; } void from_xml(pugi::xml_node node) override; diff --git a/include/openmc/tallies/filter_polar.h b/include/openmc/tallies/filter_polar.h index e06aca1e0..78bb25aa4 100644 --- a/include/openmc/tallies/filter_polar.h +++ b/include/openmc/tallies/filter_polar.h @@ -24,7 +24,8 @@ public: //---------------------------------------------------------------------------- // Methods - std::string type() const override { return "polar"; } + std::string type_str() const override { return "polar"; } + FilterType type() const override { return FilterType::POLAR; } void from_xml(pugi::xml_node node) override; diff --git a/include/openmc/tallies/filter_sph_harm.h b/include/openmc/tallies/filter_sph_harm.h index 5f5bf84f2..5d4a4bd99 100644 --- a/include/openmc/tallies/filter_sph_harm.h +++ b/include/openmc/tallies/filter_sph_harm.h @@ -25,7 +25,8 @@ public: //---------------------------------------------------------------------------- // Methods - std::string type() const override { return "sphericalharmonics"; } + std::string type_str() const override { return "sphericalharmonics"; } + FilterType type() const override { return FilterType::SPHERICAL_HARMONICS; } void from_xml(pugi::xml_node node) override; diff --git a/include/openmc/tallies/filter_sptl_legendre.h b/include/openmc/tallies/filter_sptl_legendre.h index d6ac24668..b6c380e9b 100644 --- a/include/openmc/tallies/filter_sptl_legendre.h +++ b/include/openmc/tallies/filter_sptl_legendre.h @@ -23,7 +23,8 @@ public: //---------------------------------------------------------------------------- // Methods - std::string type() const override { return "spatiallegendre"; } + std::string type_str() const override { return "spatiallegendre"; } + FilterType type() const override { return FilterType::SPATIAL_LEGENDRE; } void from_xml(pugi::xml_node node) override; diff --git a/include/openmc/tallies/filter_surface.h b/include/openmc/tallies/filter_surface.h index 358963fde..3537f1cc7 100644 --- a/include/openmc/tallies/filter_surface.h +++ b/include/openmc/tallies/filter_surface.h @@ -25,7 +25,8 @@ public: //---------------------------------------------------------------------------- // Methods - std::string type() const override { return "surface"; } + std::string type_str() const override { return "surface"; } + FilterType type() const override { return FilterType::SURFACE; } void from_xml(pugi::xml_node node) override; diff --git a/include/openmc/tallies/filter_time.h b/include/openmc/tallies/filter_time.h index c66481c57..105ef9880 100644 --- a/include/openmc/tallies/filter_time.h +++ b/include/openmc/tallies/filter_time.h @@ -22,7 +22,8 @@ public: //---------------------------------------------------------------------------- // Methods - std::string type() const override { return "time"; } + std::string type_str() const override { return "time"; } + FilterType type() const override { return FilterType::TIME; } void from_xml(pugi::xml_node node) override; diff --git a/include/openmc/tallies/filter_universe.h b/include/openmc/tallies/filter_universe.h index fde0b6397..d4894353b 100644 --- a/include/openmc/tallies/filter_universe.h +++ b/include/openmc/tallies/filter_universe.h @@ -25,7 +25,8 @@ public: //---------------------------------------------------------------------------- // Methods - std::string type() const override { return "universe"; } + std::string type_str() const override { return "universe"; } + FilterType type() const override { return FilterType::UNIVERSE; } void from_xml(pugi::xml_node node) override; diff --git a/include/openmc/tallies/filter_zernike.h b/include/openmc/tallies/filter_zernike.h index 72c47e654..b6d9c91e6 100644 --- a/include/openmc/tallies/filter_zernike.h +++ b/include/openmc/tallies/filter_zernike.h @@ -21,7 +21,8 @@ public: //---------------------------------------------------------------------------- // Methods - std::string type() const override { return "zernike"; } + std::string type_str() const override { return "zernike"; } + FilterType type() const override { return FilterType::ZERNIKE; } void from_xml(pugi::xml_node node) override; @@ -72,7 +73,8 @@ public: //---------------------------------------------------------------------------- // Methods - std::string type() const override { return "zernikeradial"; } + std::string type_str() const override { return "zernikeradial"; } + FilterType type() const override { return FilterType::ZERNIKE_RADIAL; } void get_all_bins(const Particle& p, TallyEstimator estimator, FilterMatch& match) const override; diff --git a/src/state_point.cpp b/src/state_point.cpp index 470dd7718..4170421be 100644 --- a/src/state_point.cpp +++ b/src/state_point.cpp @@ -804,7 +804,7 @@ void write_unstructured_mesh_results() vector tally_scores; for (auto filter_idx : tally->filters()) { auto& filter = model::tally_filters[filter_idx]; - if (filter->type() != "mesh") + if (filter->type() != FilterType::MESH) continue; // check if the filter uses an unstructured mesh diff --git a/src/tallies/filter.cpp b/src/tallies/filter.cpp index a1e5c709f..a121299fe 100644 --- a/src/tallies/filter.cpp +++ b/src/tallies/filter.cpp @@ -232,7 +232,7 @@ extern "C" int openmc_filter_get_type(int32_t index, char* type) if (int err = verify_filter(index)) return err; - std::strcpy(type, model::tally_filters[index]->type().c_str()); + std::strcpy(type, model::tally_filters[index]->type_str().c_str()); return 0; } diff --git a/src/tallies/filter_cell.cpp b/src/tallies/filter_cell.cpp index 9ccae6b48..794d2ae08 100644 --- a/src/tallies/filter_cell.cpp +++ b/src/tallies/filter_cell.cpp @@ -80,7 +80,7 @@ extern "C" int openmc_cell_filter_get_bins( return err; const auto& filt = model::tally_filters[index].get(); - if (filt->type() != "cell") { + if (filt->type() != FilterType::CELL) { set_errmsg("Tried to get cells from a non-cell filter."); return OPENMC_E_INVALID_TYPE; } diff --git a/src/tallies/filter_mesh.cpp b/src/tallies/filter_mesh.cpp index 3f895b4f8..deb143346 100644 --- a/src/tallies/filter_mesh.cpp +++ b/src/tallies/filter_mesh.cpp @@ -16,7 +16,7 @@ void MeshFilter::from_xml(pugi::xml_node node) auto bins_ = get_node_array(node, "bins"); if (bins_.size() != 1) { fatal_error( - "Only one mesh can be specified per " + type() + " mesh filter."); + "Only one mesh can be specified per " + type_str() + " mesh filter."); } auto id = bins_[0]; @@ -158,7 +158,8 @@ extern "C" int openmc_mesh_filter_get_translation( // Check the filter type const auto& filter = model::tally_filters[index]; - if (filter->type() != "mesh" && filter->type() != "meshsurface") { + if (filter->type() != FilterType::MESH && + filter->type() != FilterType::MESH_SURFACE) { set_errmsg("Tried to get a translation from a non-mesh-based filter."); return OPENMC_E_INVALID_TYPE; } @@ -182,7 +183,8 @@ extern "C" int openmc_mesh_filter_set_translation( const auto& filter = model::tally_filters[index]; // Check the filter type - if (filter->type() != "mesh" && filter->type() != "meshsurface") { + if (filter->type() != FilterType::MESH && + filter->type() != FilterType::MESH_SURFACE) { set_errmsg("Tried to set mesh on a non-mesh-based filter."); return OPENMC_E_INVALID_TYPE; } diff --git a/src/tallies/tally.cpp b/src/tallies/tally.cpp index 11d5b245f..51194684a 100644 --- a/src/tallies/tally.cpp +++ b/src/tallies/tally.cpp @@ -140,16 +140,18 @@ Tally::Tally(pugi::xml_node node) particle_filter_index = i_filter; // Change the tally estimator if a filter demands it - std::string filt_type = f->type(); - if (filt_type == "energyout" || filt_type == "legendre") { + FilterType filt_type = f->type(); + if (filt_type == FilterType::ENERGY_OUT || + filt_type == FilterType::LEGENDRE) { estimator_ = TallyEstimator::ANALOG; - } else if (filt_type == "sphericalharmonics") { + } else if (filt_type == FilterType::SPHERICAL_HARMONICS) { auto sf = dynamic_cast(f); if (sf->cosine() == SphericalHarmonicsCosine::scatter) { estimator_ = TallyEstimator::ANALOG; } - } else if (filt_type == "spatiallegendre" || filt_type == "zernike" || - filt_type == "zernikeradial") { + } else if (filt_type == FilterType::SPATIAL_LEGENDRE || + filt_type == FilterType::ZERNIKE || + filt_type == FilterType::ZERNIKE_RADIAL) { estimator_ = TallyEstimator::COLLISION; } }