Menu

ParsNIP home

Tanya Hutton
Attachments
ptrac_example.png (77858 bytes)

The ParsNIP tool allows MCNP users to parse most PTRAC files into an easier to handle format. It can interpret source, banked, surface, collisions and termination events and outputs the relevant variables associated with each event into a text file, where one line corresponds to one event with various event variables included. This has been developed with references from all the MCNP5 manual volumes, though the main contributors are from Appendices E, I and Section 3.J.9 (page 3-152).

PTRAC format

The PTRAC format can be daunting, particularly with the unique style of documentation given in the MCNP manual. The basic set-up is as follows (taken from Table 1 in Appendix I of the MCNP5 manual):

Line number Description Fortran format
1 -1 (i5)
2 Code, version, load date, machine date and time. (a8,a5,a8,a19)
3 Problem title (a80)
4 Input block (K x lines) (1x,10e12.4)
4+K Number of variables for each line type, i.e. NPS, Event 1 and Event 2 (1x,20i5)
5+K Variable IDs for each line type (M x lines) (1x,30i4)
5+K+M First NPS line (1x,5i,e13.5)
6+K+M First Event 1 line (Q x lines) (1x,8i10)
7+K+M First Event 2 line (Q x lines) (1x,9e13.5)
7+K+M+2Q Second NPS line, process repeats until end of file (1x,5i,e13.5)

Event IDs

There are 5 event types, with one additional identifier flag that can be used in PTRAC output:

Event number Description Notes
1000 Source (SRC) Birth of particle
±(200N) Banked (BNK) Negative for rejected banked events, N determines the source of banked event
3000 Surface (SUR) Particle crosses cell boundary
4000 Collision (COL) Interaction event
5000 Termination (TER) Death of particle
9000 End of history Flag to identify final event in history

PTRAC Example

This example shows a colour coded section from the start of a PTRAC file, with line numbers in grey. The colour here is simply used to differentiate between different parts of the file.

  • Lines 1-3 contain the general information as described in the table above
  • Lines 4-7 contain the input data from the PTRAC card used in the MCNP run (in this case K=4)
  • Line 8 contains the number of variables expected for each line type and each event type, i.e NPS line and Event1 and Event2 lines for SRC, BNK, SUR, COL, TER
    • The remaining two variables correspond to the transport particle type (1 for neutron etc. or 0 for multiple particle transport), and whether the output is given in real*4 or real*8
  • Lines 9-11 contain the variable IDs corresponding to each line type, the number of which is governed by line 8 contents, i.e the first 3 variable IDs correspond to the NPS line, the next 6 correspond to the first SRC line and the next 9 correspond to the second SRC line
  • Line 12 is the first NPS line, with reference to the variables IDS given on lines 9-11, the three values on this line correspond to IDs 1, 2 and 3 or NPS, initial event type and cell number. (See Table on variable IDs below for full list of definitions.)
  • Line 13 corresponds to the event type dictated by the NPS line (in this case 1000 = SRC), and has values corresponding to IDs 7, 8, 9, 17, 18, 19 or next event type, node, nearest surface number, source identifier, problem cell, material number and number of collisions in path.
  • Line 14 is the second event line, and contains the IDS 20-28, or x, y, z, u, v, w, energy, weight and time corresponding to the event described by line 13.
  • These two line types repeat, with the variables given changing depending on event type until we reach the end of the history for PTRAC output. This is designated by the 9000 event flag as seen on line 27, In this case the particle has had a surface event (3000) and then left the area of interest for the geometry.
  • The next history would then start with an NPS line, followed by the two event lines for all relevant events in history etc.

The code

ParsNIP is written in C and only tested with the gcc compiler. It reads an initial input deck, parses the ascii PTRAC file and stores events in memory before the events are filtered to write to an output text file, which can then be further processed as required. The code has been compiled and tested on Mac OSX, and has not been thoroughly tested on other operating systems. ParsNIP expects a file structure that has a main home directory with the relevant directories within:

  • Home/
    • ip_test - test input deck
    • ptrac_test - test PTRAC input
    • out_test - test output (to cross check)
    • lookup_tables - various tables of variables + descriptions
    • parsnipOSX - pre-compiled executable for Mac OSX
    • src/
      • main.c - main parser code
      • lookup.c - lookup tables for various parameters
      • main_h.h - definitions and struct

Input files

The code requires certain variables to be set via the input deck, this can either be input as a file (ip_test) or at runtime. The variables required are:

  • main_path - path to home directory
  • ip_name - name of PTRAC file to parse
  • op_name - name of output file (will overwrite so use caution here)
  • write - write option on PTRAC card
  • n_iplines - number of input lines in PTRAC header
  • mt - filter for reaction type (MT number from ENDF)

