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

odw.Model #110

Merged
merged 27 commits into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9efd343
added a class Model
RemDelaporteMathurin Feb 15, 2022
321ad3b
added docstrings
RemDelaporteMathurin Feb 15, 2022
4dc06cd
fixed comments
RemDelaporteMathurin Feb 15, 2022
0e6acf4
Automated autopep8 fixes
Feb 15, 2022
dcb7c93
Merge branch 'odw_model' of https://github.com/fusion-energy/openmc-d…
RemDelaporteMathurin Feb 15, 2022
73fdc9e
Automated autopep8 fixes
Feb 15, 2022
b6ef6f4
added TODO
RemDelaporteMathurin Feb 15, 2022
9a8dc22
changed TODO
RemDelaporteMathurin Feb 15, 2022
769e65b
avoid redifining filter
RemDelaporteMathurin Feb 15, 2022
16fc3eb
Automated autopep8 fixes
Feb 15, 2022
1f910a6
test for upper_right too
RemDelaporteMathurin Feb 15, 2022
28dfd87
Automated autopep8 fixes
Feb 15, 2022
4c062d5
tests running locally
shimwell Feb 25, 2022
7b468ba
Automated autopep8 fixes
Feb 25, 2022
aebfcde
updated download url
shimwell Feb 26, 2022
20025d6
Merge branch 'odw_model' of github.com:fusion-energy/openmc-dagmc-wra…
shimwell Feb 26, 2022
755393b
fixed a few tests, removed complex graveyard process
shimwell Mar 2, 2022
7029896
fixed resolution bug
shimwell Mar 2, 2022
82ceaec
Automated autopep8 fixes
Mar 2, 2022
439f217
adding missing attributes
shimwell Mar 2, 2022
d7df03f
Merge branch 'odw_model' of github.com:fusion-energy/openmc-dagmc-wra…
shimwell Mar 2, 2022
c458566
[skip ci] sorted imports
shimwell Mar 2, 2022
ac6eb7d
tallies are not meshes so no bounding_box attribute
shimwell Mar 2, 2022
22f7284
Automated autopep8 fixes
Mar 2, 2022
265cb26
pep8 format
shimwell Mar 2, 2022
1b83d44
merge conflict
shimwell Mar 2, 2022
0c3f8bc
[skip ci] Apply formatting changes
shimwell Mar 2, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 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,11 +41,6 @@
},
)

# 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
Expand All @@ -56,12 +49,12 @@

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

# no modifications are made to the default openmc.Tallies
tallies = openmc.Tallies([tally1, tally2])
Expand All @@ -79,7 +72,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()
shimwell marked this conversation as resolved.
Show resolved Hide resolved
12 changes: 3 additions & 9 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,17 +42,13 @@
},
)

# 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
tally_type="neutron_effective_dose"
)

# no modifications are made to the default openmc.Tallies
Expand All @@ -72,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()
1 change: 1 addition & 0 deletions openmc_dagmc_wrapper/Geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def create_sphere_of_vacuum_surface(self):
be used as an alternative to the traditionally DAGMC graveyard cell"""

if self.graveyard_box is None:
# TODO this could be refactored using self.corners()
from dagmc_bounding_box import DagmcBoundingBox

self.graveyard_box = DagmcBoundingBox(self.h5m_filename).corners()
Expand Down
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
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
6 changes: 4 additions & 2 deletions openmc_dagmc_wrapper/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ def __init__(
plane="xy",
resolution=(400, 400),
plane_slice_location=(-1, 1),
bounding_box=None # TODO replace this by [(xmin, xmax), (ymin, ymax)]
# TODO replace this by bounds=[(xmin, xmax), (ymin, ymax)]
bounding_box=None
):
self.plane = plane
self.resolution = resolution
self.plane_slice_location = plane_slice_location
super().__init__(mesh_id, name)
self.set_dimension()
self.set_bounds(bounding_box)
if bounding_box is not None:
self.set_bounds(bounding_box)

def set_dimension(self):
if self.plane == "xy":
Expand Down
41 changes: 41 additions & 0 deletions openmc_dagmc_wrapper/model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import openmc

import openmc_dagmc_wrapper as odw


class Model(openmc.Model):
def __init__(
self,
geometry=None,
materials=None,
settings=None,
tallies=None,
plots=None
):
"""Inits Model

Args:
geometry (odw.Geometry, optional): Geometry information. Defaults
to None.
materials (odw.Materials, optional): Materials information.
Defaults to None.
settings (openmc.Settings, optional): Settings information.
Defaults to None.
tallies (openmc.Tallies, optional): Tallies information.
Defaults to None.
plots (openmc.Plots, optional): Plot information. Defaults to None.
"""
super().__init__(geometry, materials, settings, tallies, plots)
self.materials.checks(self.geometry.h5m_filename)
self.check_tallies_meshes_corners()

def check_tallies_meshes_corners(self):
"""Iterates through tallies and check if they have a RegularMesh2D.
If the RegularMesh2D doesn't have corners, add them from the geometry.
"""
for tally in self.tallies:
for filter in tally.filters:
if isinstance(filter, openmc.MeshFilter):
if isinstance(filter.mesh, odw.RegularMesh2D):
if filter.mesh.lower_left is None:
filter.mesh.set_bounds(self.geometry.corners())