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 #96 from fusion-energy/develop
Browse files Browse the repository at this point in the history
Allow bounding box from geomentry.corners()
  • Loading branch information
shimwell authored Dec 8, 2021
2 parents 3d0f7b8 + 6880902 commit 3806834
Show file tree
Hide file tree
Showing 11 changed files with 132 additions and 34 deletions.
5 changes: 5 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ jobs:
command:
pytest tests/test_settings.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml

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

- run:
name: run tests Materials()
command:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci_with_install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
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_settings.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
pytest tests/test_geometry.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
10 changes: 5 additions & 5 deletions examples/regular_2d_mesh_tally_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
# 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
from dagmc_bounding_box import DagmcBoundingBox

# downloads a dagmc file for use in the example
# import tarfile
# import urllib.request
# 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")
Expand Down Expand Up @@ -45,8 +44,9 @@
)

# 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
my_bounding_box = DagmcBoundingBox(h5m_filename).corners()
# 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
Expand Down
11 changes: 6 additions & 5 deletions examples/regular_3d_mesh_tally_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
# 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
from dagmc_bounding_box import DagmcBoundingBox


# downloads a dagmc file for use in the example
# import tarfile
# import urllib.request
# 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")
Expand Down Expand Up @@ -45,8 +45,9 @@
)

# 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
my_bounding_box = DagmcBoundingBox(h5m_filename).corners()
# 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
Expand Down
17 changes: 16 additions & 1 deletion openmc_dagmc_wrapper/Geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import dagmc_h5m_file_inspector as di
import openmc
from numpy import cos, sin
from dagmc_bounding_box import DagmcBoundingBox


class Geometry(openmc.Geometry):
Expand All @@ -25,16 +26,30 @@ class Geometry(openmc.Geometry):

def __init__(
self,
h5m_filename: str = None,
h5m_filename: str,
reflective_angles: Tuple[float, float] = None,
graveyard_box=None,
):
self.h5m_filename = 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(
self, expand: Tuple[float, float, float] = None
) -> Tuple[Tuple[float, float, float], Tuple[float, float, float]]:
"""Gets the lower left corner and upper right corner of the DAGMC
geometry
Args:
expand:
Returns:
A tuple of two coordinates
"""

return self.dagmc_bounding_box.corners(expand)

def make_root(self):

# this is the underlying geometry container that is filled with the
Expand Down
17 changes: 9 additions & 8 deletions run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
pytest tests/test_example_neutronics_simulations.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/test_mesh_tallies.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
pytest tests/test_system.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_neutronics_utils.py -v
pytest tests/test_example_neutronics_simulations.py -v
pytest tests/test_settings.py -v
pytest tests/test_geometry.py -v
pytest tests/test_materials.py -v
pytest tests/test_tallies/ -v
pytest tests/test_system/ -v
python tests/notebook_testing.py -v
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"plotly",
"defusedxml",
"dagmc_h5m_file_inspector",
"dagmc_bounding_box",
],
# openmc, dagmc, moab are also needed and embree and double down are also
# optionally needed but not avaible on PyPi
Expand Down
75 changes: 75 additions & 0 deletions tests/test_geometry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import tarfile
import unittest
import urllib.request
from pathlib import Path

import openmc
import openmc_dagmc_wrapper as odw


class TestSettings(unittest.TestCase):
"""Tests the geometry.py file functionality"""

def setUp(self):

if not Path("tests/v0.0.2.tar.gz").is_file():
url = "https://github.com/fusion-energy/neutronics_workflow/archive/refs/tags/v0.0.2.tar.gz"
urllib.request.urlretrieve(url, "tests/v0.0.2.tar.gz")

tar = tarfile.open("tests/v0.0.2.tar.gz", "r:gz")
tar.extractall("tests")
tar.close()

self.h5m_filename_smaller = "tests/neutronics_workflow-0.0.2/example_01_single_volume_cell_tally/stage_2_output/dagmc.h5m"
self.h5m_filename_bigger = "tests/neutronics_workflow-0.0.2/example_02_multi_volume_cell_tally/stage_2_output/dagmc.h5m"

self.material_description_bigger = {
"pf_coil_case_mat": "Be",
"center_column_shield_mat": "Be",
"blanket_rear_wall_mat": "Be",
"divertor_mat": "Be",
"tf_coil_mat": "Be",
"pf_coil_mat": "Be",
"inboard_tf_coils_mat": "Be",
"blanket_mat": "Be",
"firstwall_mat": "Be",
}

def test_attributes(self):
my_geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller)
assert my_geometry.reflective_angles is None
assert my_geometry.graveyard_box is None

def test_corners_types(self):
"""checks the corner method returns the correct types"""
my_geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller)
assert isinstance(my_geometry.corners(), tuple)
assert isinstance(my_geometry.corners()[0], tuple)
assert isinstance(my_geometry.corners()[1], tuple)
assert isinstance(my_geometry.corners()[0][0], float)
assert isinstance(my_geometry.corners()[0][1], float)
assert isinstance(my_geometry.corners()[0][2], float)
assert isinstance(my_geometry.corners()[1][0], float)
assert isinstance(my_geometry.corners()[1][1], float)
assert isinstance(my_geometry.corners()[1][2], float)

def test_corners_dimensions(self):
"""checks length of tuples returned"""
my_geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller)
assert len(my_geometry.corners()) == 2
assert len(my_geometry.corners()[0]) == 3
assert len(my_geometry.corners()[1]) == 3

def test_corners_expand_increases_size(self):
"""checks the expand increases the value returned"""
my_geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller)
small_corners = my_geometry.corners()
big_corners = my_geometry.corners(expand=(1, 2, 3))

