Skip to content

Commit 8f9c180

Browse files
authored
Merge pull request #46 from paulromano/mcnp-serpent
Add MCNP/Serpent plugins and improve documentation
2 parents cadb554 + b0f4286 commit 8f9c180

File tree

18 files changed

+835
-246
lines changed

18 files changed

+835
-246
lines changed

doc/source/conf.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
'sphinx.ext.intersphinx',
3434
'sphinx.ext.napoleon',
3535
'sphinx.ext.viewcode',
36-
'sphinx_autodoc_typehints'
36+
'sphinx_autodoc_typehints',
37+
'sphinx_design'
3738
]
3839

3940
# Add any paths that contain templates here, relative to this directory.
@@ -94,5 +95,6 @@
9495
"url_template": "https://watts.readthedocs.io/en/{version}/",
9596
"version_match": version if '-dev' not in version else 'dev',
9697
},
97-
"navbar_end": ["version-switcher", "navbar-icon-links"]
98+
"navbar_end": ["version-switcher", "navbar-icon-links"],
99+
"show_toc_level": 3,
98100
}

doc/source/index.rst

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,55 @@
1+
:notoc:
2+
13
WATTS
24
=====
35

4-
.. toctree::
5-
:maxdepth: 2
6-
:caption: Contents:
6+
.. grid:: 3
7+
:gutter: 3
8+
9+
.. grid-item-card:: \ :octicon:`rocket;2em` Getting Started
10+
:text-align: center
11+
:link: user/getting_started
12+
:link-type: doc
13+
14+
New to watts? Click here to get a quick overview of how watts works.
15+
16+
.. grid-item-card:: \ :octicon:`book;2em` User's Guide
17+
:text-align: center
18+
:link: user/index
19+
:link-type: doc
20+
21+
The user's guide contains instructions for installing and an overview of
22+
the basic concepts.
723

8-
user/index
9-
reference/index
10-
dev/index
24+
.. grid-item-card:: \ :octicon:`terminal;2em` API Reference
25+
:text-align: center
26+
:link: reference/index
27+
:link-type: doc
1128

29+
The reference guide provides detailed information on classes, methods,
30+
arguments, return values, etc.
1231

13-
Indices and tables
14-
==================
32+
.. grid-item-card:: \ :octicon:`git-pull-request;2em` Developer's Guide
33+
:text-align: center
34+
:link: dev/index
35+
:link-type: doc
36+
37+
Interested in contributing to watts? Our developer's guide provides
38+
instructions on how to make a contribution.
39+
40+
.. grid-item-card:: \ :octicon:`list-unordered;2em` Examples
41+
:text-align: center
42+
:link: https://github.com/watts-dev/watts/tree/development/examples
43+
44+
Once you're acquainted with the basics of watts, check out our examples
45+
that illustrate a variety of use cases.
46+
47+
48+
.. toctree::
49+
:maxdepth: 2
50+
:caption: Contents:
51+
:hidden:
1552

16-
* :ref:`genindex`
17-
* :ref:`modindex`
18-
* :ref:`search`
53+
user/index
54+
reference/index
55+
dev/index

