pirs.mcnp subpackage

This package provides a low-level interface to the MCNP5 code.

It defines classes to represent cells, surfaces, materials and tallies. There is also a class representing the MCNP model as a collection of cells, surfaces, materials, etc; this class takes the task of setting cell, surface and material numbers (IDs) and has methods to generate valid MCNP input file. Moreover, there is a class that describes a workplace – a directory that contains all files necessary to start MCNP job and there is a method to start MCNP executable. Also, functions to read MCNP-generated files, are defined in this package.

Note

In contrast to the low-level interface, the high-level interface translates the code-independent geometry described with the help of the pirs.solids package into the low-interface MCNP model instance, and puts back results of MCNP run, read by the low-level interface methods, back to the code-independent geometry.

An MCNP model is represented by the pirs.mcnp.Model class. It consists of instances of the pirs.mcnp.Cell class, each reffering to a material represented by the pirs.mcnp.Material and with geometry defined by instances of the pirs.mcnp.Surface and pirs.mcnp.Volume classes.

Materials

The pirs.mcnp.Material class is used to represent material composition, temperature and optional use of thermal data. It inherits the pirs.core.tramat.Mixture, described in details in pirs.core.tramat subpackage. Here we overview only MCNP-related features, added to the pirs.mcnp.Material class.

Frist of all, this class can take information about available cross-sections from an xsdir file. The pirs.mcnp.Material.xsdir attribute is an instance of the pirs.mcnp.Xsdir class able to read xsdir file and to store information. By default, each material instance is supplied with an xsdir containing data from $DATAPATH/xsdir file.

The pirs.mcnp.Material.card() method generates a multi-line string containing the material card describing the material in the MCNP input file. When the card() method is called, cross-sectin data sets are searched in the specified xsdir object for each nuclide and for the temperature specified in the pirs.mcnp.Material.T attribute. If a cross-section data set for particular nuclide and particular temeprature is found, its suffix is used in the card. If there is no cross-section data exactly at the temperature T, two cross-sections are found with temepratures above and below T, and both suffices enter the material card.

from pirs.mcnp import Material

fe = Material('Fe') # Fe chemical element with nat. occuring isotopes

for T in [300, 350 ,400]:
    fe.T = T
    print fe.card()
m{0:<}                                                                            $  Fe at 300 K 
     26054.31c  5.84500e-02
     26056.31c  9.17540e-01
     26057.31c  2.11900e-02
     26058.31c  2.82000e-03
m{0:<}                                                                            $  Fe at 350 K  as mix 0.482 300.00 K,  0.518 400.01 K
     26054.31c  2.81792e-02   26054.32c  3.02708e-02
     26056.31c  4.42353e-01   26056.32c  4.75187e-01
     26057.31c  1.02159e-02   26057.32c  1.09741e-02
     26058.31c  1.35954e-03   26058.32c  1.46046e-03
m{0:<}                                                                            $  Fe at 400 K 
     26054.32c  5.84500e-02
     26056.32c  9.17540e-01
     26057.32c  2.11900e-02
     26058.32c  2.82000e-03

In this example, a material representing Iron with natural isotopic abundancies is created and material card corresponding to temepratures 300, 350 and 400 K is printed. Default xsdir, read from $DATAPATH/xsdir file is used to find cross-section suffices. As one can note, cards cannot be used directly in the MCNP input file, since material numbers are not given explicitly, there are format placeholders instead.

For temperatures 300 and 400 K data for all Fe isotopes exist in the xsdir and denoted by suffices 31c and 32c (this example uses xsdir file from the multi-temperautre data set JEFF-3.1).

For the material at 350 K, both suffices are used in proportions defined by the material temeprature and temeratures of available cross-sections. How these proportions are computed, depends on the pirs.mcnp.Material.Tif attribute that by default set to the pirs.mcnp.auxiliary.xs_interpolation.sqrT() function that implements the square-root temperature interpolation, but can be changed by the user to anything else.

Use of thermal data is controlled by the pirs.mcnp.Material.thermal attribute. By default it is None and no thermal data is used. When this attribute is set to a string, thermal data with names containing this string will be searched in the xsdir file and, if found, will be mentioned in the mt card corresponding to the material. If there are more than one thermal data set, the set with the closest temeprature will be chosen.

from pirs.mcnp import Material

h = Material('H')
o = Material('O')

h2o = 2*h + o

# thermal data
h2o.thermal = 'lwtr'

# nuclide substitution
h2o.sdict[8018] = 8016

for t in [300, 350, 400]:
    h2o.T = t
    print h2o.card()
m{0:<}                                                                            $  H-O at 300 K 
     1001.31c  1.99977e+00
     1002.31c  2.30000e-04
     8016.31c  9.97570e-01
     8017.31c  3.80000e-04
     8016.31c  2.05000e-03
