MCNP output files#

The complete API can be found at f4enix.output.MCNPoutput.Output

Examining an MCNP output file can be useful to extract data on any of the tables contained within it, controlling statistical checks results or debugging for lost particles.

# Import the related module and parse the MCNP output file
from f4enix.output.MCNPoutput import Output

# Parse the output file
file = 'outp'
outp = Output(file)
# Check how many histories were run
'%.2E' % outp.get_NPS()
/home/docs/checkouts/readthedocs.org/user_builds/f4enix/envs/developing/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html
  from .autonotebook import tqdm as notebook_tqdm
'1.30E+06'
# get the MCNP/D1SUNED version used
outp.get_code_version()
'6.2'
# It is possible to read any printed table in the output
# Some issues still in the header names due to uncorrect format in MCNP FWF
# but the data is good.

# We specify that we want to read the last instance of the table 126. The output file
# may contain multiple instances of the same table due to multiple dumps and/or particle
# types. 
table_126 = outp.get_table(126, instance_idx=-1)
display(table_126)

# get for instance a percentage of unpopulated cells (i.e. 0 tracks entering)
unpopulated = len(table_126[table_126['populatio  '].astype(int) == 0])
print('Unpopulated cells fraction: {} %'.format(unpopulated/len(table_126)*100))
cell tracks entering populatio n collision s collisions * weight (per history number weighted ) energy flux weighted energy average track weigh (relative) average t track mfp (cm)
3 1.0 1 10882 9205 0 0.0000E+00 1.7602E+00 1.7602E+00 1.0106E+00 0.0000E+00
4 2.0 2 24955 50872 146068 1.3517E-08 1.7179E+00 1.7179E+00 1.0095E+00 2.7019E+00
5 3.0 3 30828 74594 182089 1.6853E-08 1.7222E+00 1.7222E+00 1.0095E+00 2.7033E+00
6 4.0 4 22084 54746 132281 2.4477E-08 1.6916E+00 1.6916E+00 1.0093E+00 2.6817E+00
7 5.0 5 33313 83006 199986 3.7012E-08 1.7182E+00 1.7182E+00 1.0091E+00 2.6976E+00
... ... ... ... ... ... ... ... ... ... ...
103 101.0 101 30600 76562 183594 3.3959E-08 1.7152E+00 1.7152E+00 1.0085E+00 2.7015E+00
104 102.0 102 19463 48379 116620 2.1554E-08 1.7004E+00 1.7004E+00 1.0074E+00 2.6866E+00
105 103.0 103 23502 58145 140406 1.2984E-08 1.7072E+00 1.7072E+00 1.0088E+00 2.6981E+00
106 104.0 104 13620 33617 80244 7.4088E-09 1.7158E+00 1.7158E+00 1.0075E+00 2.7085E+00
107 105.0 105 13144 31180 74064 3.4224E-09 1.6804E+00 1.6804E+00 1.0088E+00 2.7045E+00

105 rows × 10 columns

