f4enix.output.MCNPoutput.Output#

class f4enix.output.MCNPoutput.Output(filepath: PathLike | str)#

Bases: object

Object representing and MCNP output file

Parameters:

filepath (os.PathLike | str) – path to the output file to be parsed

Variables:
  • filepath (os.PathLike) – path to the original output file

  • name (str) – name of the original file

  • lines (list[str]) – list of all the lines of the file

Examples

>>> from f4enix.output.MCNPoutput import Output
... # parse the output
... outp = Output('test.o')
... # print excel and .vtk file containing info on lost particles
... outp.print_lp_debug('outfile_name')
... # Get the results of the statistical checks for a specific tally
... outp.get_tally_stat_checks(46)
                        mean behaviour    rel error      rel error  ...
                                            value         decrease  ...
TFC bin behaviour
desired                   random           <0.10               yes  ...
observed                decrease            0.03               yes  ...
passed?                       no             yes               yes  ...

This tables are produced only if the bins have non-zero values and refer to the total bin. These results, combined with a summary check on all tally bins are used to compile the total summary table

>>> # Get the total summary table
... outp.get_stat_checks_table()
            mean            rel error                        TFC
            behaviour        value          ...             bins
Cell
2              yes           yes            ...            Passed
4              NaN           NaN            ...         All zeros
6              NaN           NaN            ...         All zeros
12             yes           yes            ...            Passed
14             NaN           NaN            ...         All zeros
24             NaN           NaN            ...         All zeros
34             NaN           NaN            ...         All zeros
22             yes           yes            ...            Passed
32             yes           yes            ...            Passed
44              no           yes            ...            Missed
46              no           yes            ...            Missed
104             no           yes            ...            Missed

Get an MCNP table from the output file in a pandas DataFrame format:

>>> outp.get_table(60)
                 cell   mat       ... photon wt generation
2       1.0       1          0    ...   -1.000E+00
3       2.0       2          1    ...   -1.000E+00
4       3.0       3          0    ...   -1.000E+00
5       4.0       4          0    ...   -1.000E+00

Methods

__init__(filepath)

Object representing and MCNP output file

assign_tally_description(stat_checks, tallylist)

Include the tally descriptions in the statistical checks dictionary.

get_LPR()

Get the lost particle ratio

get_NPS([particle])

Get the number of particles simulated.

get_code_version()

get_fatal_errors()

Get the fatal errors from the output file.

get_lp_debug_df([get_cosine, input_mcnp])

Generates a pandas DataFrame with the lost particles information.

get_stat_checks_table()

get a table summarizing the 10 statisical checks results for each tally.

get_statistical_checks_tfc_bins()

Retrieve the result of the 10 statistical checks for all tallies.

get_table(table_num[, instance_idx])

Extract a printed table from the MCNP output file.

get_tally_stat_checks(tally)

Get the table of statistical checks for a specific tally

get_tot_lp()

Get the total lost particle number

get_warnings([collapse])

Get the warnings from the output file.

print_lp_debug(outpath[, print_video, ...])

prints both an excel ['LPdebug_{}.vtp'] and a vtk cloud point file ['LPdebug_{}.vtp'] containing information about the lost particles registered in an MCNP run.

assign_tally_description(stat_checks: dict[int, str], tallylist: list[Tally], warning=False) dict[str, str]#

Include the tally descriptions in the statistical checks dictionary.

Parameters:
  • stat_checks (dict[int, str]) – A dictionary of the statistical checks results. It should come from the method get_statistical_checks_tfc_bins.

  • tallylist (list[Tally]) – Tallies list where to put the descriptions.

  • warning (bool, optional) – Check for the actual presence of a tally description, by default False

Returns:

Statistical checks dictionary with the tally descriptions

Return type:

dict[str, str]

get_LPR() float#

Get the lost particle ratio

Returns:

lost particle ratio

Return type:

float

get_NPS(particle: str = 'neutron') int#

Get the number of particles simulated.

Parameters:
  • particle (str) – source particle to be looked for. The trigger for founding

  • is (the correct table will be '{particle} creation'. The default)

  • 'neutron'.

Returns:

number of particles simulated

Return type:

int

get_fatal_errors() list[str]#

Get the fatal errors from the output file.

Returns:

list of fatal errors

Return type:

list[str]

get_lp_debug_df(get_cosine: bool = True, input_mcnp: Input | None = None) DataFrame#

Generates a pandas DataFrame with the lost particles information.

get_stat_checks_table() DataFrame#

get a table summarizing the 10 statisical checks results for each tally.

one row per tally, one column per statistical check. An extra column is added that report the results of the statistical checks in all other TFC bins.

Returns:

summary of the statistical checks results.

Return type:

pd.DataFrame

get_statistical_checks_tfc_bins() dict[int, str]#

Retrieve the result of the 10 statistical checks for all tallies. They are registered as either ‘Missed’, ‘Passed’ or ‘All zeros’ in a dictionary indicized using the tallies numbers.

Returns:

stat_checks – keys are the tally numbers, values the result of the statistical checks.

Return type:

dict[int, str]

get_table(table_num: int, instance_idx: int = 0) DataFrame#

Extract a printed table from the MCNP output file.

All tables should be accessible from their MCNP index.

Parameters:
  • table_num (int) – MCNP table index

  • instance_idx (int, optional) – Some tables with the same table_num may appear multiple times in the output file. This parameter allows to select which instance of the table to return. It allows negative indexing, where the numbering starts from the end of the file. For example, -1 will return the last instance of the table.

Returns:

parsed table

Return type:

pd.DataFrame

Raises:

ValueError – If the table associated to the requested index is not found

get_tally_stat_checks(tally: int) DataFrame#

Get the table of statistical checks for a specific tally

Parameters:

tally (int) – index of the cell to be parsed

Returns:

table reporting the results of the statistical checks

Return type:

pd.DataFrame

Raises:

ValueError – if the cell is not found in the file.

get_tot_lp() int#

Get the total lost particle number

Returns:

total lost particle number

Return type:

int

get_warnings(collapse: bool = True) DataFrame#

Get the warnings from the output file. Repeated warnings are counted.

Parameters:

collapse (bool, optional) – if True, some warnings will be grouped by type, by default True.

Returns:

list of warnings

Return type:

pd.DataFrame

print_lp_debug(outpath: PathLike, print_video: bool = False, get_cosine: bool = True, input_mcnp: Input | None = None) None#

prints both an excel [‘LPdebug_{}.vtp’] and a vtk cloud point file [‘LPdebug_{}.vtp’] containing information about the lost particles registered in an MCNP run. A .csv file is also printed with origin and flight direction of each lost particle.

Parameters:
  • outpath (os.PathLike) – path to the folder where outputs will be dumped.

  • print_video (bool, optional) – if True print the LP to video. deafult is False

  • get_cosine (bool, optional) – if True recover also the cosines of the flight direction of each lost particle. By default is True

  • input_mcnp (Input, optional) – Input file that generated the MCNP output. Providing this will ensure that also the universe in which the particles are lost will be tracked. By default is None.