mt{0:<} lwtr01.31t                                                                $  thermal data at 293.606K
m{0:<}                                                                            $  H-O at 350 K  as mix 0.482 300.00 K,  0.518 400.01 K
     1001.31c  9.64104e-01   1001.32c  1.03567e+00
     1002.31c  1.10885e-04   1002.32c  1.19115e-04
     8016.31c  4.80936e-01   8016.32c  5.16634e-01
     8017.31c  1.83201e-04   8017.32c  1.96799e-04
     8016.31c  9.88320e-04   8016.32c  1.06168e-03
mt{0:<} lwtr03.31t                                                                $  thermal data at 373.607K
m{0:<}                                                                            $  H-O at 400 K 
     1001.32c  1.99977e+00
     1002.32c  2.30000e-04
     8016.32c  9.97570e-01
     8017.32c  3.80000e-04
     8016.32c  2.05000e-03
mt{0:<} lwtr04.31t                                                                $  thermal data at 423.599K

In this example, the material h2o is created. Thremal data for hydrogen bound in water are all named lwtr??.31t in the default xsdir file. To use them, we set the thremal attribute to the common part of the names, which is 'lwtr'. Depending on the material temperature, particular data set is chosen. Note that thermal cross-sections are not interpolated. Note also that both m and mt cards followed by the format placeholder with the same index, to ensure that both cards will correspond to the same material.

Another feature shown in this example is the pirs.mcnp.Material.sdict attribute. This dictionary specifies substitution rules for cases when particular nuclide cannot be found in the xsdir file. Particularly, the default xsdir file contains no cross-section data for nuclide 8018, which however, enters to the h2o material since it was defined using natural isotopic composition of oxygen. Without specifying the substitution rule, the call to the card method would result in error. With the help of sdict we can avoid this error.

Surfaces and volumes

There are two classes to describe geometry of an MCNP model.

The pirs.mcnp.Surface class is a container for data to describe an MCNP surface. It can hold data for both simple surfaces and macrobodies, ‘knows’ about the order of facets for macrobodies, can generate the surface card for the MCNP input file.

from pirs.mcnp import Surface

s1 = Surface('px 1.0 $ a plane')
s2 = Surface('* pz 5.1')

s3 = Surface(type='c/z', plst=[0, 0, 6], cmnt='cylinder at z axis')
s4 = Surface('rcc 0 0 0  0 0 5  3')

#surface cards
for s in [s1, s2, s3, s4]:
    print s.card()
{0} px  1.0                                                                       $   a plane
*{0} pz  5.1
{0} cz  6.0                                                                       $  cylinder at z axis
{0} rcc  0.0  0.0  0.0  0.0  0.0  5.0  3.0

Surface parameters can be specified in two ways: the surface class constructor accepts surface cards (so it can be used as a parser), or surface type, list of parameters, reflection etc. can be specified as keyword arguments. At the initialization surfaces are simplified, when possible, as shown for surface s3. The surface card generated by the pirs.mcnp.Surface.card() method is a formatting string with placeholder for the surface ID number.

A surface separates the space into two volumes, ‘above’ and ‘below’. Representation these volumes and operations of union and intersections are implemented in the pirs.mcnp.Volume class. The constructor of this class takes two arguments: the first argument specifies part of the space (1 means ‘above’ and -1 – ‘below’), the second argument defines the surface. The main functionality of the volume class is to provide operations of union and intersection and to represent these operations in terms used in the MCNP input file; it should be noted however, that result of these operations is not evaluated. Thus, the second argument must not necesserily be an instance of the pirs.mcnp.Surface class, one can use abstract string names.

from pirs.mcnp import Volume

v1 = Volume(1, 'a')  
v2 = Volume(1, 'b')
v3 = Volume(-1, 'c')

# new volume as intersection and union
r = v1 & v2 | v3

# string representation of volume
print ' r: ', r
print '-r:', -r

# surface definition substitution
s = {}
s['a'] = 1
s['b'] = 2
s['c'] = 3

print ' r: ',  r.copy(s)
print '-r: ', -r.copy(s)
 r:  (a b):-c
-r: (-a:-b) c
 r:  (1 2):-3
-r:  (-1:-2) 3

String representation of a volume uses the space for intersection and the colon for union, and can therefore be used in the description of cell geometry in the MCNP input file, if surface ID numbers are used as abstract surface definitions. One can also use volumes with arbitrary (not necesserily integer) surface definitions together with the pirs.mcnp.Volume.copy() method. Optional argument of this method must be a mapping (function or dictionary) that will replace original surface defition in the returned copy.

