I am working on a project which requires a custom source. I have a few questions.
About custom sdef,
I am hoping the source will be sampled as isotropic thermal neutrons between r_min and r_max.
Here I attached the custom source definition (adjusted from the example),
#include <cmath> // for M_PI
#include <memory> // for unique_ptr
#include "openmc/distribution_multi.h"
#include "openmc/random_lcg.h"
#include "openmc/source.h"
#include "openmc/particle.h"
class HollowSphereSource : public openmc::Source
{
openmc::Particle::Bank sample(uint64_t* seed) const
{
openmc::Particle::Bank particle;
// particle type and weight
particle.particle = openmc::Particle::Type::neutron;
particle.wgt = 1.0;
// position
double phi = 2.0 * M_PI * openmc::prn(seed); // [0, 2pi)
double costheta = 2*openmc::prn(seed) - 1; // [-1, 1)
double u = openmc::prn(seed);
double r_min = 0.98;
double r_max = 30.0;
double r_diff = r_max - r_min;
double theta = std::acos(costheta);
double r = r_diff * std::cbrt(u);
particle.r.x = r_min + (r * std::sin(theta) * std::cos(phi));
particle.r.y = r_min + (r * std::sin(theta) * std::sin(phi));
particle.r.z = r_min + (r * std::cos(theta));
// angle and energy
particle.u = openmc::Isotropic().sample(seed);
particle.E = 253.e-4;
particle.delayed_group = 0;
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<HollowSphereSource> openmc_create_source(std::string parameters)
{
return std::make_unique<HollowSphereSource>();
}
Do I make any mistake on the sdef?
About linking the custom sdef to the OpenMC library,
I am using WSL on Windows. I installed openmc with Anaconda3 prior to the linking step.
After the hollow_sphere.cpp created, I created a CMakeLists.txt file below,
Welcome to the forum, @arief.rahman. The problem here is that the find_package call is not able to find the installation of OpenMC. If it was installed inside a conda environment, I would suggest using the CONDA_PREFIX environment variable as a hint, i.e.
@arief.rahman I was able to reproduce the behavior you are seeing. I think a solution here is to explicitly specify the directory that contains the OpenMCConfig.cmake file:
The problem seems to be that on some Linux distributions it doesn’t search for files in the lib64 directory (only lib). An alternative solution here would be to instruct it to specifically search lib64 directories:
Either way should hopefully work. In the meantime, I’m going to submit a change to our conda distribution to install the cmake files in lib instead of lib64.
Thanks for the corrections on the help @paulromano@Pranto. It works fine now by setting the dir to the following path,
I have a follow up question,
If I have 2nd custom sdef (in different dir to the current custom) and link that to the openmc, would that break the link between openmc and the 1st custom sdef?
If you have a second custom source linked to OpenMC, that will not interfere with the first one. You can create as many custom source definitions as you like.