Skip to content

Commit 3806834

Browse files
authored
Merge pull request #96 from fusion-energy/develop
Allow bounding box from geomentry.corners()
2 parents 3d0f7b8 + 6880902 commit 3806834

File tree

11 files changed

+132
-34
lines changed

11 files changed

+132
-34
lines changed

.circleci/config.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ jobs:
3030
command:
3131
pytest tests/test_settings.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
3232

33+
- run:
34+
name: run tests Geometry()
35+
command:
36+
pytest tests/test_geometry.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
37+
3338
- run:
3439
name: run tests Materials()
3540
command:

.github/workflows/ci_with_install.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ jobs:
3232
pytest tests/test_neutronics_utils.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
3333
pytest tests/test_example_neutronics_simulations.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
3434
pytest tests/test_settings.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
35+
pytest tests/test_geometry.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
3536
pytest tests/test_materials.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
3637
pytest tests/test_tallies/ -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
3738
pytest tests/test_system/ -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml

examples/regular_2d_mesh_tally_example.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
# Particular emphasis is placed on explaining the openmc-dagmc-wrapper
44
# extentions of openmc base classes.
55

6-
import tarfile
7-
import urllib.request
86

97
import openmc
108
import openmc_dagmc_wrapper as odw
119
from openmc_plasma_source import FusionRingSource
12-
from dagmc_bounding_box import DagmcBoundingBox
1310

1411
# downloads a dagmc file for use in the example
12+
# import tarfile
13+
# import urllib.request
1514
# url = "https://github.com/fusion-energy/neutronics_workflow/archive/refs/tags/v0.0.2.tar.gz"
1615
# urllib.request.urlretrieve(url, "v0.0.2.tar.gz")
1716
# tar = tarfile.open("v0.0.2.tar.gz", "r:gz")
@@ -45,8 +44,9 @@
4544
)
4645

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

5151

5252
# A MeshTally2D tally allows a set of standard tally types (made from filters

examples/regular_3d_mesh_tally_example.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
# Particular emphasis is placed on explaining the openmc-dagmc-wrapper
44
# extentions of openmc base classes.
55

6-
import tarfile
7-
import urllib.request
86

97
import openmc
108
import openmc_dagmc_wrapper as odw
119
from openmc_plasma_source import FusionRingSource
12-
from dagmc_bounding_box import DagmcBoundingBox
10+
1311

1412
# downloads a dagmc file for use in the example
13+
# import tarfile
14+
# import urllib.request
1515
# url = "https://github.com/fusion-energy/neutronics_workflow/archive/refs/tags/v0.0.2.tar.gz"
1616
# urllib.request.urlretrieve(url, "v0.0.2.tar.gz")
1717
# tar = tarfile.open("v0.0.2.tar.gz", "r:gz")
@@ -45,8 +45,9 @@
4545
)
4646

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

5152
# A MeshTally3D tally allows a set of standard tally types (made from filters
5253
# and scores) to be applied to the DAGMC geometry. By default the mesh will be

openmc_dagmc_wrapper/Geometry.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import dagmc_h5m_file_inspector as di
44
import openmc
55
from numpy import cos, sin
6+
from dagmc_bounding_box import DagmcBoundingBox
67

78

89
class Geometry(openmc.Geometry):
@@ -25,16 +26,30 @@ class Geometry(openmc.Geometry):
2526

2627
def __init__(
2728
self,
28-
h5m_filename: str = None,
29+
h5m_filename: str,
2930
reflective_angles: Tuple[float, float] = None,
3031
graveyard_box=None,
3132
):
3233
self.h5m_filename = h5m_filename
3334
self.reflective_angles = reflective_angles
3435
self.graveyard_box = graveyard_box
36+
self.dagmc_bounding_box = DagmcBoundingBox(h5m_filename)
3537

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

40+
def corners(
41+
self, expand: Tuple[float, float, float] = None
42+
) -> Tuple[Tuple[float, float, float], Tuple[float, float, float]]:
43+
"""Gets the lower left corner and upper right corner of the DAGMC
44+
geometry
45+
Args:
46+
expand:
47+
Returns:
48+
A tuple of two coordinates
49+
"""
50+
51+
return self.dagmc_bounding_box.corners(expand)
52+
3853
def make_root(self):
3954

4055
# this is the underlying geometry container that is filled with the

