Rename source classes

This commit is contained in:
Paul Romano 2020-10-23 13:45:28 -05:00
parent f2526ec439
commit 0bb39005bc
8 changed files with 46 additions and 41 deletions

View file

@ -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<Source> openmc_create_source(std::string parameters)
extern "C" std::unique_ptr<RingSource> openmc_create_source(std::string parameters)
{
return std::make_unique<Source>();
return std::make_unique<RingSource>();
}

View file

@ -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<Source> from_string(std::string parameters)
static std::unique_ptr<RingSource> from_string(std::string parameters)
{
std::unordered_map<std::string, std::string> 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<Source>(radius, energy);
return std::make_unique<RingSource>(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<Source> openmc_create_source(std::string parameters)
extern "C" std::unique_ptr<RingSource> openmc_create_source(std::string parameters)
{
return Source::from_string(parameters);
return RingSource::from_string(parameters);
}

View file

@ -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

View file

@ -19,21 +19,21 @@ namespace openmc {
// Global variables
//==============================================================================
class SourceDistribution;
class Source;
namespace model {
extern std::vector<std::unique_ptr<SourceDistribution>> external_sources;
extern std::vector<std::unique_ptr<Source>> 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<SourceDistribution> custom_source_;
std::unique_ptr<Source> custom_source_;
};
typedef std::unique_ptr<SourceDistribution> create_custom_source_t(std::string parameters);
typedef std::unique_ptr<Source> create_custom_source_t(std::string parameters);
//==============================================================================
// Functions

View file

@ -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<SourceFile>(path));
model::external_sources.push_back(std::make_unique<FileSource>(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<CustomSourceWrapper>(path, parameters));
} else {
model::external_sources.push_back(std::make_unique<IndependentSourceDistribution>(node));
model::external_sources.push_back(std::make_unique<IndependentSource>(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<IndependentSourceDistribution>(
model::external_sources.push_back(std::make_unique<IndependentSource>(
UPtrSpace{new SpatialPoint({0.0, 0.0, 0.0})},
UPtrAngle{new Isotropic()},
UPtrDist{new Watt(0.988e6, 2.249e-6)}

View file

@ -39,18 +39,18 @@ namespace openmc {
namespace model {
std::vector<std::unique_ptr<SourceDistribution>> external_sources;
std::vector<std::unique_ptr<Source>> 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];

View file

@ -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<Source> openmc_create_source(std::string parameters)
extern "C" std::unique_ptr<CustomSource> openmc_create_source(std::string parameters)
{
return std::make_unique<Source>();
return std::make_unique<CustomSource>();
}

View file

@ -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<Source> openmc_create_source(std::string parameter)
extern "C" std::unique_ptr<CustomSource> openmc_create_source(std::string parameter)
{
double energy = std::stod(parameter);
return std::make_unique<Source>(energy);
return std::make_unique<CustomSource>(energy);
}