Plot Elastic Scattering Cross Section for Mesitylene at 20K (Including S(a,b))

Hi there,

I am new to OpenMC and I would like to plot the cross section for a cold mesitylene moderator at 20K. An S(a,b) table exists in the JEFF3.3 library for this material to ensure a proper description of the elastic cross section for neutrons with energies less than 9.85 eV. I saw instructions for creating plots from Incident Neutron data alone. I am aware that the S(a,b) table can be read using ThermalScattering function on OpenMC and I was able to get it to read the S(a,b) table for mesitylene at 20K. How do I go about plotting the elastic cross section, where I include the correction to the elastic cross section using the S(a,b) table?

Thanks in advance for any tips.

Kind regards,
Dalini

Hi @dmaharaj and welcome to the community! Here’s a short code you could use to plot the mesitylene elastic cross section at 20K:

import openmc.data
import numpy as np
import matplotlib.pyplot as plt

tsl = openmc.data.ThermalScattering.from_hdf5('c_H_in_Mesitylene.h5')

# Create a grid a energies from 1e-5 eV to the max energy of the S(a,b) table
energies = np.logspace(np.log10(1e-5), np.log10(tsl.energy_max))

# Get cross section object
elastic_xs = tsl.elastic.xs['20K']

# Evaluate cross sections at each energy and plot
xs = elastic_xs(energies)
plt.loglog(energies, xs)
plt.xlabel('Energy [eV]')
plt.ylabel('Cross section [b]')
1 Like

Dear @paulromano,

Thanks for the intro to the forum, and even bigger thanks for sharing this script with me to unpack the TSL data and plot it. This is helpful as I am also new to object oriented programming and I expect learning OpenMC will provide an opportunity to expand my skills.

Best wishes,
Dalini

1 Like

Dear @paulromano,

I wish to investigate the effect of applying the S(a,b) thermal scattering table for hydrogen in mesitylene to the material characteristics of mesitylene on the macroscopic (i) elastic (ii) inelastic and (ii) total cross sections.

To do this, I created the material, mesitylene, at 20K, using the openmc.Material() function. Below is the code which I used to plot the cross sections below 10eV. It did not work. It only works for the case where I did not attempt to apply the S(a,b) cross section. That plot is shown at the bottom of the e-mail. I have some questions which will help guide me while I fix this.

  1. If I’ve read the documentation correctly, sab_name only applies the S(a,b) cross section to MT2, which corresponds to the elastic cross section. Is there not any way to look at the influence of S(a,b) on the total and inelastic cross sections?

  2. The plot of the inelastic cross section does not appear in my plots, as you can see in my graph below. I’m not sure why this is the case. Do you have any idea why it does not appear?

  3. In the documentation, it says that sab_name is only used for items which are instances of openmc.Element or openmc.Nuclide. I haven’t used either. Do I need to change how I define the compound, mesitylene?

  4. I would like to compare the elastic cross sections for two different materials. How might I be able to plot the two cross sections on the same graph?

  5. FYI, the line mesiTh.add_s_alpha_beta(…) generates this error on my end.

Thanks in advance for any insights, and I apologize in advance, if I’ve made any catastrophic errors.

Best wishes and happy holidays,
Dalini

import os
from pprint import pprint
import shutil
import subprocess
import urllib.request
import h5py
import os
import numpy as np
import matplotlib.pyplot as plt
import openmc.data
from matplotlib.patches import Rectangle
import matplotlib.cm

mesi = openmc.Material()
mesi.add_nuclide('H1', 4.0,'ao')
mesi.add_nuclide('C0', 3.0,'ao')
mesi.set_density('g/cm3', 0.865)
openmc.plot_xs(mesi,['total','inelastic','elastic'],temperature=20)
plt.xlim([0.0001,10])
plt.ylim([1,30])
plt.title('Cross Section for Mesitylene at 20K')
plt.show()

mesiTh = openmc.Material()
mesiTh.add_nuclide('H1', 4.0,'ao')
mesiTh.add_nuclide('C0', 3.0,'ao')
mesiTh.add_s_alpha_beta('c_H_in_Mesitylene')
mesiTh.set_density('g/cm3', 0.865)
openmc.plot_xs(mesiTh,['total','inelastic','elastic'],temperature=20,sab_name='c_H_in_Mesitylene')
plt.xlim([0.0001,10])
plt.ylim([1,30])
plt.title('Cross Section for Mesitylene at 20K (w/ S(a,b))')
plt.show()

Total_xn-mesi

@dmaharaj It looks like this is a bug in the plot_xs function. I have a bug fix tested locally that successfully produces a plot including the S(a,b) data for mesitylene and will submit a pull request for it. If you want to try the change on a local version of OpenMC, here is the necessary change:

diff --git a/openmc/plotter.py b/openmc/plotter.py
index 16760868e..e2d18d085 100644
--- a/openmc/plotter.py
+++ b/openmc/plotter.py
@@ -563,7 +563,7 @@ def _calculate_cexs_elem_mat(this, types, temperature=294.,
     for nuclide in nuclides.items():
         sabs[nuclide[0]] = None
     if isinstance(this, openmc.Material):
-        for sab_name in this._sab:
+        for sab_name, _ in this._sab:
             sab = openmc.data.ThermalScattering.from_hdf5(
                 library.get_by_material(sab_name, data_type='thermal')['path'])
             for nuc in sab.nuclides:

EDIT: Bug fix has been submitted.

Dear Paul,

Happy new year! I apologize for the delayed reply, but I was away for the holidays.

I am not accustomed to changing the source code locally. But I am sure I will figure it out once I snoop around a bit. I’ll let you know when I am successful!

Best wishes,
Dalini

Hi Paul,

Unfortunately, it did not work for me and I am not sure why. Here’s exactly what I did.

  1. I made the changes to a copy of openmc. Then I replaced the relevant line of code in plotter.py as shown below.

  2. I restarted Terminal and re-ran the script but I get the same error messages.

  3. I’ve also included a screenshot of source control for openmc. Maybe there is information there which can help you determine what the issue is.


    image

Let me know if you have any insights. Thanks again!

Best wishes,
Dalini

Depending on how openmc was installed from source you might want to reinstall it once these changes have been made.

Perhaps a pip install . from the root directory to update the python package

Hi @Shimwell,

Thanks for your reply, it worked like a charm! As I am still finding my bearings around git it didn’t occur to me that I needed to run,

pip install .

in the parent folder. I was able to produce the plots as I wanted and the result is shown below. Thanks so much to you and @paulromano for your help!

Best,
Dalini

xns-mesi
xns-mesi-Sab

1 Like