assert small_corners[0][0] - 1 == big_corners[0][0]
assert small_corners[0][1] - 2 == big_corners[0][1]
assert small_corners[0][2] - 3 == big_corners[0][2]

assert small_corners[1][0] + 1 == big_corners[1][0]
assert small_corners[1][1] + 2 == big_corners[1][1]
assert small_corners[1][2] + 3 == big_corners[1][2]
9 changes: 4 additions & 5 deletions tests/test_system/test_system_single_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import neutronics_material_maker as nmm
import openmc
import openmc_dagmc_wrapper as odw
from dagmc_bounding_box import DagmcBoundingBox
from remove_dagmc_tags import remove_tags


Expand Down Expand Up @@ -271,7 +270,7 @@ def test_neutronics_component_2d_mesh_simulation(self):
my_tallies = odw.MeshTallies2D(
tally_types=["heating"],
planes=["xy", "xz", "yz"],
bounding_box=DagmcBoundingBox(self.h5m_filename_smaller).corners(),
bounding_box=geometry.corners(),
)

my_model = openmc.model.Model(
Expand Down Expand Up @@ -304,7 +303,7 @@ def test_neutronics_component_3d_mesh_simulation(self):

my_tallies = odw.MeshTallies3D(
tally_types=["heating", "(n,Xt)"],
bounding_box=DagmcBoundingBox(self.h5m_filename_smaller).corners(),
bounding_box=geometry.corners(),
)

my_model = openmc.model.Model(
Expand Down Expand Up @@ -339,13 +338,13 @@ def test_neutronics_component_3d_and_2d_mesh_simulation(self):

my_3d_tally = odw.MeshTally3D(
tally_type="heating",
bounding_box=DagmcBoundingBox(self.h5m_filename_smaller).corners(),
bounding_box=geometry.corners(),
)

my_2d_tallies = odw.MeshTallies2D(
planes=["xz", "xy", "yz"],
tally_types=["heating"],
bounding_box=DagmcBoundingBox(self.h5m_filename_smaller).corners(),
bounding_box=geometry.corners(),
)

my_model = openmc.model.Model(
Expand Down
14 changes: 7 additions & 7 deletions tests/test_tallies/test_mesh_tally_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import openmc
import openmc_dagmc_wrapper as odw
from openmc_plasma_source import FusionRingSource
from dagmc_bounding_box import DagmcBoundingBox


class TestMeshTally2D(unittest.TestCase):
Expand Down Expand Up @@ -59,19 +58,19 @@ def test_shape_of_resulting_png(self):
tally1 = odw.MeshTally2D(
tally_type="neutron_flux",
plane="xy",
bounding_box=DagmcBoundingBox(self.h5m_filename_smaller).corners(),
bounding_box=geometry.corners(),
mesh_resolution=(10, 200),
)
tally2 = odw.MeshTally2D(
tally_type="neutron_flux",
plane="xz",
bounding_box=DagmcBoundingBox(self.h5m_filename_smaller).corners(),
bounding_box=geometry.corners(),
mesh_resolution=(20, 100),
)
tally3 = odw.MeshTally2D(
tally_type="neutron_flux",
plane="yz",
bounding_box=DagmcBoundingBox(self.h5m_filename_smaller).corners(),
bounding_box=geometry.corners(),
mesh_resolution=(30, 500),
)

Expand All @@ -95,22 +94,23 @@ def test_shape_of_resulting_png(self):
def test_correct_resolution(self):
"""Tests that the mesh resolution is in accordance with the plane
"""
geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller)
tally_xy = odw.MeshTally2D(
tally_type="neutron_flux",
plane="xy",
bounding_box=DagmcBoundingBox(self.h5m_filename_smaller).corners(),
bounding_box=geometry.corners(),
mesh_resolution=(10, 20),
)
tally_yz = odw.MeshTally2D(
tally_type="neutron_flux",
plane="yz",
bounding_box=DagmcBoundingBox(self.h5m_filename_smaller).corners(),
bounding_box=geometry.corners(),
mesh_resolution=(10, 20),
)
tally_xz = odw.MeshTally2D(
tally_type="neutron_flux",
plane="xz",
bounding_box=DagmcBoundingBox(self.h5m_filename_smaller).corners(),
bounding_box=geometry.corners(),
mesh_resolution=(10, 20),
)

Expand Down
6 changes: 3 additions & 3 deletions tests/test_tallies/test_mesh_tally_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import openmc
import openmc_dagmc_wrapper as odw
from dagmc_bounding_box import DagmcBoundingBox


class TestMeshTally3D(unittest.TestCase):
Expand Down Expand Up @@ -46,16 +45,17 @@ def incorrect_mesh_tally_3d_type():

def test_meshfilter_from_h5m_file(self):
# build
geometry = odw.Geometry(self.h5m_filename_smaller)
expected_mesh = openmc.RegularMesh(mesh_id=99, name="3d_mesh_expected")
bbox = DagmcBoundingBox(self.h5m_filename_smaller).corners()
bbox = geometry.corners()
expected_mesh.lower_left = bbox[0]
expected_mesh.upper_right = bbox[1]
expected_mesh.dimension = (100, 100, 100)

# run
my_tally = odw.MeshTally3D(
"heating",
bounding_box=DagmcBoundingBox(self.h5m_filename_smaller).corners(),
bounding_box=geometry.corners(),
)
produced_filter = my_tally.filters[-1]
produced_mesh = produced_filter.mesh
Expand Down

0 comments on commit 3806834

Please sign in to comment.