This, for the first glance over-engineering approach allows to use macrobodies to define geometry and then, if necessary (for example, when different boundary conditions must be set to facets of a macrobody), to represent this geometry in the MCNP input file using simple surfaces. The following example illustrates this:

from pirs.mcnp import Surface

c = Surface('rcc 0 0 0   0 0 10  4')

# mapping surface -> ID
l = []
for f in c.facets():
    l.append(f.a1[1])
m = lambda s: l.index(s) + 1

# macrobody exterior defined by simple surfaces
v = c.volume(m)
print ' c cells'
print '1 0 ',  v, ' $ cylinder exterior'
print '2 0 ', -v, ' $ cylinder interior'

print ''
print 'c surfaces:'
for s in l:
    print str(s).format(m(s))
 c cells
1 0  1:2:-3  $ cylinder exterior
2 0  -1 -2 3  $ cylinder interior

c surfaces:
1 cz  4.0
2 pz  10.0
3 pz  0.0

The c surface is a cylinder macrobody. Its pirs.mcnp.Surface.facets() method returns a list of volumes ‘above’ each macrobody’s facet. The pirs.mcnp.Volume.a1 attribute of a simple volume (i.e. defined directly by the class constructor, not as union or intersection) returns the constructor arguments, thus the second element of this attribute is the surface definition. In the loop all surfaces are collected into the list l that is used to map each surface instance to an integer number, see function m. The pirs.mcnp.Surface.volume() method returns a volume representing the macrobody’s exterior in terms of simple surfaces. It is used in the example to generate geometry description of cells representing both interior and exterior of the macrobody. Using the same mapping, we generate the surface cards, thus ensuring that surface IDs in the surface cards block is consistent with description of cells.

In this example, we defined explicitly the mapping to set surface IDs. This was done as illustration, there are other means to set automatically surface, cell and material numbers, see below.

Warning

The low-level interface was developed keeping in mind rather simple geometries that can be described by vertical cylinders and boxes with facets perpendicular to the coordinate axes. Therefore, only vertical cylinder macrobodies (i.e. parallel to the 3-rd coordinate axis) will be handled properly, although no parameters check is done at the initialization time.

Cells and models

The pirs.mcnp.Cell class represents a container that stores cell-related information: material, geometry and cell options. Cell geometry must be specified using the Volume and Surface classes, and material – useing the Material class. Cell options (e.g lat, fill, imp:n etc.) are specified using the pirs.mcnp.Cell.opt attribute, which is a dictionary with only particular keys allowable (see CellOpts class). Although there is a method to generate cell cards for the MCNP input, pirs.mcnp.Cell.card(), its direct use makes no sense, sinse one still needs to specify durface, cell and material IDs.

from pirs.mcnp import Material, Surface, Cell, Model

c1 = Cell()

# Cell 1 
c1.mat = Material('Fe')
c1.rho = -10.
c1.vol = Surface('so 8.0').volume()
c1.opt['imp:n'] = 1

# Cell 2
c2 = Cell()
c2.vol = -c1.vol

# direct use of cells
print c1.card()
print c2.card()

# cells in a model
m = Model()
m.cells.append(c1)
m.cells.append(c2)

for c in m.cards():
    print c
{ID} {mat} {rho} {geom} imp:n=1                                                   $  comment
{ID} 0  {geom} imp:n=0                                                            $  comment
MESSAGE:  datapath=/home/local/KIT/rx8040/data/mcnp/all_jeff

c title
1 1 -10.0 1 imp:n=1                                                               $  comment
2 0  -1 imp:n=0                                                                   $  comment

c surfaces
1 so  8.0

c data cards
c materials
m1                                                                                $  Fe at 300.0 K 
     26054.31c  5.84500e-02
     26056.31c  9.17540e-01
     26057.31c  2.11900e-02
     26058.31c  2.82000e-03
c tallies
c kcode 500  1.0  20  100  j  j  100000  j 
prdmp j j 1                                                                       $  write mctal file

In this example, neither material nor geometry is resolved when cells c1 and c2 are printed directly, sinse there is no rule to set material and surface IDs. This task is accomplished by the pirs.mcnp.Model class that is basically a list of cells. Cells describing the model are added to the pirs.mcnp.Model.cells list attribute. When converting to a string, or as in the example, when calling the pirs.mcnp.Model.cells() method, all cells in the model are analysed: IDs are set to unique materials and surfaces thus providing information for the cell, surface and material cards.

Setting of IDs for surfaces and materials is done with the help of the pirs.mcnp.SurfaceCollection and pirs.mcnp.MaterialCollection classes. They both have the index() method, which takes as argument a surface or material instance, adds it to the collection if it is not already there, and returns its index, which was attached to this particular instance when it was added to the collection.

Start MCNP

