Odd EnergyFilter behaviour

I’ve noticed the following odd behaviour when plotting energy spectra using defined energy grids (or I am fundamentally misunderstanding this filter). I will demonstrate with the pincell example:

tallies = openmc.Tallies()

#create two sets of energy tallies: 
#one set with uniform log energy grids with np.logspace and 
#the second set with pre-defined grids

#evenly-spaced grids
num_groups = [75, 150, 300, 600, 1200]
for n in num_groups:
    groups = np.logspace(-5, log10(20e6), n)
    tally = openmc.Tally(name=str(n))
    tally.scores = ['flux']
    efil_in = openmc.EnergyFilter(groups)
    tally.filters = [efil_in]
    tallies.append(tally)

#pre-defined grids
scale_energy_grid = [1.000E-5, 1.000E-4, ... 1.733E+7, 2.000E+7 ] #shortened for easier viewing
grids = ['CASMO-70', 'XMAS-172', 'SCALE-238', 'SHEM-361', 'UKAEA-1102']

for grid in grids:
    if grid=='SCALE-238':
        groups = scale_energy_grid
    else:
        groups = openmc.mgxs.GROUP_STRUCTURES[grid]
    tally = openmc.Tally(name=grid)
    tally.scores = ['flux']
    efil_in = openmc.EnergyFilter(groups)
    tally.filters = [efil_in]
    tallies.append(tally)

tallies.export_to_xml()
openmc.run()

When plotting the results of all these EnergyFilter tallies we see fairly smooth results for the set of tallies using np.logspace, but wildly oscillating spectra from the set which used defined group structures:


Again I might be misunderstanding how the filter works, but some clarification would be much appreciated!

Thanks,

Sourena

@sourena Did you divide each flux value by its energy width?

energies = openmc.mgxs.GROUP_STRUCTURES['XMAS-172']

ax.loglog(energies[:-1], mean_7/np.diff(energies),  label='XMAS-172')
1 Like

@Pranto’s suggestion is right on. In fact, I recently put together a Jupyter notebook showing how to tally and plot a flux spectrum and this is mentioned (the need to divide by energy bin width).

1 Like

Thank you both, you are absolutely correct. The plots shown above were a straight flux plot, and were from a simplified version of the model in which the odd spectra were originally encountered. I revisited the original model after seeing your notes and the energy width calculation was being performed incorrectly. Thank you again for your help.