How to define a source in the shape of a spherical shell?

Hi all,

I am trying a few things out for my project and need to define a neutron source which has the shape of a spherical shell. I am also wondering what the difference is between openmc.stats.CartesianIndependent and openmc.stats.Point, if I can only specify cartesian point coordinates in both? Is it possible to use CartesianIndependent to put in a formula for a volume (like x^2 + y^2 + z^2 = r^2, separately defining radius and origin)? If I can make a sphere that way, I am hoping I could make a shell too. Or is there some way of defining surfaces and instead of filling them with a material, I can fill them with a source? Help would be greatly appreciated!

Thank you in advance!

@SophiaVT You can start with this custom source example

openmc.stats.Point() class is used for point source definition or delta function by giving Cartesian coordinates whereas openmc.stats.CartesianIndependent() is used for spatial distribution of x,y,z coordinates independently.

x = openmc.stats.Uniform(-10., 10.)
y = openmc.stats.Uniform(-10., 10.)
z = openmc.stats.Uniform(0., 20.)
d = openmc.stats.CartesianIndependent(x, y, z)

Thank you for the reply! How can I plot what the source looks like so that I can double-check?

@SophiaVT You can plot your custom source sample distribution after running the simulation

import h5py
f = h5py.File('initial_source.h5','r')
s_bank = f['source_bank']

x_values = []
y_values = []
z_values = []

for particle in s_bank:
    x_values.append(particle[0][0])
    y_values.append(particle[0][1])
    z_values.append(particle[0][2])

import matplotlib.pyplot as plt
plt.scatter(x_values, y_values)
plt.show()


Note that you have to make sure write_initial_source=True in your settings.xml file.

<write_initial_source>true</write_initial_source>

Hope this will help.

@Pranto thank you. I have not used a custom source before, in the example you provided in the link I can only see how to specify the radius in the x,y,z direction. How do I specify the shell source to have a certain width? I basically want to simulate a D-T plasma neutron source but in a purely spherical shape with a thickness that I can change.

Thanks again

@SophiaVT To have a shell source, you’ll also need to sample the radius in between a minimum and maximum radius. The appropriate PDF for the radius is uniform in r², as explained in arguments here. Thus, your sampling scheme will look something like:

double r_min = ...;
double r_max = ...;
double angle = 2 * M_PI * openmc::prn(seed);
double radius_sq = r_min*r_min + openmc::prn(seed)*(r_max*r_max - r_min*r_min);
double radius = std::sqrt(radius_sq);
particle.r.x = radius * std::cos(angle);
particle.r.y = radius * std::sin(angle);
particle.r.z = 0.0;