Skip to content
This repository has been archived by the owner on Aug 15, 2023. It is now read-only.

Commit

Permalink
Merge pull request #61 from fusion-energy/develop
Browse files Browse the repository at this point in the history
Major refactoring to use OpenMC classes
  • Loading branch information
shimwell authored Sep 27, 2021
2 parents 14474cd + 09093a4 commit 3d62b9a
Show file tree
Hide file tree
Showing 26 changed files with 2,400 additions and 2,385 deletions.
31 changes: 19 additions & 12 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,36 @@ jobs:
python setup.py install
- run:
name: run test_NeutronicModel
name: run test_neutronics_utils
command:
pytest tests/test_neutronics_model.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
pytest tests/test_neutronics_utils.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml

- run:
name: run test_shape_neutronics
name: run tests Settings()
command:
pytest tests/test_shape_neutronics.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
pytest tests/test_settings.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml

- run:
name: run test_reactor_neutronics
name: run tests Materials()
command:
pytest tests/test_reactor_neutronics.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
pytest tests/test_materials.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml

# - run:
# name: run test_neutronics_utils
# command:
# pytest tests/test_neutronics_utils.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
- run:
name: run tests Tallies
command:
pytest tests/test_tallies/ -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml

- run:
name: run test_example_neutronics_simulations
name: System tests
command:
pytest tests/test_example_neutronics_simulations.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
pytest tests/test_system/ -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml

# - run:
# name: run test_example_neutronics_simulations
# command:
# pytest tests/test_example_neutronics_simulations.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml



# TODO add example notebooks
# - run:
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/ci_with_install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ jobs:
- name: run tests
run: |
pytest tests/test_neutronics_utils.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
pytest tests/test_example_neutronics_simulations.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
pytest tests/test_neutronics_model.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
# pytest tests/test_neutronics_utils.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
pytest tests/test_reactor_neutronics.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
pytest tests/test_shape_neutronics.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
python tests/notebook_testing.py
pytest tests/test_settings.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
pytest tests/test_materials.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
pytest tests/test_tallies/ -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
pytest tests/test_system/ -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
87 changes: 87 additions & 0 deletions examples/cell_tally_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# A minimal example that obtains TBR on the blanket and fast neutron flux on all
# cells in the DAGMC geometry.
# Particular emphasis is placed on explaining the openmc-dagmc-wrapper
# extentions of openmc base classes.

import tarfile
import urllib.request

import openmc
import openmc_dagmc_wrapper as odw
from openmc_plasma_source import FusionRingSource

# downloads a dagmc file for use in the example
url = "https://github.com/fusion-energy/neutronics_workflow/archive/refs/tags/v0.0.2.tar.gz"
urllib.request.urlretrieve(url, "v0.0.2.tar.gz")
tar = tarfile.open("v0.0.2.tar.gz", "r:gz")
tar.extractall(".")
tar.close()
h5m_filename = "neutronics_workflow-0.0.2/example_02_multi_volume_cell_tally/stage_2_output/dagmc.h5m"


# creates a geometry object from a DAGMC geometry.
# In this case the geometry doen't have a graveyard cell.
# So a set of 6 CSG surfaces are automatically made and added to the geometry
geometry = odw.Geometry(h5m_filename=h5m_filename)

# Creates the materials to use in the problem using by linking the material
# tags in the DAGMC h5m file with material definitions in the
# neutronics-material-maker. One could also use openmc.Material or nmm.Material
# objects instead of the strings used here
materials = odw.Materials(
h5m_filename=h5m_filename,
correspondence_dict={
"blanket_mat": "Li4SiO4",
"blanket_rear_wall_mat": "Be",
"center_column_shield_mat": "Be",
"divertor_mat": "Be",
"firstwall_mat": "Be",
"inboard_tf_coils_mat": "Be",
"pf_coil_case_mat": "Be",
"pf_coil_mat": "Be",
"tf_coil_mat": "Be",
},
)

# A cell tally allows a set of standard tally types (made from filters and
# scores) to be applied to a DAGMC material or a volume
# This cell tally applies a TBR tally to the volume(s) labeled with the
# blanket_mat tag in the DAGMC geometry
tally1 = odw.CellTally(
tally_type="TBR",
target="blanket_mat",
materials=materials)