To manually add cards to the automatically generated input files, there are Model.amc, Model.acc, Model.asc and Model.adc list attributes containing strings that will be added to the message, cell, surface or data blocks. In this way one can define the source distribution or add manually cells.

The MCNP code can be started on the input file. The Model.wp attribute is an instance of the pirs.mcnp.McnpWorkPlace that can be used to specify directory names where the input file will be written and MCNP code started. The Model.run() method prepares all necessary files and can be used to start MCNP in different modes (neutron transport, plot geometry).

TODO: example showing work with Model.wp and Model.run().

Docstrings

class pirs.mcnp.Xsdir(path=None)

Container for data from xsdir file.

Data can be added manually or read from existing file.

awr

Property represents the ‘atomic weight ratios’ section of xsdir file. This is a dictionary: keys are ZAIDs, values are nuclide masses in terms of awr.

clear()

Removes data from awr, dir and path.

datapath

Returns path to the xsdir file, if the data in the xsdir intance was read from a file.

classmethod default()

Default system xsdir file.

Returns an instance of the Xsdir class containing data from the $DATAPATH/xsdir file.

dir

A list whose elements represent lines from the directory section of the xsdir file. Elements are instances of the DirEntry() class.

filename

Returns the name of the xsdir file, if the data in the xsdir instance were read from a file.

find_thermal(namepart, T)

Returns the name of thermal data containing string namepart, closest to temperature T (in K).

read(path, append=False)

Read existing xsdir file.

The path argument specifies relative or absolute path to the xsdir file.

If the optional argument append is True, data read from the xsdir file are appended to the data allready stored in the instance of Xsdir(). Otherwise, the clear() method is called before reading the file.

suffix(ZAID, T=None, xstype='c', smin=None, smax=None)

Find suffices of the cross-section data of type xstype describing ZAID at temperature T. T must be specified in Kelvin.

Two suffices are returned, for cross-sections at temperatures closest to T, below and above T.

If smin or smax are specified, they define interval of suffixes that are searched for the closest temperature.

The returned value is always a list of two tuples, in the form [(T1, S1), (T2, S2)], where T1 and T2 are cross-section temperatures below and above T, and S1 and S2 are the correspondent suffices.

If T is not specified, T1 and S1 are parameters of the first cross-section data found in the directory section for nuclide defined by ZAID. In this case, T2 and S2 are the same as T1 and S1.

class pirs.mcnp.Material(*args)

Object-oriented representation of material composition for MCNP.

Constructor arguments are passed to the constructor of the parent class, see description of available arguments there.

One can setup material composition, temperature and specify xsdir file, which is used to find cross-section data suffixes.

T

Temperature of material, K

Material temperature is used to find proper suffix (or the pair of suffices) in xsdir file.

It is also used to find the most close thermal data, if the self.thermal attribute is specified.

Tif

Tempareture interpolating function.

A function that takes as arguments temperatures T, T1 and T2, and returns fractions f1 and f2 of cross-sections evaluated at temperatures T1 and T2 used to represent a material at temperature T. It must have the following signature:

f1, f2 = func(T, T1, T2)

This function is used when the temperature of material is set to a value than cannot be found in the xsdir file. In this case, each isotope of the material at temperature T is represented as a mixture of two, at temperatures T1 and T2. The temperatures T1 and T2 are found in xsdir automatically, being the closest to T from below and above.

Note that values T1 and T2 are usually defined from the xsdir file, where temperature is given originally in MeV (as kT), and the material temperature T is given in Kelvin. Thus, even if one specifies T as “a temperature from xsdir”, it will not much T1 or T2 exactly. To avoid unnecessary cross-section data in the material specification, the user is responsible to provide the logic inside func to set f1 or f2 exactly to 1.0 or to 0.0 even if T does not match exactly, but is close to T1 or T2.

Cross sections at temperature T1 and T2 appear in the material specification only if the correspondent fraction, f1 or f2, is nonzero.

By default, the auxiliary.xs_interpolation.sqrT() function is used, which describes the sqrt(T) interpolation.

card(formatted=True, suffixes=True, smin=None, smax=None)

Returns a multi-line string with the material cards for MCNP input.

The returned string generally represents two cards, m and mt.

The formatted optional argument defines if the lines in the string are wrapped to fit to 80 characters.

The suffixes optional argument defines if suffixes for particular cross-section sets are printed or not.

Optional parameters smin and smax can take integer values. If they are specified, only cross-sections with suffix numbers satisfying smin <= XX <= smax are returned.

The material number is NOT defined explicitly, there is just a placeholder for it. Use the format() method of the returned string to put particular material ID:

