OpenMC/examples/custom_source/source_ring.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

36 lines
1 KiB
C++
Raw Permalink Normal View History

#define _USE_MATH_DEFINES
#include <cmath> // for M_PI
#include <memory> // for unique_ptr
2020-03-13 16:13:53 -05:00
#include "openmc/particle.h"
2020-03-13 16:13:53 -05:00
#include "openmc/random_lcg.h"
#include "openmc/source.h"
class RingSource : public openmc::Source {
openmc::SourceSite sample(uint64_t* seed) const
{
openmc::SourceSite particle;
2022-01-19 18:30:11 -06:00
// particle type
particle.particle = openmc::ParticleType::neutron();
// position
double angle = 2.0 * M_PI * openmc::prn(seed);
double radius = 3.0;
particle.r.x = radius * std::cos(angle);
particle.r.y = radius * std::sin(angle);
particle.r.z = 0.0;
// angle
particle.u = {1.0, 0.0, 0.0};
particle.E = 14.08e6;
return particle;
}
};
// 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<RingSource> openmc_create_source(
std::string parameters)
{
2020-10-23 13:45:28 -05:00
return std::make_unique<RingSource>();
2020-03-13 16:13:53 -05:00
}