Plot three energy group flux tallies with python API

Hello, I have a design where I am doing flux tallie with three energy group. Below is my tallie.xml file

<?xml version='1.0' encoding='utf-8'?>

regular

120 1

<lower_left> -60 -60 </lower_left>

1 120

1

0.0 0.625 100000.0 20000000.0

1 2

flux

Now, I want the tally data plot on the same graph with python API. How can I do it? So far I am able to generate the graph with python API with only one energy group (0.0 0.625). To do that I edit my tallie.xml to only one energy group hanging 0.0 0.625 100000.0 20000000.0 to 0.0 0.625 , and after running the project i open python API and run these below commands,

Import openmc

sp = openmc.StatePoint(‘statepoint.200.h5’)

tally = sp.tallies[1]

flux = tally.mean.ravel()

import numpy as np

import matplotlib.pyplot as plt

x = np.linspace(-60, 60, 120)

plt.plot(x, flux)

plt.xlabel(‘x position [cm]’)

plt.ylabel('flux (0 - 0.625eV)’)

plt.show()

this generates a graph for the (0 - 0.625eV) energy group. Can anyone help me with the python API command that I can use to generate the graph for three energy group for my provided tallies.xml. I get three different flux value for three energy group for a single mash. I need to know how to ploy multiple energy group data in a single plot. I can do it with xcell. But I want to know the python API way. Any help is much appreciated. I followed the link https://openmc.readthedocs.io/en/stable/examples/tally-arithmetic.html but I wasn’t able to figure out. Thanks.

Hi Sharif,

If you want to get a single energy group, you can use the Tally.get_slice method to narrow the tally to just one bin from the energy filter. In your script, it would look something like:

tally_thermal = tally.get_slice(filters=[openmc.EnergyFilter], filter_bins=[((0.0, 0.625,)], squeeze=True)

From that point, you can now use tally_thermal just as you did before, calling tally_thermal.mean.ravel().

Best regards,
Paul

Hello Dr, thanks for your reply.