Add wrapper class for custom sources

This commit is contained in:
Paul Romano 2020-10-22 15:50:30 -05:00
parent 713469bf59
commit 3f62fab565
4 changed files with 95 additions and 142 deletions

View file

@ -71,6 +71,28 @@ private:
std::vector<Particle::Bank> sites_; //!< Source sites from a file
};
//==============================================================================
//! Wrapper for custom sources that manages opening/closing shared library
//==============================================================================
class CustomSourceWrapper : public SourceDistribution {
public:
// Constructors, destructors
CustomSourceWrapper(std::string path, std::string parameters);
~CustomSourceWrapper();
// Defer implementation to custom source library
Particle::Bank sample(uint64_t* seed) override
{
return custom_source_->sample(seed);
}
double strength() const override { return custom_source_->strength(); }
private:
void* shared_library_; //!< library from dlopen
std::unique_ptr<SourceDistribution> custom_source_;
};
typedef std::unique_ptr<SourceDistribution> create_custom_source_t(std::string parameters);
//==============================================================================
@ -86,18 +108,6 @@ extern "C" void initialize_source();
//! \return Sampled source site
Particle::Bank sample_external_source(uint64_t* seed);
//! Sample a site from custom source library
Particle::Bank sample_custom_source_library(uint64_t* seed);
//! Load custom source library
void load_custom_source_library();
//! Release custom source library
void close_custom_source_library();
//! Fill source bank at the end of a generation for dlopen based source simulation
void fill_source_bank_custom_source();
void free_memory_source();
} // namespace openmc