>>> m = Material(1001)
>>> print m.card().format(1)   # put 1 as material number
m1 $ mixture  H-001 at 300.0 K 
       1001.31c 1.0000000e+00
fmt

Dictionary of format strings used to generate card representation of the material.

The following keys have sense:

‘zaid’: format string for ZAIDs ‘fraction’: format string for fraction.

If explicit field index is used (for Python versions < 2.6), it should be set to 0.

sdict

Substitution dictionary.

A dictionary of the form {ZA1:za1, ZA2:za2, ...}, where ZAi and zai are integer numbers representing ZAIDs.

If a nuclide with ZAID ZAi is not found in xsdir, it is substituted with cross-sections for nuclide zai.

By default, there is no substitutions, the dictionary is empty.

thermal

Part of the cross-section data set name for thermal scattering.

When this property is given, the string representing material in the MCNP input file, contains additionaly to m card also mt card. The xsdir file is searched for thermal data with names containing thermal as a substring. If several data sets are found, the one with the closest temperature is chosen.

xsdir

Instance of Xsdir() class.

Suffices to represent material in the MCNP input are defined based on the content of this xsdir file and value of attribute T.

This property can be set to a string, in which case this string should represent path to existing xsdir file, or to an instance of the Xsdir() class.

class pirs.mcnp.Surface(card=None, **kwargs)

MCNP surface.

Instances are immutable.

The constructor takes a string with usual definition of a surface as appears in an input file, except the surface ID. Alternatively, parameters of a surface can be specified as keyword arguments.

Parameters:
  • card (str) – is a string representing the surface card of the MCNP input, except the surface number should not be specified, for example '+ px 1.0'.
  • type (str) – a string representing the surface type, for example ‘px’.
  • refl (char) – a character representing the reflection of the surface, for example ‘*’.
  • plst (list) – a list or tuple of parameters of the surface.
  • cmnt (str) – a string representing the surface comment.
MBTYPES = ['rpp', 'rcc']

Known macrobody surfaces

PRECISION = 9

Precision of surface parameters. Parameters rounded to this number of digits when printed to the card or when two surfaces are compared.

SSTYPES = ['px', 'py', 'pz', 'cz', 'c/z', 'so', 's']

Known simple surfaces

card(formatted=True)

Returns string representing the surface, valid for an MCNP input file, except the surface ID.

If optional argument formatted set to True (default), the returned string can contain new-line characters, so that the lines fit to 80-characters limit required by the MCNP input file syntax.

This method is used to transform an instance of the Surface() class to a string.

facets(mapp=<function <lambda> at 0x2add5e5f4398>)

Returns the list of volumes for each facet of the surface.

Parameters:mapp (func) – a mapping applied to the facets before passing to the Volume() constructor.
Returns:list of volumes.

If the surface is a simple surface, the returned list contains single element.

is_macrobody()

Returns True if the surface is a macrobody.

prm

The tuple of surface parameters.

rfl

Reflection of the surface. Can be '' (empty string), '*' or '+'.

tpe

Type of the surface, for expample, 'px'

volume(mapp=<function <lambda> at 0x2add5e5f4230>)

Volume ‘above’ the surface.

Parameters:mapp (func) – a mapping applied to the surface facets before passing to the Volume() constructor.
Returns:an instance of the Volume class. The Volume() class defines operations of union, intersect and nagation.

Instances of the Volume() class returned by this method are always defined via simple (not macrobody) surfaces. To get an instance of the Volume() class defined via a macrobody surface, use the constructor Volume() directly.

class pirs.mcnp.Volume(sign=1, surface=None)

Representation of the cell geometry using signed surfaces and union, intersection and negation operations.

A new volume instance is created by specifying the sign and the surface description. The surface description can be of any type (although in real MCNP applications, an instance of the Surface class must be used):

>>> v1 = Volume(1, 'a')  # 'a' here is an abstract surface definition 
>>> print v1
a

There are two special volumes representing by tuples (1,) and (-1,). The first means ‘empty set’, the second is ‘whole space’. To create the emtpy set, multiply usual volume by 0. To create whole space, multiply empty set by -1:

>>> e = Volume()*0   # empty set
>>> print e
Empty Set
>>> w = -e           # whole space
>>> print w
Whole space

Instances of the Volume() class support operations of union ‘|’, intersection ‘&’ and negation ‘-‘.

a

Returns the list of operands, [self.a1, self.a2].

a1

Returns the first operand of the volume, if the volume was defined using intersection or union operators. For a simple volume, i.e. defined directly by the Volume() constructor, this is a tuple (sign, surface).

>>> v = Volume(1, 'a')
>>> v.a1
(1, 'a')
>>> v = Volume(1, 'a') & Volume(1, 'b')
>>> v.a1                               
<__main__.Volume object at ...>
a2

