Skip to content

Commit 3d62b9a

Browse files
authored
Merge pull request #61 from fusion-energy/develop
Major refactoring to use OpenMC classes
2 parents 14474cd + 09093a4 commit 3d62b9a

26 files changed

+2400
-2385
lines changed

.circleci/config.yml

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,36 @@ jobs:
1616
python setup.py install
1717
1818
- run:
19-
name: run test_NeutronicModel
19+
name: run test_neutronics_utils
2020
command:
21-
pytest tests/test_neutronics_model.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
21+
pytest tests/test_neutronics_utils.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
2222

2323
- run:
24-
name: run test_shape_neutronics
24+
name: run tests Settings()
2525
command:
26-
pytest tests/test_shape_neutronics.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
26+
pytest tests/test_settings.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
2727

2828
- run:
29-
name: run test_reactor_neutronics
29+
name: run tests Materials()
3030
command:
31-
pytest tests/test_reactor_neutronics.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
31+
pytest tests/test_materials.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
3232

33-
# - run:
34-
# name: run test_neutronics_utils
35-
# command:
36-
# pytest tests/test_neutronics_utils.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
33+
- run:
34+
name: run tests Tallies
35+
command:
36+
pytest tests/test_tallies/ -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
3737

3838
- run:
39-
name: run test_example_neutronics_simulations
39+
name: System tests
4040
command:
41-
pytest tests/test_example_neutronics_simulations.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
41+
pytest tests/test_system/ -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
42+
43+
# - run:
44+
# name: run test_example_neutronics_simulations
45+
# command:
46+
# pytest tests/test_example_neutronics_simulations.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
47+
48+
4249

4350
# TODO add example notebooks
4451
# - run:

.github/workflows/ci_with_install.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ jobs:
2525
2626
- name: run tests
2727
run: |
28+
pytest tests/test_neutronics_utils.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
2829
pytest tests/test_example_neutronics_simulations.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
29-
pytest tests/test_neutronics_model.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
30-
# pytest tests/test_neutronics_utils.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
31-
pytest tests/test_reactor_neutronics.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
32-
pytest tests/test_shape_neutronics.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
33-
python tests/notebook_testing.py
30+
pytest tests/test_settings.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
31+
pytest tests/test_materials.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
32+
pytest tests/test_tallies/ -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
33+
pytest tests/test_system/ -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml

