Skip to content

Commit 70d672c

Browse files
committed
examples: updated documentation
1 parent 75216da commit 70d672c

28 files changed

+244
-158
lines changed

docs/source/conf.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,11 @@
33
# For the full list of built-in configuration values, see the documentation:
44
# https://www.sphinx-doc.org/en/master/usage/configuration.html
55

6-
# import sys
7-
# import os
8-
# sys.path.insert(0, os.path.abspath("../../src"))
9-
# import pymcnp
10-
116
# -- Project information -----------------------------------------------------
127
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
138

149
project = 'PyMCNP'
15-
copyright = '2024, The Regents of the University of California, through Lawrence Berkeley National Laboratory '
16-
'(subject to receipt of any required approvals from the U.S. Dept. of Energy). All rights reserved.'
10+
copyright = '2024, The Regents of the University of California, through Lawrence Berkeley National Laboratory (subject to receipt of any required approvals from the U.S. Dept. of Energy). All rights reserved.'
1711
author = 'Devin Pease, Arun Persaud, Mauricio Ayllon Unzueta'
1812

1913
# -- General configuration ---------------------------------------------------

docs/source/examples.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
# Examples
22

3-
PyMCNP includes examples for reading INP, PTRAC, and OUTP, creating INP, and doing workflows, such as visualizing, running, and plotting:
3+
```{eval-rst}
4+
.. warning::
5+
Some examples overwrite or create files or directories. If running in the PyMCNP/examples directory, run the following command to clean the
6+
directory:
7+
8+
::
9+
10+
rm -R pymcnp-*; rm *.pdf; rm *.csv; rm *.parquet
11+
```
412

5-
* ["Create" Examples](examples/create)
6-
* ["Do" Examples](examples/do)
7-
* ["Read" Examples](examples/read)
13+
PyMCNP includes examples for reading INP, PTRAC, and OUTP, creating INP, and doing workflows, such as visualizing, running, and plotting.
814

915
## Table of Contents
1016