Returns the second operand of the Volume class, if the volume was defined using union or intersection. For a simple Volume returns 0.

>>> Volume(1, 'a').a2
0
>>> (Volume(1, 'a') & Volume(1, 'b')).a2    
<__main__.Volume object at ...>
copy(mapp=<function <lambda> at 0x2add5e5f4d70>)

Returns a (deep) copy of the volume.

The returned volume has the same structure as the original one. The surface definitions are defined using the mapping mapp applied to the original surface definitions.

UPD: mapp can be a dictionary.

Lets create a complex volume:

>>> v = Volume(1, 'a')
>>> for c in ['b', 'c']:
...     v = v & Volume(-1, c)
...     v = v | v
...
>>> print v
(((a -b):(a -b)) -c):(((a -b):(a -b)) -c)

A copy of v with the upper() method of a string upplied:

>>> print v.copy( lambda x: x.upper() )
(((A -B):(A -B)) -C):(((A -B):(A -B)) -C)
intersection_operands()

If a volume is an intersection of simple or compound volumes, returns two lists.

The first contains simple volumes, the second – compound volumes that defined as a union.

is_empty()

Checks if the volume is the specifal empty volume.

is_intersection()

True if self was obtained only by intersection operations.

is_simple()

Checks if the volume is simple, i.e. not a result of operation on another volumes.

is_special()

Checks if the volume is the whole or empty volume.

is_union()

True if self was obtained only by union operations.

is_universal()

Checks if the volume is the whole volume (universal set).

op

Returns the operator used to create the volume. For a simple volume returns None.

>>> print Volume(1, 'a').op
None
>>> (Volume(1, 'a') & Volume(1, 'b')).op
'and'
>>> (Volume(1, 'a') | Volume(1, 'b')).op
'or'
static sort_operands(op1, op2)

Sorts operands for the & and | operations.

surfaces()

Returns a list of surface definitions used to define the volume.

>>> v1 = Volume( 1, 'a')
>>> v2 = Volume(-1, 'b')
>>> v = v1 & v2
>>> v.surfaces()
['a', 'b']
>>> v = Volume(1, 'c') | v
>>> v.surfaces()
['c', 'a', 'b']
volumes(reference=None)

Returns the list of simple volumes used to define the volume.

TODO: describe the reference optional argument.

class pirs.mcnp.Cell(**kwargs)

Representation of the MCNP cell card.

This is a container for cell material, density, geometry description and options, that can generate string representation of the cell for the MCNP input file.

Constructor can take optional keyword arguments to specify cell paramters and options:

>>> c = Cell(mat=1, rho=-10., vol=(-1, 1), cmt='comment', ID=10, 'imp:n'=2.5)
>>> print c
10 1 -10.0 -1 imp:n=2.5  $ comment

Cell parameters can be changed after initialization by setting the correspondent attributes:

>>> c.ID = 5
>>> c.mat = 4
>>> c.rho = -1.
>>> c.vol = (-1, 'a')
>>> c.opt['imp:n'] = 0
>>> print c
5 4 -1.0 -a imp:n=0  $ comment
ID

Cell ID.

At initialization set to the string ‘{ID}’.

card(formatted=True)

Returns a string representing the cell in the MCNP input file.

If optional argument formatted set to True (default), the returned string can contain new-line characters delimiting the string to lines that fit to 80-characters limit imposed by the MCNP input file syntax.

Representation of cell ID, material and volume depends on the type of correspondent attributes.

If cell ID is a positive integer or a string, it is printed as is. Otherwise, placeholder {ID} is printed.

If mat is an nonnegative integer or a string, it is printed together with density rho. Otherwise, placeholder {mat} {rho} is printed.

If vol is an instance of the Volume() class containing definitions that utilize the Surface() class, or if it is an instance of the Surface() class, placeholder {geom} is printed. Otherwise, the string representation of vol is printed.

cmt

Cell comment.

mat

Material of the cell.

Can be an integer or an instance of the Material() class.

opt

Dictionary of cell options.

An instance of the CellOpt() class.

rho

Cell density.

vol

Cell geometry (cell volume).

Can be set to an integer, string, or to an instance of the Volume() class.

The setter method accepts also a tuple of the form (sign, def), which is transformed to an instance of the Volume() class.

>>> c1 = Cell()
>>> c2 = Cell()
>>> c1.vol = Volume(-1, ['px', 0.])
>>> c2.vol = (-1, ['px', 0.])
>>> c1.vol == c2.vol
True
class pirs.mcnp.cells.CellOpts[source]

A dictioary to store cell options.

This is a dictionary that allows only particular string keys. Additionally, its string representation can be used directly in the input file within cell card.

VALIDKEYS = ('imp:n', 'u', 'fill', 'tmp', 'lat')