doc/source/reference/index.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,18 @@ API Reference
1111
watts.Database
1212
watts.Parameters
1313
watts.Plugin
14-
watts.PluginOpenMC
14+
watts.PluginMCNP
1515
watts.PluginMOOSE
16+
watts.PluginOpenMC
1617
watts.PluginPyARC
18+
watts.PluginRELAP5
19+
watts.PluginSAS
20+
watts.PluginSerpent
1721
watts.Results
18-
watts.ResultsOpenMC
22+
watts.ResultsMCNP
1923
watts.ResultsMOOSE
24+
watts.ResultsOpenMC
2025
watts.ResultsPyARC
26+
watts.ResultsRELAP5
27+
watts.ResultsSAS
28+
watts.ResultsSerpent
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
.. _getting_started:
2+
3+
Getting Started
4+
---------------
5+
6+
What is :mod:`watts`?
7+
+++++++++++++++++++++
8+
9+
WATTS (Workflow and Template Toolkit for Simulation) consists of a set of Python
10+
classes that can manage simulation workflows for one or multiple codes. It
11+
provides the following capabilities:
12+
13+
- An isolated execution environment when running a code;
14+
- The ability to use placeholder values in input files that are filled in
15+
programmatically;
16+
- Seamless :ref:`unit conversions <units>` when working with multiple codes;
17+
- A managed database that simulation inputs and outputs are automatically saved
18+
to; and
19+
- Python classes that provide extra post-processing and analysis capabilities
20+
for each code.
21+
22+
Basic Execution
23+
+++++++++++++++
24+
25+
There are four major types of classes within :mod:`watts`. The
26+
:class:`~watts.Plugin` class (and its subclasses) provide the main interface to
27+
codes. As an example, let's say we have the following input file for MCNP that
28+
we want to run:
29+
30+
.. code-block:: text
31+
32+
Bare sphere of plutonium
33+
1 1 0.04 -1 imp:n=1
34+
2 0 1 imp:n=0
35+
36+
1 so 6.5
37+
38+
m1 94239.70c 0.04
39+
kcode 10000 1.0 50 150
40+
ksrc 0 0 0
41+
42+
If the filename of the input file is ``sphere_model``, we start by creating a
43+
:class:`watts.PluginMCNP` object::
44+
45+
plugin_mcnp = watts.PluginMCNP("sphere_model")
46+
47+
Calling the plugin class then executes the code::
48+
49+
result = plugin_mcnp()
50+
51+
When a plugin is called, any input files are copied to a temporary directory to
52+
create an isolated execution environment. Once the code is finished executing,
53+
all input and output files are moved to a database, and you are provided a
54+
:class:`~watts.Results` object that provides an interface to the simulation
55+
artifacts and methods for common post-processing tasks. In the example above,
56+
calling the :class:`~watts.PluginMCNP` instance returns a
57+
:class:`~watts.ResultsMCNP` object, which we can use to get a list of the output
58+
files or determine the resulting :math:`k_\text{eff}` value:
59+
60+
.. code-block:: pycon
61+
62+
>>> result.outputs
63+
[PosixPath('MCNP_log.txt'),
64+
PosixPath('srctp')
65+
PosixPath('outp')
66+
PosixPath('runtpe')]
67+
>>> result.keff
68+
1.0007+/-0.00053
69+
70+
Templates and Parameters
71+
++++++++++++++++++++++++
72+
73+
The input file shown above is just a normal MCNP input file. However, you can
74+
also put placeholders in an input file and have :mod:`watts` fill them in using
75+
the :class:`~watts.Parameters` class. Let's say we change the input file as
76+
follows:
77+
78+
.. code-block:: jinja
79+
80+
Bare sphere of plutonium
81+
1 1 0.04 -1 imp:n=1
82+
2 0 1 imp:n=0
83+
84+
1 so {{ radius }}
85+
86+
m1 94239.70c 0.04
87+
kcode 10000 1.0 50 {{ cycles }}
88+
ksrc 0 0 0
89+
90+
We've added two placeholders, ``{{ radius }}`` and ``{{ cycles }}``, that will
91+
be filled in. Before creating and calling our plugin, we now need to specify
92+
these parameters::
93+
94+
params = watts.Parameters()
95+
params['radius'] = 6.0
96+
params['cycles'] = 200
97+
98+
As before, we create an instance of :class:`~watts.PluginMCNP` but instead of
99+
calling it with no arguments, we pass it the :class:`~watts.Parameters`
100+
instance::
101+
102+
plugin_mcnp = watts.PluginMCNP("sphere_model")
103+
result = plugin_mcnp(params)
104+
105+
If we wanted to run this model with a series of different radii, it's now as
106+
simple as changing the corresponding parameter and calling the plugin::
107+
108+
for r in [2.0, 4.0, 6.0, 8.0, 10.0]:
109+
params['radius'] = r
110+
result = plugin_mcnp(params)
111+
112+
Results Database
113+
++++++++++++++++
114+
115+
Results are automatically added to a database and persist between invocations of
116+
Python. For the example above, we may want to look at the last five results to
117+
see how :math:`k_\text{eff}` varies with the radius. The
118+
:class:`~watts.Database` class provides a list-like object that contains all
119+
previously generated :class:`~watts.Results` objects:
120+
121+
.. code-block:: pycon
122+
123+
>>> database = watts.Database()
124+
>>> database
125+
[<ResultsMCNP: 2022-06-01 13:21:44.713942>,
126+
<ResultsMCNP: 2022-06-01 13:23:12.410774>,
127+
<ResultsMCNP: 2022-06-02 07:46:05.463723>,
128+
<ResultsMCNP: 2022-06-02 07:46:10.996932>,
129+
<ResultsMCNP: 2022-06-02 07:46:17.487411>,
130+
<ResultsMCNP: 2022-06-02 07:46:24.964455>,
131+
<ResultsMCNP: 2022-06-02 07:46:33.426781>]
132+
133+
This enables us to easily look at the :math:`k_\text{eff}` value for the last
134+
five MCNP simulations:
135+
136+
.. code-block:: pycon
137+
138+
>>> [result.keff for result in database[-5:]]
139+
[0.3523+/-0.00021,
140+
0.68017+/-0.00042,
141+
0.97663+/-0.00063,
142+
1.24086+/-0.00075,
143+
1.47152+/-0.00081]

doc/source/user/index.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ User's Guide
44
============
55

66
.. toctree::
7-
:maxdepth: 2
7+
:maxdepth: 1
88

99
install
10+
getting_started
1011
usage
12+
plugins

0 commit comments

Comments
 (0)