If any lines within the input file start with the # character, the line is taken to be comment.

Compiling and running

To compile with gcc from initiate a bash shell from the home directory and use:
gcc src/*.c -lm -o parsnip
To execute use:
./parsnip ip_test

This will parse the file as designated in the input deck, in ip_test, this corresponds to ptrac_test within the ptrac_files directory. If all paths and permission are set up correctly all should run as expected and parse the PTRAC file.

Output

There are two output streams for ParsNIP. The first being the the shell, this contains run-time information on parsing the file. This contains the information extracted from the header sections of the PTRAC:

  • Echo input deck
  • Opens PTRAC file
  • Writes lookup tables to file
  • Parsed input header
  • Parsed number of variables expected per line
  • Parsed variable IDs for each line type
    • See file: lookup_tables for more info.
  • Print counters for number of lines, events and histories parsed
  • Any banked events are printed to screen
  • Output file

The second output stream is to the output file that contains all the data concerning parsed events. The output variables are determined by the write option in the input deck. These (for the most part) correspond to the MCNP variable definitions. A guide to the output variables is shown below.

Variable Definition Notes
NPS History number
COUNT Event number within history
TYPE Source, banked, surface, collision or termination
NXS ZZAAA for event COL and BNK events only
NTYN Reaction type (MT number) COL and BNK events only
NSF Surface crossing SUR event only
ANG Angle with surface normal (degrees) SUR event only
NTER Termination type TER event only
BRANCH Branch number for history TER event only
NCL Cell number
MAT Material number
NCP Number of collisions to event from source
X, Y, Z Co-ordinates of event (cm)
U, V, W Unit vector for direction after event write=all only
ERG Energy after event (MeV) write=all only
WGT Particle weight after event write=all only
TME Event time(shakes) write=all only

Additional variable definitions

Input variables

Keyword Description
BUFFER Storage available for filtered events
CELL Filter based on cell
EVENT Filter based on event type
FILE File type (ascii/binary)
FILTER Additional filters
MAX Maximum number of events to write
MEPH Maximum events per history
NPS Filter based on history number
SURFACE Filter based on surface
TALLY Filter based on tally
TYPE Filter based on particle type
VALUE Tally cutoff above which events are written
WRITE Control what events are written to PTRAC

Filter variables

Filter index Mnemonic Description
1 X X-coordinate of particle position(cm)
2 Y Y-coordinate of particle position(cm)
3 Z Z-coordinate of particle position(cm)
4 U X component of particle direction
5 V Y component of particle direction
6 W Z component of particle direction
7 ERG Particle energy (MeV)
8 WGT Particle weight
9 TME Time at particle position (shakes)
10 VEL Speed of particle (cm/shake)
11 IMP1 Neutron cell importance
12 IMP2 Photon cell importance
13 IMP3 Electron cell importance
14 ICL Problem number of current cell
15 JSU Problem number of current surface
16 IDX Number of current DXTRAN sphere
17 NCP Number of collisions for current branch
18 LEV Geometry level of particle position
19 III 1st lattice index of particle position
20 JJJ 2nd lattice index of particle position
21 KKK 3rd lattice index of particle position

Variable IDs

Taken from Table I.3 in MCNP5 manual, Appendix I with descriptions and notes as an interpretation of the relevant sections of the manual.

ID number MCNP name Description Notes
NPS line
1 NPS History number All NPS lines
2 Type of first history event SRC, BNK, SUR, COL, TER
3 NCL Cell number Omitted if not cell filtered
4 NSF Nearest surface headed towards Omitted if not surface filtered
5 JPTAL Tally specifier Omitted if not tally filtered
6 TAL TFC specifier Omitted if not tally filtered
Event1 line
7 Next event type BNK, SUR, COL, TER, END
8 NODE Number of nodes in track from source to this point
9 NSR Source number SRC events only
10 NXS ZZAAA for interaction BNK and COL events only
11 NYTN Reaction type (MT from ENDF) BNK and COL events only
12 NSF Surface number SUR events only
13 Angle with surface normal (degrees) SUR events only
14 NTER Termination type TER events only
15 Branch number TER events only
16 IPT Particle type Multi-particle transport only
17 NCL Cell number All events
18 MAT Material number All events
19 NCP Number of collisions in history Write=all only
Event2 line
20 XXX x-coordinate of event (cm) All events
21 YYY y-coordinate of event (cm) All events
22 ZZZ z-coordinate of event (cm) All events
23 UUU x-component of exit direction vector Write=all only
24 VVV y-component of exit direction vector Write=all only
25 WWW z-component of exit direction vector Write=all only
26 ERG Energy of particle after event Write=all only
27 WGT Weight of particle after event Write=all only
28 TME Time of event Write=all only