Unpopulated cells fraction: 0.0 %
# Check the MCNP 10 statistical checks
outp.get_stat_checks_table().sort_index()  # sort them by cell index
mean behaviour rel error value rel error decrease rel error decrease rate VoV value VoV decrease VoV decrease rate FoM value FoM behaviour PDF slope Other TFC bins
Tally
4 yes yes yes yes yes yes yes yes yes yes Passed
6 yes yes yes yes yes yes yes yes yes yes Passed
14 yes yes yes yes yes yes yes yes yes yes Passed
16 yes yes yes yes yes yes yes yes yes yes Passed
24 yes yes yes yes yes yes yes yes yes yes Passed
26 yes yes yes yes yes yes yes yes yes yes Passed
34 yes yes yes yes yes yes yes yes yes yes Passed
44 yes yes yes yes yes yes yes yes yes yes Passed
54 yes yes yes yes yes yes yes yes yes yes Passed
64 yes yes yes yes yes yes yes yes yes yes Passed
74 yes yes yes yes yes yes yes yes no yes Missed
84 yes yes yes yes yes yes yes yes no yes Missed
94 yes yes yes yes yes yes yes yes no yes Missed
104 yes yes yes yes yes yes yes yes yes yes Passed
114 yes yes yes yes yes yes yes yes yes yes Passed
124 yes yes yes yes yes yes yes yes yes yes Passed
134 yes yes yes yes yes yes yes yes yes yes Passed
144 yes yes yes yes yes yes yes yes yes yes Passed
154 yes yes yes yes yes yes yes yes yes yes Passed
164 yes yes yes yes yes yes yes yes yes yes Passed
174 yes yes yes yes yes yes yes yes yes yes Passed
204 yes yes yes yes yes yes yes yes yes yes Passed
214 yes yes yes yes yes yes yes yes yes yes Passed
# Get more info on the checks on a specific tally
outp.get_tally_stat_checks(74)
mean behaviour rel error value rel error decrease rel error decrease rate VoV value VoV decrease VoV decrease rate FoM value FoM behaviour PDF slope
TFC bin behaviour
desired random <0.10 yes 1/sqrt(nps) <0.10 yes 1/nps constant random >3.00
observed random 0.00 yes yes 0.00 yes yes constant decrease 10.00
passed? yes yes yes yes yes yes yes yes no yes
# get a pd.Series counting all the warnings encountered in the simulation
outp.get_warnings()[:10]  # show only 10
Warning
1 coincident energy grid points in   5011.31c                                                                 1
1 coincident energy grid points in  42095.31c                                                                 1
1000.  p and   1000.84p are both called for.                                                                  1
12000.  p and  12000.84p are both called for.                                                                 1
13000.  p and  13000.84p are both called for.                                                                 1
14000.  p and  14000.84p are both called for.                                                                 1
15000.  p and  15000.84p are both called for.                                                                 1
16000.  p and  16000.84p are both called for.                                                                 1
19000.  p and  19000.84p are both called for.                                                                 1
194 photons from neutron collisions were created below a local photon energy cutoff and were not followed.    1
dtype: int64
# get all fatal errors encountered in the simulation
# Parse the output file
outp = Output("outp_fatal")
outp.get_fatal_errors()
['no m card for material no. 1',
 'surface        5 of tally       22 not found.',
 'FILES card is missing.',
 'photon material        1 is not defined.',
 '1 tally volumes or areas were not input nor calculated.']

Lost particles debugging#

# Get the total number of particles lost (if applicable)
outp = Output('test_lp_u.o')
outp.get_tot_lp()
677
# get the Lost Particle Rate
outp.get_LPR()
0.06763236763236763
import tempfile  # To have a scratch directory for the example
outpath = tempfile.gettempdir()

# This will output excel file, csv and vtp file containing data for
# lost particles debugging in different formats.
outp.print_lp_debug(outpath) #, print_video=True) <- get interactive plot
# Get all the raw information as a pandas DataFrame
df = outp.get_lp_debug_df()
print(df)
    Surface Cell         x         y         z         u         v         w
0         6    6   8.51597   7.66724   5.83396  0.662279  0.596273  0.453702
1         6    6   7.75842   9.13777   5.61458  0.768164  0.178897  0.614752
2         6    6   7.36287   8.51361  13.97950  0.013925  0.389456 -0.920940
3         6    6  12.50940   7.94754   6.19337  0.532819  0.704170  0.469306
4         6    6   5.19721   8.90472   9.14354  0.907545 -0.184714  0.377151
..      ...  ...       ...       ...       ...       ...       ...       ...
672       6    6   8.89572   6.45090   6.65568  0.489383  0.117032  0.864180
673       6    6   8.49142  12.65140   6.03840 -0.273160 -0.408824  0.870774
674       6    6   5.15440   8.84265   9.57497  0.367758  0.630910  0.683159
675       6    6   9.96136   6.10580   6.86413  0.735109  0.450584  0.506546
676       6    6  11.65190   8.34418   5.58079  0.539463  0.611278  0.579067

[677 rows x 8 columns]