Cylinder source in fixed source mode

Hello, I am now trying to create multiple cylindrical sources in the mode ‘fixed source’, those sources are are just different in coordinates x,y and the other settings are totatly same. And I met two problems:
Here are my code:

radius=0.25
r=openmc.stats.PowerLaw(0.0,radius,1.0)
phi=openmc.stats.Uniform(0.0,2*pi)
z=openmc.stats.Uniform(-fuelLength/2,fuelLength/2)
x=[]
y=[]
m=12
for n in range(17-m):
    for i in range(5):
        for j in range(9-i):
            if i==0:
                x.append((3 ** 0.5) * m * L2 / 2 + (j - (8 - i) / 2) * L1)
                y.append((n - 8 + 0.5 * m) * L2 + (3 ** 0.5) * i * L1 / 2)
            else:
                x.append((3 ** 0.5) * m * L2 / 2 + (j - (8 - i) / 2) * L1)
                y.append((n - 8 + 0.5 * m) * L2 + (3 ** 0.5) * i * L1 / 2)
                x.append((3 ** 0.5) * m * L2 / 2 + (j - (8 - i) / 2) * L1)
                y.append((n - 8 + 0.5 * m) * L2 - (3 ** 0.5) * i * L1 / 2)

energy_bins = [1.00E-05, 0.625, 100, 1000, 5.00E+03, 10000, 50000, 1.00E+05, 200000, 300000, 4.00E+05,
               500000, 600000, 700000, 800000, 900000, 1000000, 2000000, 3000000, 4000000, 5000000,
               6000000, 7000000, 8000000, 9000000, 10000000, 20000000]
probability_density = [0.114804354, 0.130632628, 0.073037242, 0.056694686, 0.025809602, 0.06903753,
                       0.038666972, 0.051744062, 0.041062851, 0.034657177, 0.02416415, 0.027668522,
                       0.027214132, 0.025025168, 0.021317823, 0.015144402, 0.108801774, 0.059257734,
                       0.026894671, 0.014246912, 0.007213418, 0.003657553, 0.001703832, 0.00081529,
                       0.00038822, 0.000339297]

sources=[]
for i in range(len(x)):
    source = openmc.Source()
    source = openmc.stats.CylindricalIndependent(r, phi, z, origin=(x[i], y[i], 0.0))
    source.angle = openmc.stats.Isotropic()
    source.energy = openmc.stats.Tabular(energy_bins, probability_density)
    sources.append(source)

# Indicate how many particles to run
settings = openmc.Settings()
settings.run_mode = 'fixed source'
settings.batches = 100
settings.inactive = 50
settings.particles = 1000
settings.temperature = {"method":"interpolation","range":(280+273.15,320+273.15),"multipole":True}
settings.source = sources
settings.export_to_xml()

Firstly, i dont konw why it made an error as follow:

Blockquote
TypeError: Unable to set “source distributions” to <openmc.stats.multivariate.CylindricalIndependent object at 0x7f8e02374e80>" which is not of type:“SourceBase”

what should i modify my code?

Secondly, for the energy spectrum of my source, I have a series of continuous energy intervals and their probability density:

energy low [eV] energy high [eV] probability_density
1.00E-05 0.625 0.114804354
0.625 100 0.130632628
100 1000 0.073037242
1.00E+03 5.00E+03 0.056694686
5000 10000 0.025809602
10000 50000 0.06903753
5.00E+04 1.00E+05 0.038666972
100000 200000 0.051744062
200000 300000 0.041062851
3.00E+05 4.00E+05 0.034657177
400000 500000 0.02416415
500000 600000 0.027668522
600000 700000 0.027214132
700000 800000 0.025025168
800000 900000 0.021317823
900000 1000000 0.015144402
1000000 2000000 0.108801774
2000000 3000000 0.059257734
3000000 4000000 0.026894671
4000000 5000000 0.014246912
5000000 6000000 0.007213418
6000000 7000000 0.003657553
7000000 8000000 0.001703832
8000000 9000000 0.00081529
9000000 10000000 0.00038822
10000000 20000000 0.000339297

I am not sure the setting ‘source.energy’ in my code is correct. If not, how can i do it?

Thanks,
Richard

1 Like

Sir, Have you resolved your issue? I am facing the same problem for defining multiple sources. If possible, kindly guide me.
With thanks & best regards,
L Thilagam

For the first problem, that is my mistake. It must be:

source.space = openmc.stats.CylindricalIndependent(r, phi, z, origin=(x[i], y[i], 0.0))

And for the second one, my mentor told me that it should be set up this way:

