Pin Power Distribution in Two types of Fuel Pin by Cell Filter

Hi there,
I was trying to visualize the pin-power distribution of an assembly containing two different fuel types in the same picture. But I am getting errors.
Let me share the tally and loop block part of the code

import openmc as mc
# Instantiate the Tally
tally_c = mc.Tally(name='distribcell tally 1')
tally_c.filters = [mc.DistribcellFilter(fuelc)]
tally_c.scores = ['fission']

# 2nd distribcell tally
tally_2 = mc.Tally(name='distribcell tally 2')
tally_2.filters = [mc.DistribcellFilter(fuel2)]
tally_2.scores = ['fission']

# Export all tallies to a "tallies.xml" file
tallies_file = mc.Tallies([tally_c, tally_2])
tallies_file.export_to_xml()

#Reading Statepoint to get data
with mc.StatePoint('statepoint.10.h5') as sp:
    tally1 = sp.get_tally(name='distribcell tally 1')
    df1 = tally1.get_pandas_dataframe()
    tally2 = sp.get_tally(name='distribcell tally 2')
    df2 = tally2.get_pandas_dataframe()
    # let's merge two dataframe object into one
    concat = pd.concat([df1, df2])
    ce_fission_rates = concat[concat['score'] == 'fission']
    # Normalize
    m = (ce_fission_rates[['mean']]/ce_fission_rates[['mean']].mean())
    # create another column with norm value
    df3 = ce_fission_rates.assign(Normalized = m)
    fis_value = df3.Normalized.ravel()
#setting up resolution and min, max value
resolution = (600, 600)
img = np.full(resolution, np.nan)
xmin, xmax = -l, l
ymin, ymax = -l, l
#reading library memory to sort data according to Cell ID
with mc.lib.run_in_memory():
    for row, y in enumerate(np.linspace(ymin, ymax, resolution[0])):
        for col, x in enumerate(np.linspace(xmin, xmax, resolution[1])):
            try:
                # For each (x, y, z) point, determine the cell and distribcell index
                cell, distribcell_index = openmc.lib.find_cell((x, y, 0.))
            except mc.exceptions.GeometryError:
                # If a point appears outside the geometry, you'll get a GeometryError exception.
                # These lines catch the exception and continue on
                continue

            if cell.id == fuelc.id and cell.id == fuel2.id:
                # When the cell ID matches, we set the corresponding pixel in the image using the
                # distribcell index. Note that we're taking advantage of the fact that the i-th element
                # in the flux array corresponds to the i-th distribcell instance.
                print(distribcell_index)
                img[row, col] = fis_value[distribcell_index]
# Visualizing data
 ce_fission_rates[ce_fission_rates == 0.] = np.nan

 options = {
     'origin': 'lower',
     'extent': (xmin, xmax, ymin, ymax),
     'vmin': 0.50,
     'vmax': 2.00,
     'cmap': 'jet',
}
plt.imshow(img, **options)
plt.title('Continuous-Energy Fission Rates')
plt.colorbar()
plt.show()
plt.savefig('ref.png', format='png', dpi=1200, transparent= False)

Can anyone help me solve this?
Thank you

@fsabab What errors are you seeing when you run this?

Thank you for replying back to me @paulromano. I only see a blank image when I try to plot it. This doesn’t happen when I try to plot only one type of fuel rod. For example, consider this

If I try to plot using only fuelc.id, I can visualize the fuel rods which contain the fuelc cell. However, giving both conditions give me a blank graph.

Ok, I think I understand what might be wrong then:

In this line, there are two boolean conditions which don’t seem like they could both be true (assuming fuelc and fuel2 have different IDs). Perhaps you want if cell.id == fuelc.id or cell.id == fuel2.id? That is, use a logical OR instead of a logical AND.

1 Like

Thank you @paulromano