Copyright (c) 2017-2020 Serpent-Tools developer team, GTRC
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Data files are not included with the python package, but can be downloaded from the GitHub repository. For this tutorial, the files are placed in the directory identified with the SERPENT_TOOLS_DATA
environment variable.
In [1]:
import os
xfile = os.path.join(
os.environ["SERPENT_TOOLS_DATA"],
"plut_xs0.m")
Firstly, to get started plotting some cross sections from Serpent, you generate a yourInputFileName_xs.m file using set xsplot as documented on the Serpent wiki. serpentTools
can then read the output, figuring out its filetype automatically as with other readers. Let's plot some data used in the serpentTools
regression suite.
In [ ]:
import serpentTools
%matplotlib inline
xsreader = serpentTools.read(xfile)
This file contains some cross sections from a Serpent case containing a chunk of plutonium metal reflected by beryllium. Let's see what cross sections are available from the file:
In [2]:
xsreader.xsections
Out[2]:
In [3]:
xsreader.keys()
Out[3]:
Notice that the important part of the reader is the xsections
attribute, which contains a dictionary of named XSData objects. Entries starting with "i" are isotopes, while "m" preceded names are materials. Notably, materials not appearing in the neutronics calculation, e.g., external tanks in Serpent continuous reprocessing calculations, are not printed in the yourInputFileName_xs.m file.
These XSData
instances can be obtained by indexing into the xsection
dictionary, or the reader directly.
In [4]:
# Check that the two entries stored are identical objects in memory
assert xsreader.xsections['i4009_03c'] is xsreader["i4009_03c"]
The final bit of useful information stored on the reader are the energy groups and majorant cross section. The energy groups are shared across all the XSData
objects stored on the reader.
In [5]:
xsreader.energies
Out[5]:
In [6]:
xsreader.majorant
Out[6]:
In [7]:
o16 = xsreader["i8016_03c"]
In [8]:
# Make a quick dictionary to show the descriptions
dict(zip(o16.MT, o16.MTdescrip))
Out[8]:
Cross section data are stored in the xsdata
array, which has shape (N_E, N_MT)
In [9]:
assert o16.xsdata.shape == (len(o16.energies), len(o16.MT))
The data can be obtained in a few different ways. First, you can index into the xsdata
array directly
In [10]:
o16.xsdata[:, 0]
Out[10]:
This implies you know the position of your reaction. Alternatively, you can index directly into the XSData
object using the reaction MT as a key
In [11]:
o16[1]
Out[11]:
The tabulate
method can be used to create a pandas DataFrame
for nice tabular representation
In [12]:
xsreader.xsections['mfissile'].tabulate()
Out[12]:
Lastly, the descriptions for the reaction MTs can be found in MTdescrip
or using describe
In [13]:
o16.MTdescrip[0]
Out[13]:
In [14]:
o16.describe(1)
Out[14]:
In [15]:
be9 = xsreader["i4009_03c"]
In [16]:
be9.plot(legend='right');
This is nice to have an automatically generated legend, but gets somewhat busy quickly. So, it's easy to check which MT numbers are available, and plot only a few:
In [17]:
be9.showMT()
In [ ]:
be9.plot(mts=[2, 16], title='Less busy!');
Of course, the same process can be applied to materials, but Serpent has some special unique negative MT numbers. The code will give you their meaning without requiring your reference back to the wiki.
In [ ]:
xsreader.xsections['mfissile'].showMT()
In [ ]:
xsreader.xsections['mfissile'].plot(mts=[-3, -6, -16], loglog=True);
Labels can be configured through the labels
argument
In [21]:
xsreader.xsections['mfissile'].plot(mts=[-3, -6], loglog=True, labels=["Total elastic scatter", "Total fission"]);
serpentTools
can plot your Serpent XS data in a friendly way. We're always looking to improve the feel of the code though, so let us know if there are changes you would like.
Keep in mind that setting an energy grid with closer to 10000 points makes far prettier XS plots however. There were none in this example to not clog up the repository.