run_tests.sh

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
pytest tests/test_example_neutronics_simulations.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
2-
pytest tests/test_materials.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
3-
pytest tests/test_tallies/test_mesh_tallies.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
4-
pytest tests/test_system.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
5-
# pytest tests/test_neutronics_utils.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
6-
# pytest tests/test_reactor_neutronics.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
7-
# pytest tests/test_shape_neutronics.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
8-
python tests/notebook_testing.py
1+
2+
pytest tests/test_neutronics_utils.py -v
3+
pytest tests/test_example_neutronics_simulations.py -v
4+
pytest tests/test_settings.py -v
5+
pytest tests/test_geometry.py -v
6+
pytest tests/test_materials.py -v
7+
pytest tests/test_tallies/ -v
8+
pytest tests/test_system/ -v
9+
python tests/notebook_testing.py -v

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"plotly",
2828
"defusedxml",
2929
"dagmc_h5m_file_inspector",
30+
"dagmc_bounding_box",
3031
],
3132
# openmc, dagmc, moab are also needed and embree and double down are also
3233
# optionally needed but not avaible on PyPi

tests/test_geometry.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import tarfile
2+
import unittest
3+
import urllib.request
4+
from pathlib import Path
5+
6+
import openmc
7+
import openmc_dagmc_wrapper as odw
8+
9+
10+
class TestSettings(unittest.TestCase):
11+
"""Tests the geometry.py file functionality"""
12+
13+
def setUp(self):
14+
15+
if not Path("tests/v0.0.2.tar.gz").is_file():
16+
url = "https://github.com/fusion-energy/neutronics_workflow/archive/refs/tags/v0.0.2.tar.gz"
17+
urllib.request.urlretrieve(url, "tests/v0.0.2.tar.gz")
18+
19+
tar = tarfile.open("tests/v0.0.2.tar.gz", "r:gz")
20+
tar.extractall("tests")
21+
tar.close()
22+
23+
self.h5m_filename_smaller = "tests/neutronics_workflow-0.0.2/example_01_single_volume_cell_tally/stage_2_output/dagmc.h5m"
24+
self.h5m_filename_bigger = "tests/neutronics_workflow-0.0.2/example_02_multi_volume_cell_tally/stage_2_output/dagmc.h5m"
25+
26+
self.material_description_bigger = {
27+
"pf_coil_case_mat": "Be",
28+
"center_column_shield_mat": "Be",
29+
"blanket_rear_wall_mat": "Be",
30+
"divertor_mat": "Be",
31+
"tf_coil_mat": "Be",
32+
"pf_coil_mat": "Be",
33+
"inboard_tf_coils_mat": "Be",
34+
"blanket_mat": "Be",
35+
"firstwall_mat": "Be",
36+
}
37+
38+
def test_attributes(self):
39+
my_geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller)
40+
assert my_geometry.reflective_angles is None
41+
assert my_geometry.graveyard_box is None
42+
43+
def test_corners_types(self):
44+
"""checks the corner method returns the correct types"""
45+
my_geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller)
46+
assert isinstance(my_geometry.corners(), tuple)
47+
assert isinstance(my_geometry.corners()[0], tuple)
48+
assert isinstance(my_geometry.corners()[1], tuple)
49+
assert isinstance(my_geometry.corners()[0][0], float)
50+
assert isinstance(my_geometry.corners()[0][1], float)
51+
assert isinstance(my_geometry.corners()[0][2], float)
52+
assert isinstance(my_geometry.corners()[1][0], float)
53+
assert isinstance(my_geometry.corners()[1][1], float)
54+
assert isinstance(my_geometry.corners()[1][2], float)
55+
56+
def test_corners_dimensions(self):
57+
"""checks length of tuples returned"""
58+
my_geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller)
59+
assert len(my_geometry.corners()) == 2
60+
assert len(my_geometry.corners()[0]) == 3
61+
assert len(my_geometry.corners()[1]) == 3
62+
63+
def test_corners_expand_increases_size(self):
64+
"""checks the expand increases the value returned"""
65+
my_geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller)
66+
small_corners = my_geometry.corners()
67+
big_corners = my_geometry.corners(expand=(1, 2, 3))
68+
69+
assert small_corners[0][0] - 1 == big_corners[0][0]
70+
assert small_corners[0][1] - 2 == big_corners[0][1]
71+
assert small_corners[0][2] - 3 == big_corners[0][2]
72+
73+
assert small_corners[1][0] + 1 == big_corners[1][0]
74+
assert small_corners[1][1] + 2 == big_corners[1][1]
75+
assert small_corners[1][2] + 3 == big_corners[1][2]