energy_bins = [1.00E-05, 0.625, 100, 1000, 5.00E+03, 10000, 50000, 1.00E+05, 200000, 300000, 4.00E+05,
               500000, 600000, 700000, 800000, 900000, 1000000, 2000000, 3000000, 4000000, 5000000,
               6000000, 7000000, 8000000, 9000000, 10000000, 20000000]
probability_density = [0.114804354, 0.130632628, 0.073037242, 0.056694686, 0.025809602, 0.06903753,
                       0.038666972, 0.051744062, 0.041062851, 0.034657177, 0.02416415, 0.027668522,
                       0.027214132, 0.025025168, 0.021317823, 0.015144402, 0.108801774, 0.059257734,
                       0.026894671, 0.014246912, 0.007213418, 0.003657553, 0.001703832, 0.00081529,
                       0.00038822, 0.000339297,0]
source.energy = openmc.stats.Tabular(energy_bins, probability_density,'histogram')

Hope that helpful for you

Richard
This worked for me. Note the use of openmc_source_plotter to actually view the source configuration and energy.
I left a number of your steps in (as comments) to help clarify the changes that I made.
I did not try to make the input neat or concise, so there may be code that is unneeded or redundant.
I wasn’t sure what you were trying to do with the variables L1 & L2, so I assumed the had something to do with the source length.

Thanks for posting the question. It helped me learn OpenMC a little better.

from math import pi, sin, cos
import numpy as np
import openmc
from openmc_source_plotter import plot_source_position

radius=0.25
pi=np.pi
fuelLength=10.0
L1=fuelLength/2.5
L2=fuelLength/2.0

source = openmc.IndependentSource()

r=openmc.stats.PowerLaw(0.0,radius,1.0)
phi=openmc.stats.Uniform(0.0,2*pi)
z=openmc.stats.Uniform(-fuelLength/2,fuelLength/2)

x=
y=
m=12

for n in range(17-m):

for i in range(5):

for j in range(9-i):

if i==0:

x.append((3 ** 0.5) * m * L2 / 2 + (j - (8 - i) / 2) * L1)

y.append((n - 8 + 0.5 * m) * L2 + (3 ** 0.5) * i * L1 / 2)

else:

x.append((3 ** 0.5) * m * L2 / 2 + (j - (8 - i) / 2) * L1)

y.append((n - 8 + 0.5 * m) * L2 + (3 ** 0.5) * i * L1 / 2)

x.append((3 ** 0.5) * m * L2 / 2 + (j - (8 - i) / 2) * L1)

y.append((n - 8 + 0.5 * m) * L2 - (3 ** 0.5) * i * L1 / 2)

energy_bins = [1.00E-05, 0.625, 100, 1000, 5.00E+03, 10000,
50000, 1.00E+05, 200000, 300000, 4.00E+05, 500000,
600000, 700000, 800000, 900000, 1000000, 2000000,
3000000, 4000000, 5000000, 6000000, 7000000, 8000000,
9000000, 10000000, 20000000]
probability_density = [0.114804354, 0.130632628, 0.073037242, 0.056694686, 0.025809602, 0.06903753,
0.038666972, 0.051744062, 0.041062851, 0.034657177, 0.02416415, 0.027668522,
0.027214132, 0.025025168, 0.021317823, 0.015144402, 0.108801774, 0.059257734,
0.026894671, 0.014246912, 0.007213418, 0.003657553, 0.001703832, 0.00081529,
0.00038822, 0.000339297, 0]

sources=

for i in range(len(x)):

sources = openmc.stats.CylindricalIndependent(r, phi, z, origin=(x[i], y[i], 0.0))

sources.angle = openmc.stats.Isotropic()

sources.energy = openmc.stats.Tabular(energy_bins, probability_density,‘histogram’)

sources.append(source)

spatial_dist = openmc.stats.CylindricalIndependent(r, phi, z)

source.angle = openmc.stats.Isotropic()
source.energy = openmc.stats.Tabular(energy_bins, probability_density,‘histogram’)
source.space=spatial_dist

settings = openmc.Settings()
settings.source = source

settings.export_to_xml()

Indicate how many particles to run

settings = openmc.Settings()
settings.run_mode = ‘fixed source’
settings.batches = 100
settings.inactive = 50
settings.particles = 1000

settings.temperature = {“method”:“interpolation”,“range”:(280+273.15,320+273.15),“multipole”:True}

settings.source = source

settings.export_to_xml()

plots the particle energy distribution

plot = plot_source_position(source)

plot.show()

Thanks for your suggestion. I will check it with openmc_source_plotter.
Best regards