# This cell tally obtains the neutron fast flux on all volumes in the problem
tally2 = odw.CellTallies(
tally_types=["neutron_fast_flux"],
targets="all_volumes",
h5m_filename=h5m_filename)

# no modifications are made to the default openmc.Tallies
tallies = openmc.Tallies([tally1] + tally2.tallies)

# Creates and openmc settings object with the run mode set to 'fixed source'
# and the number of inactivate particles set to zero. Setting these to values
# by default means less code is needed by the user and less chance of simulating
# batches that don't contribute to the tallies
settings = odw.FusionSettings()
settings.batches = 1
settings.particles = 100
# assigns a ring source of DT energy neutrons to the source using the
# openmc_plasma_source package
settings.source = FusionRingSource(fuel="DT", radius=350)


# no modifications are made to the default openmc.Model object
my_model = openmc.Model(
materials=materials, geometry=geometry, settings=settings, tallies=tallies
)
statepoint_file = my_model.run()

# processes the output h5 file. the process_results function contains logic on
# how to process each tally with respect to the tally multipliers and units
# involved. The fusion power input allows tallies to be scaled from the units
# of per source neutron to units such as Watts (for heating), Sv per second
# (for dose) and other convenient units.
odw.process_results(statepoint_file, fusion_power=1e9)
86 changes: 86 additions & 0 deletions examples/regular_2d_mesh_tally_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# A minimal example that obtains TBR on the blanket and fast neutron flux on all
# cells in the DAGMC geometry.
# Particular emphasis is placed on explaining the openmc-dagmc-wrapper
# extentions of openmc base classes.

import tarfile
import urllib.request

import openmc
import openmc_dagmc_wrapper as odw
from openmc_plasma_source import FusionRingSource


# downloads a dagmc file for use in the example
# url = "https://github.com/fusion-energy/neutronics_workflow/archive/refs/tags/v0.0.2.tar.gz"
# urllib.request.urlretrieve(url, "v0.0.2.tar.gz")
# tar = tarfile.open("v0.0.2.tar.gz", "r:gz")
# tar.extractall(".")
# tar.close()
h5m_filename = "neutronics_workflow-0.0.2/example_02_multi_volume_cell_tally/stage_2_output/dagmc.h5m"
h5m_filename = "neutronics_workflow-0.0.2/example_02_multi_volume_cell_tally/stage_2_output/dagmc_no_grave_yard.h5m"


# creates a geometry object from a DAGMC geometry.
# In this case the geometry doen't have a graveyard cell.
# So a set of 6 CSG surfaces are automatically made and added to the geometry
geometry = odw.Geometry(h5m_filename=h5m_filename)

# Creates the materials to use in the problem using by linking the material
# tags in the DAGMC h5m file with material definitions in the
# neutronics-material-maker. One could also use openmc.Material or nmm.Material
# objects instead of the strings used here
materials = odw.Materials(
h5m_filename=h5m_filename,
correspondence_dict={
"blanket_mat": "Li4SiO4",
"blanket_rear_wall_mat": "Be",
"center_column_shield_mat": "Be",
"divertor_mat": "Be",
"firstwall_mat": "Be",
"inboard_tf_coils_mat": "Be",
"pf_coil_case_mat": "Be",
"pf_coil_mat": "Be",
"tf_coil_mat": "Be",
},
)

# A MeshTally2D tally allows a set of standard tally types (made from filters
# and scores) to be applied to the DAGMC geometry. By default the mesh will be
# applied across the entire geomtry with and the size of the geometry is
# automatically found.

tally1 = odw.MeshTally2D(
tally_type="photon_effective_dose", plane="xy", bounding_box=h5m_filename
)
tally2 = odw.MeshTally2D(
tally_type="neutron_effective_dose", plane="xy", bounding_box=h5m_filename
)

# no modifications are made to the default openmc.Tallies
tallies = openmc.Tallies([tally1, tally2])

