“Create” Examples

PyMCNP supports INP files and cards creation.

Creating Cell Cards

Code:

"""
Examples creating INP cells.

This example creates an INP cell using `__init__`. First, it creates an cell
option, namely `Imp`, and second, it creates the cell using `Cell`, printing
the result.
"""

import pymcnp

# Creating option.
imp = pymcnp.inp.cell.Imp(designator='n', importance=1.0)

# Creating cell.
cell = pymcnp.inp.Cell(
    material=1,
    geometry='#(99:3)',
    density=0.5,
    options=[imp],
)

print('INP cell created using `__init__`:')
print(cell)

Output:

INP cell created using `__init__`:
1 1 0.5 #(99:3) imp:n 1.0

Creating Material Cards

Code:

"""
Examples creating INP materials.

This example creates INP surfaces using `__init__`. First, it creates an
cell option using `Imp`, and second, it creates the cell using `Cell`, printing
the result.
"""

import pymcnp

# Creating material using `__init__`.
material = pymcnp.inp.M_0(substances=['001001 0.1118855432927602', '008016 0.8859435015301171'])

print('INP material created using `__init__`:')
print(material)

# Creating material using `from_formula`.
material = pymcnp.inp.M_0.from_formula(
    {'H2O': 1},
    is_weight=False,
)

print('INP material created using `from_formula`:')
print(material)

Output:

m1 001001 0.1118855432927602 008016 0.8859435015301171
m1 001001 0.1118855432927602 008016 0.8859435015301171

Creating Surface Cards

Code:

"""
Examples creating INP surfaces.

This example creates an INP surface using `__init__`. First, it creates a
surface option, namely `So`, to specify the shape. Second, it creates the
surface using `Surface`, printing the result.
"""

import pymcnp

# Creating surface.
surface = pymcnp.inp.So(
    r=2,
)

print('INP surface created using `__init__`:')
print(surface)

Output:

INP surface created using `__init__`:
1  so 2

Creating INP Files

Code:

"""
Example creating INP files.

This example creates an INP file. First, it creates surfaces, and second,
it defines materials. Third, it defines cells by combining geometries using
operators and assigning materials. Fourth, it creates a point source and a
type #4 tally. Fifth, it creates a INP file using `Inp` and prints the result.
"""

import pymcnp

RADIUS_WORLD: float = 100
RADIUS_INNER: float = 50
RADIUS_OUTER: float = 10

# Creating surfaces.
surface_inner = pymcnp.inp.Rpp(
    xmin=-RADIUS_INNER,
    xmax=RADIUS_INNER,
    ymin=-RADIUS_INNER,
    ymax=RADIUS_INNER,
    zmin=-RADIUS_INNER,
    zmax=RADIUS_INNER,
)
surface_outer = pymcnp.inp.Rpp(
    xmin=-RADIUS_OUTER,
    xmax=RADIUS_OUTER,
    ymin=-RADIUS_OUTER,
    ymax=RADIUS_OUTER,
    zmin=-RADIUS_OUTER,
    zmax=RADIUS_OUTER,
)
surface_world = pymcnp.inp.So(
    r=RADIUS_WORLD,
)

# Creating materials.
material_air = pymcnp.inp.M_0.from_formula(formulas={'N2': 0.8, 'O2': 0.2})
material_lead = pymcnp.inp.M_0.from_formula(formulas={'Pb': 1})

# Creating cells.
imp = pymcnp.inp.cell.Imp(designator='n', importance=1)
cell_inside = pymcnp.inp.Cell(material=0, geometry=-surface_inner, options=[imp])
cell_shield = pymcnp.inp.Cell(material=material_lead, density=0.5, geometry=+surface_inner & -surface_outer, options=[imp])
cell_air = pymcnp.inp.Cell(material=material_air, density=0.5, geometry=-surface_inner | (+surface_outer & -surface_world), options=[imp])
cell_world = pymcnp.inp.Cell(material=0, geometry=+surface_world, options=[imp])

# Creating source.
source = pymcnp.inp.Sdef(
    options=[
        pymcnp.inp.sdef.Pos_0(0, 0, 0),
        pymcnp.inp.sdef.Erg_0(14.4),
        pymcnp.inp.sdef.Par_0(1),
    ]
)

# Creating tally.
tally = pymcnp.inp.F_0(
    suffix=4,
    designator='n',
    problems=[2],
)

# Creating inp.
inp = pymcnp.Inp(
    title='Create `Inp`\n',
    cells=[cell_inside, cell_shield, cell_air, cell_world],
    surfaces=[surface_inner, surface_outer, surface_world],
    data=[material_air, material_lead, source, tally],
)
inp.nps = 1e5
inp.seed = 1232209489

print('INP file created using `__init__`:')
print(inp)

Output:

INP file created using `__init__`:
Create `Inp`

1 0  -1 
1 1 0.5 +1:-1 
1 1 0.5 -1 +1:-1 
1 0  +1 

1  rpp -50 50 -50 50 -50 50
1  rpp -10 10 -10 10 -10 10
1  so 100

m1 007014 -0.797088 008016 -0.199514
m1 082204 -0.014 082206 -0.241 082207 -0.221 082208 -0.524
sdef pos 0 0 0 erg 14.4 par 1
f4:n 2
nps 100000.0
rand seed 1232209489