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 #110 from fusion-energy/odw_model
Browse files Browse the repository at this point in the history
odw.Model
  • Loading branch information
shimwell authored Mar 2, 2022
2 parents 6254947 + 0c3f8bc commit 073641d
Show file tree
Hide file tree
Showing 27 changed files with 370 additions and 405 deletions.
24 changes: 0 additions & 24 deletions .github/workflows/autopep8.yml

This file was deleted.

32 changes: 32 additions & 0 deletions .github/workflows/black.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: black

on:
push:
paths:
- '**.py'

defaults:
run:
shell: bash

jobs:
black:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: 3.x
- name: Install black
run: |
python -m pip install --upgrade pip
pip install black
- name: Run black
run: |
black .
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "[skip ci] Apply formatting changes"
10 changes: 8 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,11 @@ dmypy.json
*.trelis
*.out
*.tar.gz
examples/neutronics_workflow-0.0.2/
tests/neutronics_workflow-0.0.2/

tests/example_01_single_volume_cell_tally/
tests/example_02_multi_volume_cell_tally/
tests/example_04_multi_volume_regular_mesh_tally/
tests/example_05_3D_unstructured_mesh_tally/
tests/output_files_produced.zip

_version.py
10 changes: 3 additions & 7 deletions examples/cell_tally_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,12 @@
# 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)
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)
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)
Expand Down
21 changes: 4 additions & 17 deletions examples/regular_2d_mesh_tally_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@
# 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
# Creates the materials to use in the problem 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",
Expand All @@ -43,25 +41,14 @@
},
)

# makes use of the dagmc-bound-box package to get the corners of the bounding
# box. This will be used to set the bounding box for the tally. This can be
# expanded with the expand keyword if needed
my_bounding_box = geometry.corners()


# 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=my_bounding_box)
tally2 = odw.MeshTally2D(
tally_type="neutron_effective_dose",
plane="xy",
bounding_box=my_bounding_box)
tally1 = odw.MeshTally2D(tally_type="photon_effective_dose", plane="xy")
tally2 = odw.MeshTally2D(tally_type="neutron_effective_dose", plane="xy")

# no modifications are made to the default openmc.Tallies
tallies = openmc.Tallies([tally1, tally2])
Expand All @@ -79,7 +66,7 @@
settings.source = FusionRingSource(fuel="DT", radius=350)

# no modifications are made to the default openmc.Model object
my_model = openmc.Model(
my_model = odw.Model(
materials=materials, geometry=geometry, settings=settings, tallies=tallies
)
statepoint_file = my_model.run()
14 changes: 3 additions & 11 deletions examples/regular_3d_mesh_tally_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@
# 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
# Creates the materials to use in the problem 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",
Expand All @@ -44,18 +42,12 @@
},
)

# makes use of the dagmc-bound-box package to get the corners of the bounding
# box. This will be used to set the bounding box for the tally. This can be
# expanded with the expand keyword if needed
my_bounding_box = geometry.corners()

# 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=my_bounding_box
)
tally1 = odw.MeshTally3D(tally_type="neutron_effective_dose")

# no modifications are made to the default openmc.Tallies
tallies = openmc.Tallies([tally1])
Expand All @@ -72,7 +64,7 @@
settings.source = FusionRingSource(fuel="DT", radius=350)