examples/cell_tally_example.py

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# A minimal example that obtains TBR on the blanket and fast neutron flux on all
2+
# cells in the DAGMC geometry.
3+
# Particular emphasis is placed on explaining the openmc-dagmc-wrapper
4+
# extentions of openmc base classes.
5+
6+
import tarfile
7+
import urllib.request
8+
9+
import openmc
10+
import openmc_dagmc_wrapper as odw
11+
from openmc_plasma_source import FusionRingSource
12+
13+
# downloads a dagmc file for use in the example
14+
url = "https://github.com/fusion-energy/neutronics_workflow/archive/refs/tags/v0.0.2.tar.gz"
15+
urllib.request.urlretrieve(url, "v0.0.2.tar.gz")
16+
tar = tarfile.open("v0.0.2.tar.gz", "r:gz")
17+
tar.extractall(".")
18+
tar.close()
19+
h5m_filename = "neutronics_workflow-0.0.2/example_02_multi_volume_cell_tally/stage_2_output/dagmc.h5m"
20+
21+
22+
# creates a geometry object from a DAGMC geometry.
23+
# In this case the geometry doen't have a graveyard cell.
24+
# So a set of 6 CSG surfaces are automatically made and added to the geometry
25+
geometry = odw.Geometry(h5m_filename=h5m_filename)
26+
27+
# Creates the materials to use in the problem using by linking the material
28+
# tags in the DAGMC h5m file with material definitions in the
29+
# neutronics-material-maker. One could also use openmc.Material or nmm.Material
30+
# objects instead of the strings used here
31+
materials = odw.Materials(
32+
h5m_filename=h5m_filename,
33+
correspondence_dict={
34+
"blanket_mat": "Li4SiO4",
35+
"blanket_rear_wall_mat": "Be",
36+
"center_column_shield_mat": "Be",
37+
"divertor_mat": "Be",
38+
"firstwall_mat": "Be",
39+
"inboard_tf_coils_mat": "Be",
40+
"pf_coil_case_mat": "Be",
41+
"pf_coil_mat": "Be",
42+
"tf_coil_mat": "Be",
43+
},
44+
)
45+
46+
# A cell tally allows a set of standard tally types (made from filters and
47+
# scores) to be applied to a DAGMC material or a volume
48+
# This cell tally applies a TBR tally to the volume(s) labeled with the
49+
# blanket_mat tag in the DAGMC geometry
50+
tally1 = odw.CellTally(
51+
tally_type="TBR",
52+
target="blanket_mat",
53+
materials=materials)
54+
55+
# This cell tally obtains the neutron fast flux on all volumes in the problem
56+
tally2 = odw.CellTallies(
57+
tally_types=["neutron_fast_flux"],
58+
targets="all_volumes",
59+
h5m_filename=h5m_filename)
60+
61+
# no modifications are made to the default openmc.Tallies
62+
tallies = openmc.Tallies([tally1] + tally2.tallies)
63+
64+
# Creates and openmc settings object with the run mode set to 'fixed source'
65+
# and the number of inactivate particles set to zero. Setting these to values
66+
# by default means less code is needed by the user and less chance of simulating
67+
# batches that don't contribute to the tallies
68+
settings = odw.FusionSettings()
69+
settings.batches = 1
70+
settings.particles = 100
71+
# assigns a ring source of DT energy neutrons to the source using the
72+
# openmc_plasma_source package
73+
settings.source = FusionRingSource(fuel="DT", radius=350)
74+
75+
76+
# no modifications are made to the default openmc.Model object
77+
my_model = openmc.Model(
78+
materials=materials, geometry=geometry, settings=settings, tallies=tallies
79+
)
80+
statepoint_file = my_model.run()
81+
82+
# processes the output h5 file. the process_results function contains logic on
83+
# how to process each tally with respect to the tally multipliers and units
84+
# involved. The fusion power input allows tallies to be scaled from the units
85+
# of per source neutron to units such as Watts (for heating), Sv per second
86+
# (for dose) and other convenient units.
87+
odw.process_results(statepoint_file, fusion_power=1e9)
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# A minimal example that obtains TBR on the blanket and fast neutron flux on all
2+
# cells in the DAGMC geometry.
3+
# Particular emphasis is placed on explaining the openmc-dagmc-wrapper
4+
# extentions of openmc base classes.
5+
6+
import tarfile
7+
import urllib.request
8+
9+
import openmc
10+
import openmc_dagmc_wrapper as odw
11+
from openmc_plasma_source import FusionRingSource
12+
13+
14+
# downloads a dagmc file for use in the example
15+
# url = "https://github.com/fusion-energy/neutronics_workflow/archive/refs/tags/v0.0.2.tar.gz"
16+
# urllib.request.urlretrieve(url, "v0.0.2.tar.gz")
17+
# tar = tarfile.open("v0.0.2.tar.gz", "r:gz")
18+
# tar.extractall(".")
19+
# tar.close()
20+
h5m_filename = "neutronics_workflow-0.0.2/example_02_multi_volume_cell_tally/stage_2_output/dagmc.h5m"
21+
h5m_filename = "neutronics_workflow-0.0.2/example_02_multi_volume_cell_tally/stage_2_output/dagmc_no_grave_yard.h5m"
22+
23+
24+
# creates a geometry object from a DAGMC geometry.
25+
# In this case the geometry doen't have a graveyard cell.
26+
# So a set of 6 CSG surfaces are automatically made and added to the geometry
27+
geometry = odw.Geometry(h5m_filename=h5m_filename)
28+
29+
# Creates the materials to use in the problem using by linking the material
30+
# tags in the DAGMC h5m file with material definitions in the
31+
# neutronics-material-maker. One could also use openmc.Material or nmm.Material
32+
# objects instead of the strings used here
33+
materials = odw.Materials(
34+
h5m_filename=h5m_filename,
35+
correspondence_dict={
36+
"blanket_mat": "Li4SiO4",
37+
"blanket_rear_wall_mat": "Be",
38+
"center_column_shield_mat": "Be",
39+
"divertor_mat": "Be",
40+
"firstwall_mat": "Be",
41+
"inboard_tf_coils_mat": "Be",
42+
"pf_coil_case_mat": "Be",
43+
"pf_coil_mat": "Be",
44+
"tf_coil_mat": "Be",
45+
},
46+
)
47+
48+
# A MeshTally2D tally allows a set of standard tally types (made from filters
49+
# and scores) to be applied to the DAGMC geometry. By default the mesh will be
50+
# applied across the entire geomtry with and the size of the geometry is
51+
# automatically found.
52+
53+
tally1 = odw.MeshTally2D(
54+
tally_type="photon_effective_dose", plane="xy", bounding_box=h5m_filename
55+
)
56+
tally2 = odw.MeshTally2D(
57+
tally_type="neutron_effective_dose", plane="xy", bounding_box=h5m_filename
58+
)
59+
60+
# no modifications are made to the default openmc.Tallies
61+
tallies = openmc.Tallies([tally1, tally2])
62+
63+
# Creates and openmc settings object with the run mode set to 'fixed source'
64+
# and the number of inactivate particles set to zero. Setting these to values
65+
# by default means less code is needed by the user and less chance of simulating
66+
# batches that don't contribute to the tallies
67+
settings = odw.FusionSettings()
68+
settings.batches = 2
69+
settings.particles = 100
70+
settings.photon_transport = True
71+
# assigns a ring source of DT energy neutrons to the source using the
72+
# openmc_plasma_source package
73+
settings.source = FusionRingSource(fuel="DT", radius=350)
74+
75+
# no modifications are made to the default openmc.Model object
76+
my_model = openmc.Model(
77+
materials=materials, geometry=geometry, settings=settings, tallies=tallies
78+
)
79+
statepoint_file = my_model.run()
80+
81+
# processes the output h5 file. The process_results function contains logic on
82+
# how to process each tally with respect to the tally multipliers and units
83+
# involved. The fusion power input allows tallies to be scaled from the units
84+
# of per source neutron to units such as Watts (for heating), Sv per second
85+
# (for dose) and other convenient units.
86+
odw.process_results(statepoint_file, fusion_power=1e9)
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# A minimal example that obtains TBR on the blanket and fast neutron flux on all
2+
# cells in the DAGMC geometry.
3+
# Particular emphasis is placed on explaining the openmc-dagmc-wrapper
4+
# extentions of openmc base classes.
5+
6+
import tarfile
7+
import urllib.request
8+
9+
import openmc
10+
import openmc_dagmc_wrapper as odw
11+
from openmc_plasma_source import FusionRingSource
12+
13+
# downloads a dagmc file for use in the example
14+
# url = "https://github.com/fusion-energy/neutronics_workflow/archive/refs/tags/v0.0.2.tar.gz"
15+
# urllib.request.urlretrieve(url, "v0.0.2.tar.gz")
16+
# tar = tarfile.open("v0.0.2.tar.gz", "r:gz")
17+
# tar.extractall(".")
18+
# tar.close()
19+
h5m_filename = "neutronics_workflow-0.0.2/example_02_multi_volume_cell_tally/stage_2_output/dagmc.h5m"
20+
21+
22+
# creates a geometry object from a DAGMC geometry.
23+
# In this case the geometry doen't have a graveyard cell.
24+
# So a set of 6 CSG surfaces are automatically made and added to the geometry
25+
geometry = odw.Geometry(h5m_filename=h5m_filename)
26+
27+
# Creates the materials to use in the problem using by linking the material
28+
# tags in the DAGMC h5m file with material definitions in the
29+
# neutronics-material-maker. One could also use openmc.Material or nmm.Material
30+
# objects instead of the strings used here
31+
materials = odw.Materials(
32+
h5m_filename=h5m_filename,
33+
correspondence_dict={
34+
"blanket_mat": "Li4SiO4",
35+
"blanket_rear_wall_mat": "Be",
36+
"center_column_shield_mat": "Be",
37+
"divertor_mat": "Be",
38+
"firstwall_mat": "Be",
39+
"inboard_tf_coils_mat": "Be",
40+
"pf_coil_case_mat": "Be",
41+
"pf_coil_mat": "Be",
42+
"tf_coil_mat": "Be",
43+
},
44+
)
45+
46+
# A MeshTally3D tally allows a set of standard tally types (made from filters
47+
# and scores) to be applied to the DAGMC geometry. By default the mesh will be
48+
# applied across the entire geomtry with and the size of the geometry is
49+
# automatically found.
50+
tally1 = odw.MeshTally3D(
51+
tally_type="neutron_effective_dose",
52+
bounding_box=h5m_filename)
53+
54+
# no modifications are made to the default openmc.Tallies
55+
tallies = openmc.Tallies([tally1])
56+
57+
# Creates and openmc settings object with the run mode set to 'fixed source'
58+
# and the number of inactivate particles set to zero. Setting these to values
59+
# by default means less code is needed by the user and less chance of simulating
60+
# batches that don't contribute to the tallies
61+
settings = odw.FusionSettings()
62+
settings.batches = 1
63+
settings.particles = 100
64+
# assigns a ring source of DT energy neutrons to the source using the
65+
# openmc_plasma_source package
66+
settings.source = FusionRingSource(fuel="DT", radius=350)
67+
68+
# no modifications are made to the default openmc.Model object
69+
my_model = openmc.Model(
70+
materials=materials, geometry=geometry, settings=settings, tallies=tallies
71+
)
72+
statepoint_file = my_model.run()
73+
74+
# processes the output h5 file. The process_results function contains logic on
75+
# how to process each tally with respect to the tally multipliers and units
76+
# involved. The fusion power input allows tallies to be scaled from the units
77+
# of per source neutron to units such as Watts (for heating), Sv per second
78+
# (for dose) and other convenient units.
79+
odw.process_results(statepoint_file, fusion_power=1e9)

0 commit comments

Comments
 (0)