tuple of valid cell option names.

getvalue(key)[source]

Returns meaningfull part of the value for options ‘fill’, ‘u’ and ‘lat’.

In general, ‘fill’ is a (mulli-line) string that can optionally contain comments. This method returns a list of values of this cell option.

If options were not defined, return 0.

class pirs.mcnp.SurfaceCollection(iv=1, step=1)

Class to describe a collection of simple surfaces (SS) and macrobodies (MB).

One can ask for a surface index using the index() method of the collection. If a surface passed to this method is not in the collecion yet, it is added with a unique index.

The index() method adds only the surfaces (or facets of MB) that are not already in the collection.

The index() method can take as argument an instance of the Surface class, or arguments valid for the Surface() constructor.

When a SS is added to the collection, it is compared to the previously added surfaces, including MB facets. Only if it is not found, a new entry is added to the collection.

When a MB is added to the collection, it is compared to the previously added SSs, MBs and MB facets. If all facets of MB are allready defined, nothing is added. If some of the facets are defined and some are not, the missing facets are added as simple surfaces. If none of the MB facets are defined, the MB is added to the collection as MB.

Initializes new collection.

iv: initial value, the first elements index. step: step for indices.

cards(filter_=<function <lambda> at 0x2add5e5f6410>, formatted=True)

Returns a list of surface cards to represent surfaces in the collection in an MCNP input file.

Optional argument filter_ specifies a boolean-valued mapping, which defines whether to print surface with index ID passed to the mapping, or not.

By default it filters out the facets of MBs.

If the optional argument formatted set to True (default), the surface cards are splitted to several lines to fit to 80 characters, allowed by the MCNP input file syntax.

index(s, **kwargs)

Returns the ID of the surface s.

If s or some of its facets are not in the collection, they are added with a unique ID.

class pirs.mcnp.MaterialCollection(xsdir=None, *args)

Collection of materials with common xsdir.

Elementes of this collection are instances of the Material class augmented with a set of keyword arguments specifying additional attributes for this material.

Giving attribute values separated from the material allows to use the same material instance to describe different temperatures, for example.

One can pass an integer to the index() method. If the collection already contains a material with this index, its is just returned. Otherwise, an index error is raised. Index 0 is always in the collection.

cards(formatted=True)

Returns a list of multi-line strings with material cards.

If the optional argument formatted is True (default), the strings in the list are wrapped to fit to 80 characters of the MCNP input line maximal length.

index(mat, **kwargs)

Returns index of material mat.

Argument mat can be an instance of the Material() class, or an integer.

When mat is an instance of the Material() class:

If mat not yet in the collecion, it is added. Optional arguments specify material attributes to be changed, when material mat is processed. In this way, materials that differ only by temperature, can be represented with the same instance of the Material() class.

When mat is an integer:

If a material with this index allready exists, this index is returned. If there is no element with this index, the IndexError is raised.
class pirs.mcnp.Model(SurfaceCollectionClass=<class 'pirs.mcnp.surfaces.SurfaceCollection'>, MaterialCollectionClass=<class 'pirs.mcnp.material.MaterialCollection'>, TallyCollectionClass=<class 'pirs.mcnp.tallies.TallyCollection'>, CellCounterClass=<class 'pirs.mcnp.auxiliary.counters.Counter'>)

Model is a list of cells with common collection of materials, surfaces and tallies.

One setups the model by adding instances of the Cell class to the model.cells list. When the model is processed (for example, when converted to a string), each cell from the list is analysed: cells are added to a collection of cells, materials and surfaces used in the definition of cells are added to the material and surface collections. Collections are used to assign unique numbers (IDs) to cells, materials, surfaces, etc. When IDs are defined, a multi-line string representing the content of MCNP input file, is generated.

Cell, material, surface and tally IDs are assigned automatically.

In this way, cell and surface blocks, as well as part of the data block containig material and tally description of MCNP input file are generated automatically. One has also possibility to add lines to each block manually.

acc

List of additional cell cards. Each list element must be a string representing one cell card.

Strings from the list are added to the cell block after the cell cards generated automatically.

adc

List of additional data cards. Each list element must be a string representing one data card.

Strings from this list are added to the data block after the material and tally cards generated automatically.

Note, that the kcode card is treated specially, see the kcode attribute.

amc

List of additional message cards. Each list element must be a string representing one message line (do not forget to put 5 spaces at the begining)

String from this list are added to the message block after the automatically generated cards.

>>> m = Model()
>>> m.amc.append('     runtpe=rtp1')
>>> m.amc.append('     srctp=__s')
>>> print m                                
MESSAGE:
     datapath=D:\MCNPDATA\jeff31
     runtpe=rtp1
     srctp=__s

