From 0bb39005bcf7f9aad4d333ede0715c249229094e Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Fri, 23 Oct 2020 13:45:28 -0500 Subject: [PATCH] Rename source classes --- examples/custom_source/source_ring.cpp | 6 ++-- .../parameterized_source_ring.cpp | 12 +++---- include/openmc/settings.h | 1 - include/openmc/source.h | 33 +++++++++++-------- src/settings.cpp | 7 ++-- src/source.cpp | 14 ++++---- .../source_dlopen/source_sampling.cpp | 6 ++-- .../parameterized_source_sampling.cpp | 8 ++--- 8 files changed, 46 insertions(+), 41 deletions(-) diff --git a/examples/custom_source/source_ring.cpp b/examples/custom_source/source_ring.cpp index a23250db1..7ff3b03b4 100644 --- a/examples/custom_source/source_ring.cpp +++ b/examples/custom_source/source_ring.cpp @@ -5,7 +5,7 @@ #include "openmc/source.h" #include "openmc/particle.h" -class Source : public openmc::SourceDistribution +class RingSource : public openmc::Source { openmc::Particle::Bank sample(uint64_t* seed) { @@ -30,7 +30,7 @@ class Source : public openmc::SourceDistribution // A function to create a unique pointer to an instance of this class when generated // via a plugin call using dlopen/dlsym. // You must have external C linkage here otherwise dlopen will not find the file -extern "C" std::unique_ptr openmc_create_source(std::string parameters) +extern "C" std::unique_ptr openmc_create_source(std::string parameters) { - return std::make_unique(); + return std::make_unique(); } diff --git a/examples/parameterized_custom_source/parameterized_source_ring.cpp b/examples/parameterized_custom_source/parameterized_source_ring.cpp index 8668fd426..2176a073a 100644 --- a/examples/parameterized_custom_source/parameterized_source_ring.cpp +++ b/examples/parameterized_custom_source/parameterized_source_ring.cpp @@ -6,13 +6,13 @@ #include "openmc/source.h" #include "openmc/particle.h" -class Source : public openmc::SourceDistribution { +class RingSource : public openmc::Source { public: - Source(double radius, double energy) : radius_(radius), energy_(energy) { } + RingSource(double radius, double energy) : radius_(radius), energy_(energy) { } // Defines a function that can create a unique pointer to a new instance of this class // by extracting the parameters from the provided string. - static std::unique_ptr from_string(std::string parameters) + static std::unique_ptr from_string(std::string parameters) { std::unordered_map parameter_mapping; @@ -27,7 +27,7 @@ class Source : public openmc::SourceDistribution { double radius = std::stod(parameter_mapping["radius"]); double energy = std::stod(parameter_mapping["energy"]); - return std::make_unique(radius, energy); + return std::make_unique(radius, energy); } // Samples from an instance of this class. @@ -59,7 +59,7 @@ class Source : public openmc::SourceDistribution { // A function to create a unique pointer to an instance of this class when generated // via a plugin call using dlopen/dlsym. // You must have external C linkage here otherwise dlopen will not find the file -extern "C" std::unique_ptr openmc_create_source(std::string parameters) +extern "C" std::unique_ptr openmc_create_source(std::string parameters) { - return Source::from_string(parameters); + return RingSource::from_string(parameters); } diff --git a/include/openmc/settings.h b/include/openmc/settings.h index c743cf721..74cbbc132 100644 --- a/include/openmc/settings.h +++ b/include/openmc/settings.h @@ -59,7 +59,6 @@ extern std::string path_cross_sections; //!< path to cross_sections.xml extern std::string path_input; //!< directory where main .xml files resides extern std::string path_output; //!< directory where output files are written extern std::string path_particle_restart; //!< path to a particle restart file -extern std::string path_source_library; //!< path to the source shared object extern std::string path_sourcepoint; //!< path to a source file extern "C" std::string path_statepoint; //!< path to a statepoint file diff --git a/include/openmc/source.h b/include/openmc/source.h index ff4b3e04f..93e6bcf54 100644 --- a/include/openmc/source.h +++ b/include/openmc/source.h @@ -19,21 +19,21 @@ namespace openmc { // Global variables //============================================================================== -class SourceDistribution; +class Source; namespace model { -extern std::vector> external_sources; +extern std::vector> external_sources; } // namespace model //============================================================================== -//! External source distribution +//! Abstract source interface //============================================================================== -class SourceDistribution { +class Source { public: - virtual ~SourceDistribution() = default; + virtual ~Source() = default; // Methods that must be implemented virtual Particle::Bank sample(uint64_t* seed) = 0; @@ -42,11 +42,15 @@ public: virtual double strength() const { return 1.0; } }; -class IndependentSourceDistribution : public SourceDistribution { +//============================================================================== +//! Source composed of independent spatial, angle, and energy distributions +//============================================================================== + +class IndependentSource : public Source { public: // Constructors - IndependentSourceDistribution(UPtrSpace space, UPtrAngle angle, UPtrDist energy); - explicit IndependentSourceDistribution(pugi::xml_node node); + IndependentSource(UPtrSpace space, UPtrAngle angle, UPtrDist energy); + explicit IndependentSource(pugi::xml_node node); //! Sample from the external source distribution //! \param[inout] seed Pseudorandom seed pointer @@ -70,11 +74,14 @@ private: UPtrDist energy_; //!< Energy distribution }; +//============================================================================== +//! Source composed of particles read from a file +//============================================================================== -class SourceFile : public SourceDistribution { +class FileSource : public Source { public: // Constructors - explicit SourceFile(std::string path); + explicit FileSource(std::string path); // Methods Particle::Bank sample(uint64_t* seed) override; @@ -87,7 +94,7 @@ private: //! Wrapper for custom sources that manages opening/closing shared library //============================================================================== -class CustomSourceWrapper : public SourceDistribution { +class CustomSourceWrapper : public Source { public: // Constructors, destructors CustomSourceWrapper(std::string path, std::string parameters); @@ -102,10 +109,10 @@ public: double strength() const override { return custom_source_->strength(); } private: void* shared_library_; //!< library from dlopen - std::unique_ptr custom_source_; + std::unique_ptr custom_source_; }; -typedef std::unique_ptr create_custom_source_t(std::string parameters); +typedef std::unique_ptr create_custom_source_t(std::string parameters); //============================================================================== // Functions diff --git a/src/settings.cpp b/src/settings.cpp index b692274c6..5a868d445 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -73,7 +73,6 @@ std::string path_cross_sections; std::string path_input; std::string path_output; std::string path_particle_restart; -std::string path_source_library; std::string path_sourcepoint; std::string path_statepoint; @@ -422,7 +421,7 @@ void read_settings_xml() for (pugi::xml_node node : root.children("source")) { if (check_for_node(node, "file")) { auto path = get_node_value(node, "file", false, true); - model::external_sources.push_back(std::make_unique(path)); + model::external_sources.push_back(std::make_unique(path)); } else if (check_for_node(node, "library")) { // Get shared library path and parameters auto path = get_node_value(node, "library", false, true); @@ -434,13 +433,13 @@ void read_settings_xml() // Create custom source model::external_sources.push_back(std::make_unique(path, parameters)); } else { - model::external_sources.push_back(std::make_unique(node)); + model::external_sources.push_back(std::make_unique(node)); } } // If no source specified, default to isotropic point source at origin with Watt spectrum if (model::external_sources.empty()) { - model::external_sources.push_back(std::make_unique( + model::external_sources.push_back(std::make_unique( UPtrSpace{new SpatialPoint({0.0, 0.0, 0.0})}, UPtrAngle{new Isotropic()}, UPtrDist{new Watt(0.988e6, 2.249e-6)} diff --git a/src/source.cpp b/src/source.cpp index 5c96adc20..fd2d6cd8f 100644 --- a/src/source.cpp +++ b/src/source.cpp @@ -39,18 +39,18 @@ namespace openmc { namespace model { -std::vector> external_sources; +std::vector> external_sources; } //============================================================================== -// IndependentSourceDistribution implementation +// IndependentSource implementation //============================================================================== -IndependentSourceDistribution::IndependentSourceDistribution(UPtrSpace space, UPtrAngle angle, UPtrDist energy) +IndependentSource::IndependentSource(UPtrSpace space, UPtrAngle angle, UPtrDist energy) : space_{std::move(space)}, angle_{std::move(angle)}, energy_{std::move(energy)} { } -IndependentSourceDistribution::IndependentSourceDistribution(pugi::xml_node node) +IndependentSource::IndependentSource(pugi::xml_node node) { // Check for particle type if (check_for_node(node, "particle")) { @@ -141,7 +141,7 @@ IndependentSourceDistribution::IndependentSourceDistribution(pugi::xml_node node } } -Particle::Bank IndependentSourceDistribution::sample(uint64_t* seed) +Particle::Bank IndependentSource::sample(uint64_t* seed) { Particle::Bank site; @@ -233,7 +233,7 @@ Particle::Bank IndependentSourceDistribution::sample(uint64_t* seed) // SourceFile implementation //============================================================================== -SourceFile::SourceFile(std::string path) +FileSource::FileSource(std::string path) { // Check if source file exists if (!file_exists(path)) { @@ -261,7 +261,7 @@ SourceFile::SourceFile(std::string path) file_close(file_id); } -Particle::Bank SourceFile::sample(uint64_t* seed) +Particle::Bank FileSource::sample(uint64_t* seed) { size_t i_site = sites_.size()*prn(seed); return sites_[i_site]; diff --git a/tests/regression_tests/source_dlopen/source_sampling.cpp b/tests/regression_tests/source_dlopen/source_sampling.cpp index 4425af5a9..796b504f3 100644 --- a/tests/regression_tests/source_dlopen/source_sampling.cpp +++ b/tests/regression_tests/source_dlopen/source_sampling.cpp @@ -5,7 +5,7 @@ #include "openmc/source.h" #include "openmc/particle.h" -class Source : public openmc::SourceDistribution +class CustomSource : public openmc::Source { openmc::Particle::Bank sample(uint64_t *seed) { @@ -29,7 +29,7 @@ class Source : public openmc::SourceDistribution // A function to create a unique pointer to an instance of this class when generated // via a plugin call using dlopen/dlsym. // You must have external C linkage here otherwise dlopen will not find the file -extern "C" std::unique_ptr openmc_create_source(std::string parameters) +extern "C" std::unique_ptr openmc_create_source(std::string parameters) { - return std::make_unique(); + return std::make_unique(); } diff --git a/tests/regression_tests/source_parameterized_dlopen/parameterized_source_sampling.cpp b/tests/regression_tests/source_parameterized_dlopen/parameterized_source_sampling.cpp index 3f9e87639..91c165dbc 100644 --- a/tests/regression_tests/source_parameterized_dlopen/parameterized_source_sampling.cpp +++ b/tests/regression_tests/source_parameterized_dlopen/parameterized_source_sampling.cpp @@ -1,9 +1,9 @@ #include "openmc/source.h" #include "openmc/particle.h" -class Source : public openmc::SourceDistribution { +class CustomSource : public openmc::Source { public: - Source(double energy) : energy_(energy) { } + CustomSource(double energy) : energy_(energy) { } // Samples from an instance of this class. openmc::Particle::Bank sample(uint64_t* seed) @@ -31,8 +31,8 @@ class Source : public openmc::SourceDistribution { // A function to create a unique pointer to an instance of this class when generated // via a plugin call using dlopen/dlsym. // You must have external C linkage here otherwise dlopen will not find the file -extern "C" std::unique_ptr openmc_create_source(std::string parameter) +extern "C" std::unique_ptr openmc_create_source(std::string parameter) { double energy = std::stod(parameter); - return std::make_unique(energy); + return std::make_unique(energy); }