Cylinder source in fixed source mode

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()