docs/source/index.md

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,3 @@ visualizes simulation geometries, and runs MCNP simulations in parallel.
1717
examples
1818
contributing
1919
```
20-
21-
## Components
22-
23-
PyMCNP has two main components:
24-
25-
* [PyMCNP CLI](cli)
26-
* [PyMCNP Library](pymcnp)
27-
28-
## Guides
29-
30-
PyMCNP has guides:
31-
32-
* [Installation](installation)
33-
* [Examples](examples)
34-
* [Contributing](contributing)

docs/source/pymcnp.md

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
# PyMCNP Library
22

3-
> [!WARNING]
4-
> Warning: PyMCNP is in active development! Please, double check eveything works. Reports error on [GitHub](https://github.com/FSIBT/PyMCNP).
3+
```{eval-rst}
4+
.. warning::
5+
PyMCNP is in active development! Please, double check everything works. Reports error on [GitHub](https://github.com/FSIBT/PyMCNP).
6+
```
57

68
PyMCNP provides the backend for the CLI and useful tools for programatically interfacing with
7-
MCNP. This package supports INP, OUTP, PTRAC, and MESHTAL parsing using subpackages:
8-
9-
* [inp subpackage](/pymcnp/inp): INP parsing.
10-
* [meshtal subpackage](/pymcnp/meshtal): MESHTAL parsing.
11-
* [outp subpackage](/pymcnp/outp): OUTP parsing.
12-
* [ptrac subpackage](/pymcnp/ptrac): PTRAC parsing.
13-
* [types subpackage](/pymcnp/types): Shared parsing, data types.
14-
* [errors subpackage](/pymcnp/errors): Error handling.
9+
MCNP. This package supports INP, OUTP, PTRAC, and MESHTAL parsing using subpackages.
1510

1611
## Table of Contents
1712

docs/source/pymcnp/inp.md

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
# `pymcnp.inp` Subpackage
22

3-
> [!WARNING]
4-
> The following non-terminals are not currently supported:
5-
> * data.Field (3.3.3.12)
6-
> * data.Mplot (3.3.7.2.5)
7-
> * data.Burn (3.3.4.13)
8-
> * data.Embed.Overlap (3.3.1.6.2)
9-
> * data.Tmesh (3.3.5.24)
10-
> * data.Spabi (3.3.6.16)
11-
> The following non-terminals are partial supported:
12-
> * data.Fm (3.3.5.7)
13-
> * data.Ft (3.3.5.18)
3+
```{eval-rst}
4+
.. warning::
5+
The following non-terminals are not currently supported:
6+
7+
* `Field` (3.3.3.12)
8+
* `Mplot` (3.3.7.2.5)
9+
* `Burn` (3.3.4.13)
10+
* `Embed.Overlap` (3.3.1.6.2)
11+
* `Tmesh` (3.3.5.24)
12+
* `Spabi` (3.3.6.16)
13+
14+
The following non-terminals are partial supported:
15+
16+
* `Fm` (3.3.5.7)
17+
* `Ft` (3.3.5.18)
18+
```
1419

1520
`pymcnp.inp` contains the INP parser. PyMCNP implements an object-oriented recursive
1621
descent parser, approximating INP as the following context-free-grammar described in modified Bakus-Naur form:

docs/source/pymcnp/inp/surface.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# `pymcnp.inp.surface` Subpackage
22

3+
```{eval-rst}
4+
.. warning::
5+
The following surface visualizations are not currently supported:
6+
7+
* `Arb` (3.2.2.4.10)
8+
* `Gq` (3.2.2.1)
9+
* `Sq` (3.2.2.1)
10+
* `X` (3.2.2.2)
11+
* `Y` (3.2.2.2)
12+
* `Z` (3.2.2.2)
13+
```
14+
315
## AST Classes
416

517
### `Arb` Class

examples/create_cell.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
"""
22
Examples creating INP cells.
3+
4+
This example creates an INP cell using `__init__`. First, it creates an cell
5+
option, namely `Imp`, and second, it creates the cell using `Cell`, printing
6+
the result.
37
"""
48

59
import pymcnp
@@ -16,4 +20,5 @@
1620
options=[imp],
1721
)
1822

23+
print('INP cell created using `__init__`:')
1924
print(cell)

examples/create_inp.py

Lines changed: 59 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,82 @@
11
"""
22
Example creating INP files.
3+
4+
This example creates an INP file. First, it creates surfaces, and second,
5+
it defines materials. Third, it defines cells by combining geometries using
6+
operators and assigning materials. Fourth, it creates a point source and a
7+
type #4 tally. Fifth, it creates a INP file using `Inp` and prints the result.
38
"""
49

510
import pymcnp
611

7-
RADIUS_AIR: float = 60
8-
RADIUS_SHIELD: float = 5
9-
RADIUS_LEAD: float = 1
10-
11-
# Creating cell geometries.
12-
geometry_air = pymcnp.types.Geometry.from_mcnp('11')
13-
geometry_shield = pymcnp.types.Geometry.from_mcnp('12')
14-
geometry_lead = pymcnp.types.Geometry.from_mcnp('13')
15-
geometry_world = pymcnp.types.Geometry.from_mcnp('14')
16-
17-
# Creating cells.
18-
cell_air = pymcnp.inp.Cell(number=1, material=21, density=0.5, geometry=geometry_air)
19-
cell_shield = pymcnp.inp.Cell(number=2, material=22, density=0.5, geometry=geometry_shield & geometry_air)
20-
cell_lead = pymcnp.inp.Cell(number=3, material=23, density=0.5, geometry=geometry_lead & geometry_shield)
21-
cell_world = pymcnp.inp.Cell(number=4, material=0, geometry=geometry_world)
22-
23-
# Creating surface options.
24-
rpp_air = pymcnp.inp.surface.Rpp(
25-
xmin=-RADIUS_AIR,
26-
xmax=RADIUS_AIR,
27-
ymin=-RADIUS_AIR,
28-
ymax=RADIUS_AIR,
29-
zmin=-RADIUS_AIR,
30-
zmax=RADIUS_AIR,
31-
)
32-
rpp_shield = pymcnp.inp.surface.Rpp(
33-
xmin=-RADIUS_SHIELD,
34-
xmax=RADIUS_SHIELD,
35-
ymin=-RADIUS_SHIELD,
36-
ymax=RADIUS_SHIELD,
37-
zmin=-RADIUS_SHIELD,
38-
zmax=RADIUS_SHIELD,
39-
)
40-
rpp_lead = pymcnp.inp.surface.Rpp(
41-
xmin=-RADIUS_LEAD,
42-
xmax=RADIUS_LEAD,
43-
ymin=-RADIUS_LEAD,
44-
ymax=RADIUS_LEAD,
45-
zmin=-RADIUS_LEAD,
46-
zmax=RADIUS_LEAD,
47-
)
48-
so_world = pymcnp.inp.surface.So(r=RADIUS_AIR + RADIUS_SHIELD + RADIUS_LEAD + 1)
12+
RADIUS_WORLD: float = 100
13+
RADIUS_INNER: float = 50
14+
RADIUS_OUTER: float = 10
4915

5016
# Creating surfaces.
51-
surface_air = pymcnp.inp.Surface(
52-
number=11,
53-
option=rpp_air,
17+
surface_inner = pymcnp.inp.Surface(
18+
number=12,
19+
option=pymcnp.inp.surface.Rpp(
20+
xmin=-RADIUS_INNER,
21+
xmax=RADIUS_INNER,
22+
ymin=-RADIUS_INNER,
23+
ymax=RADIUS_INNER,
24+
zmin=-RADIUS_INNER,
25+
zmax=RADIUS_INNER,
26+
),
5427
)
55-
surface_shield = pymcnp.inp.Surface(
56-
number=11,
57-
option=rpp_shield,
58-
)
59-
surface_lead = pymcnp.inp.Surface(
60-
number=11,
61-
option=rpp_lead,
28+
surface_outer = pymcnp.inp.Surface(
29+
number=13,
30+
option=pymcnp.inp.surface.Rpp(
31+
xmin=-RADIUS_OUTER,
32+
xmax=RADIUS_OUTER,
33+
ymin=-RADIUS_OUTER,
34+
ymax=RADIUS_OUTER,
35+
zmin=-RADIUS_OUTER,
36+
zmax=RADIUS_OUTER,
37+
),
6238
)
6339
surface_world = pymcnp.inp.Surface(
64-
number=99,
65-
option=so_world,
40+
number=14,
41+
option=pymcnp.inp.surface.So(
42+
r=RADIUS_WORLD,
43+
),
6644
)
6745

6846
# Creating materials.
6947
material_air = pymcnp.inp.M_0.from_formula(number=21, formulas={'N2': 0.8, 'O2': 0.2})
70-
material_shield = pymcnp.inp.M_0.from_formula(number=22, formulas={'TiO2': 0.5, 'PbO': 0.5})
7148
material_lead = pymcnp.inp.M_0.from_formula(number=23, formulas={'Pb': 1})
7249

50+
# Creating cells.
51+
cell_inside = pymcnp.inp.Cell(number=1, material=0, geometry=-surface_inner)
52+
cell_shield = pymcnp.inp.Cell(number=2, material=23, density=0.5, geometry=+surface_inner & -surface_outer)
53+
cell_air = pymcnp.inp.Cell(number=3, material=21, density=0.5, geometry=-surface_inner | (+surface_outer & -surface_world))
54+
cell_world = pymcnp.inp.Cell(number=4, material=0, geometry=+surface_world)
55+
56+
# Creating source & tally.
57+
source = pymcnp.inp.Sdef(
58+
options=[
59+
pymcnp.inp.sdef.Pos_0(0, 0, 0),
60+
pymcnp.inp.sdef.Erg_0(14.4),
61+
pymcnp.inp.sdef.Par_0(1),
62+
]
63+
)
64+
65+
tally = pymcnp.inp.F_0(
66+
suffix=4,
67+
designator='n',
68+
problems=[2],
69+
)
70+
7371
# Creating inp.
7472
inp = pymcnp.Inp(
7573
title='Create `Inp`\n',
76-
cells=[cell_air, cell_shield, cell_lead, cell_world],
77-
surfaces=[surface_air, surface_shield, surface_lead, surface_world],
78-
data=[material_air, material_shield, material_lead],
74+
cells=[cell_inside, cell_shield, cell_air, cell_world],
75+
surfaces=[surface_inner, surface_outer, surface_world],
76+
data=[material_air, material_lead, source, tally],
7977
)
78+
inp.nps = 1e5
79+
inp.seed = 1232209489
8080

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

examples/create_material.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
"""
22
Examples creating INP materials.
3+
4+
This example creates INP surfaces using `__init__`. First, it creates an
5+
cell option using `Imp`, and second, it creates the cell using `Cell`, printing
6+
the result.
37
"""
48

59
import pymcnp
610

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

14+
print('INP material created using `__init__`:')
1015
print(material)
1116

1217
# Creating material using `from_formula`.
@@ -16,4 +21,5 @@
1621
is_weight=False,
1722
)
1823

24+
print('INP material created using `from_formula`:')
1925
print(material)

examples/create_surface.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
"""
22
Examples creating INP surfaces.
3+
4+
This example creates an INP surface using `__init__`. First, it creates a
5+
surface option, namely `So`, to specify the shape. Second, it creates the
6+
surface using `Surface`, printing the result.
37
"""
48

59
import pymcnp
@@ -15,4 +19,5 @@
1519
option=so,
1620
)
1721

22+
print('INP surface created using `__init__`:')
1823
print(surface)

0 commit comments

Comments
 (0)