# Creates and openmc settings object with the run mode set to 'fixed source'
# and the number of inactivate particles set to zero. Setting these to values
# by default means less code is needed by the user and less chance of simulating
# batches that don't contribute to the tallies
settings = odw.FusionSettings()
settings.batches = 2
settings.particles = 100
settings.photon_transport = True
# assigns a ring source of DT energy neutrons to the source using the
# openmc_plasma_source package
settings.source = FusionRingSource(fuel="DT", radius=350)

# no modifications are made to the default openmc.Model object
my_model = openmc.Model(
materials=materials, geometry=geometry, settings=settings, tallies=tallies
)
statepoint_file = my_model.run()

# processes the output h5 file. The process_results function contains logic on
# how to process each tally with respect to the tally multipliers and units
# involved. The fusion power input allows tallies to be scaled from the units
# of per source neutron to units such as Watts (for heating), Sv per second
# (for dose) and other convenient units.
odw.process_results(statepoint_file, fusion_power=1e9)
79 changes: 79 additions & 0 deletions examples/regular_3d_mesh_tally_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# A minimal example that obtains TBR on the blanket and fast neutron flux on all
# cells in the DAGMC geometry.
# Particular emphasis is placed on explaining the openmc-dagmc-wrapper
# extentions of openmc base classes.

import tarfile
import urllib.request

import openmc
import openmc_dagmc_wrapper as odw
from openmc_plasma_source import FusionRingSource

# downloads a dagmc file for use in the example
# url = "https://github.com/fusion-energy/neutronics_workflow/archive/refs/tags/v0.0.2.tar.gz"
# urllib.request.urlretrieve(url, "v0.0.2.tar.gz")
# tar = tarfile.open("v0.0.2.tar.gz", "r:gz")
# tar.extractall(".")
# tar.close()
h5m_filename = "neutronics_workflow-0.0.2/example_02_multi_volume_cell_tally/stage_2_output/dagmc.h5m"


# creates a geometry object from a DAGMC geometry.
# In this case the geometry doen't have a graveyard cell.
# So a set of 6 CSG surfaces are automatically made and added to the geometry
geometry = odw.Geometry(h5m_filename=h5m_filename)

# Creates the materials to use in the problem using by linking the material
# tags in the DAGMC h5m file with material definitions in the
# neutronics-material-maker. One could also use openmc.Material or nmm.Material
# objects instead of the strings used here
materials = odw.Materials(
h5m_filename=h5m_filename,
correspondence_dict={
"blanket_mat": "Li4SiO4",
"blanket_rear_wall_mat": "Be",
"center_column_shield_mat": "Be",
"divertor_mat": "Be",
"firstwall_mat": "Be",
"inboard_tf_coils_mat": "Be",
"pf_coil_case_mat": "Be",
"pf_coil_mat": "Be",
"tf_coil_mat": "Be",
},
)

# A MeshTally3D tally allows a set of standard tally types (made from filters
# and scores) to be applied to the DAGMC geometry. By default the mesh will be
# applied across the entire geomtry with and the size of the geometry is
# automatically found.
tally1 = odw.MeshTally3D(
tally_type="neutron_effective_dose",
bounding_box=h5m_filename)

# no modifications are made to the default openmc.Tallies
tallies = openmc.Tallies([tally1])

# Creates and openmc settings object with the run mode set to 'fixed source'
# and the number of inactivate particles set to zero. Setting these to values
# by default means less code is needed by the user and less chance of simulating
# batches that don't contribute to the tallies
settings = odw.FusionSettings()
settings.batches = 1
settings.particles = 100
# assigns a ring source of DT energy neutrons to the source using the
# openmc_plasma_source package
settings.source = FusionRingSource(fuel="DT", radius=350)

# no modifications are made to the default openmc.Model object
my_model = openmc.Model(
materials=materials, geometry=geometry, settings=settings, tallies=tallies
)
statepoint_file = my_model.run()

# processes the output h5 file. The process_results function contains logic on
# how to process each tally with respect to the tally multipliers and units
# involved. The fusion power input allows tallies to be scaled from the units
# of per source neutron to units such as Watts (for heating), Sv per second
# (for dose) and other convenient units.
odw.process_results(statepoint_file, fusion_power=1e9)
Loading

0 comments on commit 3d62b9a

Please sign in to comment.