tests/test_system/test_system_single_volume.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import neutronics_material_maker as nmm
88
import openmc
99
import openmc_dagmc_wrapper as odw
10-
from dagmc_bounding_box import DagmcBoundingBox
1110
from remove_dagmc_tags import remove_tags
1211

1312

@@ -271,7 +270,7 @@ def test_neutronics_component_2d_mesh_simulation(self):
271270
my_tallies = odw.MeshTallies2D(
272271
tally_types=["heating"],
273272
planes=["xy", "xz", "yz"],
274-
bounding_box=DagmcBoundingBox(self.h5m_filename_smaller).corners(),
273+
bounding_box=geometry.corners(),
275274
)
276275

277276
my_model = openmc.model.Model(
@@ -304,7 +303,7 @@ def test_neutronics_component_3d_mesh_simulation(self):
304303

305304
my_tallies = odw.MeshTallies3D(
306305
tally_types=["heating", "(n,Xt)"],
307-
bounding_box=DagmcBoundingBox(self.h5m_filename_smaller).corners(),
306+
bounding_box=geometry.corners(),
308307
)
309308

310309
my_model = openmc.model.Model(
@@ -339,13 +338,13 @@ def test_neutronics_component_3d_and_2d_mesh_simulation(self):
339338

340339
my_3d_tally = odw.MeshTally3D(
341340
tally_type="heating",
342-
bounding_box=DagmcBoundingBox(self.h5m_filename_smaller).corners(),
341+
bounding_box=geometry.corners(),
343342
)
344343

345344
my_2d_tallies = odw.MeshTallies2D(
346345
planes=["xz", "xy", "yz"],
347346
tally_types=["heating"],
348-
bounding_box=DagmcBoundingBox(self.h5m_filename_smaller).corners(),
347+
bounding_box=geometry.corners(),
349348
)
350349

351350
my_model = openmc.model.Model(

tests/test_tallies/test_mesh_tally_2d.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import openmc
77
import openmc_dagmc_wrapper as odw
88
from openmc_plasma_source import FusionRingSource
9-
from dagmc_bounding_box import DagmcBoundingBox
109

1110

1211
class TestMeshTally2D(unittest.TestCase):
@@ -59,19 +58,19 @@ def test_shape_of_resulting_png(self):
5958
tally1 = odw.MeshTally2D(
6059
tally_type="neutron_flux",
6160
plane="xy",
62-
bounding_box=DagmcBoundingBox(self.h5m_filename_smaller).corners(),
61+
bounding_box=geometry.corners(),
6362
mesh_resolution=(10, 200),
6463
)
6564
tally2 = odw.MeshTally2D(
6665
tally_type="neutron_flux",
6766
plane="xz",
68-
bounding_box=DagmcBoundingBox(self.h5m_filename_smaller).corners(),
67+
bounding_box=geometry.corners(),
6968
mesh_resolution=(20, 100),
7069
)
7170
tally3 = odw.MeshTally2D(
7271
tally_type="neutron_flux",
7372
plane="yz",
74-
bounding_box=DagmcBoundingBox(self.h5m_filename_smaller).corners(),
73+
bounding_box=geometry.corners(),
7574
mesh_resolution=(30, 500),
7675
)
7776

@@ -95,22 +94,23 @@ def test_shape_of_resulting_png(self):
9594
def test_correct_resolution(self):
9695
"""Tests that the mesh resolution is in accordance with the plane
9796
"""
97+
geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller)
9898
tally_xy = odw.MeshTally2D(
9999
tally_type="neutron_flux",
100100
plane="xy",
101-
bounding_box=DagmcBoundingBox(self.h5m_filename_smaller).corners(),
101+
bounding_box=geometry.corners(),
102102
mesh_resolution=(10, 20),
103103
)
104104
tally_yz = odw.MeshTally2D(
105105
tally_type="neutron_flux",
106106
plane="yz",
107-
bounding_box=DagmcBoundingBox(self.h5m_filename_smaller).corners(),
107+
bounding_box=geometry.corners(),
108108
mesh_resolution=(10, 20),
109109
)
110110
tally_xz = odw.MeshTally2D(
111111
tally_type="neutron_flux",
112112
plane="xz",
113-
bounding_box=DagmcBoundingBox(self.h5m_filename_smaller).corners(),
113+
bounding_box=geometry.corners(),
114114
mesh_resolution=(10, 20),
115115
)
116116

0 commit comments

Comments
 (0)