OpenMC/include/openmc/source.h

134 lines
4 KiB
C
Raw Permalink Normal View History

2018-08-23 21:38:23 -05:00
//! \file source.h
//! \brief External source distributions
2018-07-17 06:43:35 -05:00
#ifndef OPENMC_SOURCE_H
#define OPENMC_SOURCE_H
#include "pugixml.hpp"
#include "openmc/distribution_multi.h"
#include "openmc/distribution_spatial.h"
#include "openmc/memory.h"
2018-07-17 06:43:35 -05:00
#include "openmc/particle.h"
#include "openmc/vector.h"
2018-07-17 06:43:35 -05:00
namespace openmc {
2018-11-08 15:29:46 -06:00
//==============================================================================
// Global variables
//==============================================================================
2020-10-23 13:45:28 -05:00
class Source;
2018-11-08 15:29:46 -06:00
namespace model {
extern vector<unique_ptr<Source>> external_sources;
2018-11-08 15:29:46 -06:00
} // namespace model
2018-07-17 06:43:35 -05:00
//==============================================================================
2020-10-23 13:45:28 -05:00
//! Abstract source interface
2018-07-17 06:43:35 -05:00
//==============================================================================
2020-10-23 13:45:28 -05:00
class Source {
public:
2020-10-23 13:45:28 -05:00
virtual ~Source() = default;
// Methods that must be implemented
2021-04-29 16:23:54 -04:00
virtual SourceSite sample(uint64_t* seed) const = 0;
// Methods that can be overridden
virtual double strength() const { return 1.0; }
};
2020-10-23 13:45:28 -05:00
//==============================================================================
//! Source composed of independent spatial, angle, and energy distributions
//==============================================================================
class IndependentSource : public Source {
2018-07-17 06:43:35 -05:00
public:
2018-08-23 21:38:23 -05:00
// Constructors
2020-10-23 13:45:28 -05:00
IndependentSource(UPtrSpace space, UPtrAngle angle, UPtrDist energy);
explicit IndependentSource(pugi::xml_node node);
2018-07-17 06:43:35 -05:00
2018-08-23 21:38:23 -05:00
//! Sample from the external source distribution
//! \param[inout] seed Pseudorandom seed pointer
2018-08-23 21:38:23 -05:00
//! \return Sampled site
2021-04-29 16:23:54 -04:00
SourceSite sample(uint64_t* seed) const override;
2018-08-23 21:38:23 -05:00
// Properties
ParticleType particle_type() const { return particle_; }
double strength() const override { return strength_; }
// Make observing pointers available
SpatialDistribution* space() const { return space_.get(); }
UnitSphereDistribution* angle() const { return angle_.get(); }
Distribution* energy() const { return energy_.get(); }
2018-07-17 06:43:35 -05:00
private:
ParticleType particle_ {ParticleType::neutron}; //!< Type of particle emitted
2018-08-23 21:38:23 -05:00
double strength_ {1.0}; //!< Source strength
UPtrSpace space_; //!< Spatial distribution
UPtrAngle angle_; //!< Angular distribution
UPtrDist energy_; //!< Energy distribution
};
2020-10-23 13:45:28 -05:00
//==============================================================================
//! Source composed of particles read from a file
//==============================================================================
2020-10-23 13:45:28 -05:00
class FileSource : public Source {
public:
// Constructors
2020-10-23 13:45:28 -05:00
explicit FileSource(std::string path);
// Methods
2021-04-29 16:23:54 -04:00
SourceSite sample(uint64_t* seed) const override;
private:
2021-04-29 16:23:54 -04:00
vector<SourceSite> sites_; //!< Source sites from a file
2018-07-17 06:43:35 -05:00
};
2020-10-22 15:50:30 -05:00
//==============================================================================
//! Wrapper for custom sources that manages opening/closing shared library
//==============================================================================
2020-10-23 13:45:28 -05:00
class CustomSourceWrapper : public Source {
2020-10-22 15:50:30 -05:00
public:
// Constructors, destructors
CustomSourceWrapper(std::string path, std::string parameters);
~CustomSourceWrapper();
// Defer implementation to custom source library
2021-04-29 16:23:54 -04:00
SourceSite sample(uint64_t* seed) const override
2020-10-22 15:50:30 -05:00
{
return custom_source_->sample(seed);
}
double strength() const override { return custom_source_->strength(); }
private:
void* shared_library_; //!< library from dlopen
unique_ptr<Source> custom_source_;
2020-10-22 15:50:30 -05:00
};
typedef unique_ptr<Source> create_custom_source_t(std::string parameters);
2018-07-17 06:43:35 -05:00
//==============================================================================
// Functions
//==============================================================================
//! Initialize source bank from file/distribution
extern "C" void initialize_source();
//! Sample a site from all external source distributions in proportion to their
//! source strength
//! \param[inout] seed Pseudorandom seed pointer
2018-08-23 21:38:23 -05:00
//! \return Sampled source site
2021-04-29 16:23:54 -04:00
SourceSite sample_external_source(uint64_t* seed);
2018-07-17 06:43:35 -05:00
2019-02-21 08:32:32 -06:00
void free_memory_source();
2018-07-17 06:43:35 -05:00
} // namespace openmc
#endif // OPENMC_SOURCE_H