# no modifications are made to the default openmc.Model object
my_model = openmc.Model(
my_model = odw.Model(
materials=materials, geometry=geometry, settings=settings, tallies=tallies
)
statepoint_file = my_model.run()
55 changes: 13 additions & 42 deletions openmc_dagmc_wrapper/Geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,33 @@

import dagmc_h5m_file_inspector as di
import openmc
from numpy import cos, sin
from dagmc_bounding_box import DagmcBoundingBox
from numpy import cos, sin

from .utils import check_files_exists


class Geometry(openmc.Geometry):
"""A openmc.Geometry object with a DAGMC Universe. If the model
requires a graveyard bounding box this will be automatically added. When
simulating a sector model reflecting surfaces can be added to complete the
boundary conditions.
"""A openmc.Geometry object with a DAGMC Universe. When simulating a sector
model reflecting surfaces can be added to complete the boundary conditions.
Args:
h5m_filename: the filename of the h5m file containing the DAGMC
geometry.
reflective_angles: if a sector model is being simulated this argument
can be used to specify the angles (in radians) to use when
creating reflecting surfaces for a sector model.
graveyard_box: If a certain size of graveyard is required then the
upper left and lower right corners can be specified. If this is not
specified then the code checks to see if a graveyard exists and if
none are found then it makes the graveyard to encompass the geometry
"""

def __init__(
self,
h5m_filename: str,
reflective_angles: Tuple[float, float] = None,
graveyard_box=None,
):
self.h5m_filename = h5m_filename
check_files_exists(h5m_filename)
self.reflective_angles = reflective_angles
self.graveyard_box = graveyard_box
self.dagmc_bounding_box = DagmcBoundingBox(h5m_filename)

super().__init__(root=self.make_root())

def corners(
Expand All @@ -61,19 +55,15 @@ def make_root(self):
# made

if "graveyard" not in di.get_materials_from_h5m(self.h5m_filename):
# vac_surfs = self.create_cube_of_vacuum_surfaces()
# # creates a cube of surfaces for the boundary conditions
# region = +vac_surfs[0] & \
# -vac_surfs[1] & \
# +vac_surfs[2] & \
# -vac_surfs[3] & \
# +vac_surfs[4] & \
# -vac_surfs[5]
vac_surf = self.create_sphere_of_vacuum_surface()
vac_surf = openmc.Sphere(
r=1000000, # set to 10km to be big enough for models
surface_id=99999999, # set to large surface id to avoid overlaps
boundary_type="vacuum",
)
region = -vac_surf

containing_cell = openmc.Cell(
cell_id=9999, region=region, fill=dag_univ
cell_id=99999999, region=region, fill=dag_univ
)
root = [containing_cell]
else:
Expand Down Expand Up @@ -105,27 +95,8 @@ def make_root(self):
vac_surf = self.create_sphere_of_vacuum_surface()
region = -vac_surf & -reflective_1 & +reflective_2

containing_cell = openmc.Cell(
cell_id=9999, region=region, fill=dag_univ)
containing_cell = openmc.Cell(cell_id=9999, region=region, fill=dag_univ)

root = [containing_cell]

return root

def create_sphere_of_vacuum_surface(self):
"""Creates a single vacuum surfaces that surround the geometry and can
be used as an alternative to the traditionally DAGMC graveyard cell"""

if self.graveyard_box is None:
from dagmc_bounding_box import DagmcBoundingBox

self.graveyard_box = DagmcBoundingBox(self.h5m_filename).corners()
bbox = [[*self.graveyard_box[0]], [*self.graveyard_box[1]]]

largest_radius = 3 * max(max(bbox[0]), max(bbox[1]))

sphere_surface = openmc.Sphere(
r=largest_radius, surface_id=9999, boundary_type="vacuum"
)

return sphere_surface
12 changes: 4 additions & 8 deletions openmc_dagmc_wrapper/Materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,14 @@ class Materials(openmc.Materials):
input formats.
Args:
h5m_filename: the filename of the h5m file containing the DAGMC
geometry
correspondence_dict: A dictionary that maps the material tags present
within the DAGMC file with materials. Materials can be provided in
a variety of formats including neutronics_material_maker.Material
objects, strings or openmc.Material objects.
"""

def __init__(self, h5m_filename: str, correspondence_dict: dict):
def __init__(self, correspondence_dict: dict):
self.correspondence_dict = correspondence_dict
self.h5m_filename = h5m_filename
self.checks()
self.set_openmc_materials()
super().__init__(list(self.openmc_materials.values()))

Expand All @@ -43,14 +39,14 @@ def set_openmc_materials(self):

self.openmc_materials = openmc_materials

def checks(self):
materials_in_h5m = di.get_materials_from_h5m(self.h5m_filename)
def checks(self, h5m_filename):
materials_in_h5m = di.get_materials_from_h5m(h5m_filename)
# # checks all the required materials are present
for reactor_material in self.correspondence_dict.keys():
if reactor_material not in materials_in_h5m:
msg = (
f"material with tag {reactor_material} was not found in "
f"the dagmc h5m file. The DAGMC file {self.h5m_filename} "
f"the dagmc h5m file. The DAGMC file {h5m_filename} "
f"contains the following material tags {materials_in_h5m}."
)
raise ValueError(msg)
Expand Down
4 changes: 1 addition & 3 deletions openmc_dagmc_wrapper/Tally.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@ def compute_filters(tally_type):
energy_function_filter_n = openmc.EnergyFunctionFilter(
energy_bins_n, dose_coeffs_n
)
additional_filters = [
neutron_particle_filter,
energy_function_filter_n]
additional_filters = [neutron_particle_filter, energy_function_filter_n]
elif tally_type == "photon_effective_dose":
energy_function_filter_p = openmc.EnergyFunctionFilter(
energy_bins_p, dose_coeffs_p
Expand Down
2 changes: 2 additions & 0 deletions openmc_dagmc_wrapper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@
from .tallies import *

from .Settings import FusionSettings

from .model import Model
Loading

0 comments on commit 073641d

Please sign in to comment.