c title
...
asc

List of additional surface cards. Each list element must be a string representing one surface card.

Strings from the list are added to the surface block after the surface cards generated automatically.

cards(formatted=True)

Returns list of strings representing MCNP input file.

If optional argument formatted set to True (default), strings can contain the new-line characters so that the lines fit to the 80-characters limit imposed by the MCNP input file syntax.

cellCounter

The instance of the auxiliary.Counter class to enumerate cells.

cells

List of cells. The elements of the list must be instances of the Cell() class.

Elements can be added to and removed from the list. The processing of the cells in the list, i.e. adding the materials and surfaces to the common model collections, is done inside the method _process_cells. This method is called each time the model is converted to a string.

Note that the default value of the Cell.vol attribute is a string. This cannot be used directly in the MCNP model; geometry of cells that are used in the model must be defined with the help of the Volume() and Surface() classes.

clear()

Removes all cells, materials and surfaces from the correspondent collections. The lists of additional cards remain.

kcode

kcode card.

An instance of the card_classes.KcodeCard class.

keff()

Reads last mctal file and returns the combined Keff and its st.dev.

materialCollection

Instance of the MaterialCollection class. Cell materials are collected in this object.

The MaterialCollection is used to assign unique IDs to each material and to ensure that a material does not appear several times in the data block of MCNP input file.

Run _process_model to ensure that the material collection corresponds to the actual list of cells.

run(mode='r', **kwargs)

Prepares content of the input file and starts MCNP job.

surfaceCollection

Instance of the SurfaceCollection class. Surfaces used to define geometry of cells are collected in this object.

This collection is used to define unique surface IDs and to ensure that a surface does not appear in the surface block of MCNP input file several times.

Run the _process_model() method to ensure that the surface collection corresponds to the actual list of cells.

tallyCollection

Instance of the TallyCollection class. Tallies (currently, only mesh tallies) can be added to the model by adding them manually to the collection.

title

String title of the problem. Goes to the title card in MCNP input file.

wp

Instance of the McnpWorkPlace() class.

Prepares working directory for MCNP and starts the code.

xsdir

xsdir of the material collection of the model. It is used to define suffices in the material cards. Note that instances of Material class used in the description of cells can have their own xsdir objects that differ from the collection xsdir; the collection xsdir is always used to generate string representation of materials of the model.

Function(s) to represent doppler broading temperature by mixing two other temperatures.

pirs.mcnp.auxiliary.xs_interpolation.linT(T, T1, T2)[source]

Similar to sqrT(), but uses linear interpolation.

>>> linT(310, 300, 400)   
(0.9, 0.0999...)
>>> linT(300, 300, 400)
(1.0, 0.0)
>>> linT(400, 300, 400)
(0.0, 1.0)
>>> linT(310, 400, 300)
(0.1, 0.9)
pirs.mcnp.auxiliary.xs_interpolation.sqrT(T, T1, T2, rtol=0.1)[source]

Returns fractions of XS at temperatures T1 and T2 to represent temperature T.

Computes fractions of cross-sections at T1 and T2 to represent temperature T using the square-root temperature interpolation. T, T1 and T2 must be given in absolute units (Kelvin or MeV, for example).

Returns a tuple (f1, f2), where f1 and f2 are fractions of cross-sections at T1 and T2, respectively.

Optional argument rtol is used to specify distance from T1 or T2, at which interpolation takes place. For example, if T is close to T1, i.e. when

|T-T1| < |T1-T2|*rtol,

interpolation is not done, tuple (1.0, 0.0) is returned. In this way one can exclude interpolation, when T differs from existing temperatures T1 or T2 only negligibly.

>>> sqrT(350, 300, 400)   
(0.48207..., 0.5179...)
>>> sqrT(350, 400, 300)   
(0.5179..., 0.48207...)
>>> sqrT(300, 300, 400)   
(1.0, 0.0)
>>> sqrT(400, 300, 400)   
(0.0, 1.0)

Fractions f1 and f2 are defined from the following equations:

(1)  sigma(T) = sigma(T1)*f1  +  sigma(T2)*f2     # this is how cross-sections can be mixed in MCNP 
(2)  sigma(T) is proportional to T^1/2            # see van der Marck, Meulekamp, Hogenbirk, M&C2005
(3)  f1 + f2 = 1                                  # this is how nuclide fractions normed in MCNP material. 

from this equaitons, given T, T1 and T2, one can express f1 and f2:

(4)   f1 = (T^1/2 - T2^1/2) / (T1^1/2 - T2^1/2)
(5)   f2 = 1. - f1

Table Of Contents

Previous topic

pirs.solids subpackage

Next topic

pirs.scf2 subpackage

This Page