Skip to content

Commit 904c8a2

Browse files
authored
Merge pull request #80 from fusion-energy/develop
removing print statements
2 parents f0908be + 92f40c6 commit 904c8a2

File tree

4 files changed

+120
-25
lines changed

4 files changed

+120
-25
lines changed

openmc_dagmc_wrapper/Tally.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from openmc.data import REACTION_MT, REACTION_NAME
77

88
from openmc_dagmc_wrapper import Materials
9-
from .utils import create_material, silently_remove_file, find_bounding_box
9+
from .utils import find_bounding_box
1010

1111

1212
class Tally(openmc.Tally):
@@ -33,8 +33,12 @@ def tally_type(self, value):
3333
output_options = (
3434
[
3535
"TBR",
36-
"heating",
3736
"flux",
37+
"heating",
38+
"photon_heating",
39+
"neutron_heating",
40+
"neutron_flux",
41+
"photon_flux",
3842
"absorption",
3943
"neutron_effective_dose",
4044
"photon_effective_dose",
@@ -57,6 +61,9 @@ def tally_type(self, value):
5761

5862
def set_score(self):
5963
flux_scores = [
64+
"flux",
65+
"neutron_flux",
66+
"photon_flux",
6067
"neutron_fast_flux",
6168
"photon_fast_flux",
6269
"neutron_spectra",
@@ -141,11 +148,11 @@ class CellTallies:
141148
Usage:
142149
my_mats = odw.Materials(....)
143150
my_tallies = odw.CellTallies(
144-
tally_types=['TBR', "flux"],
151+
tally_types=['TBR', "neutron_flux"],
145152
target=["Be", 2],
146153
materials=my_mats
147154
)
148-
my_tallies = odw.CellTallies(tally_types=['TBR', "flux"], target=[2])
155+
my_tallies = odw.CellTallies(tally_types=['TBR', "neutron_flux"], target=[2])
149156
150157
Args:
151158
tally_types ([type]): [description]
@@ -451,14 +458,25 @@ def compute_filters(tally_type):
451458
neutron_particle_filter = openmc.ParticleFilter(["neutron"])
452459

453460
additional_filters = []
454-
if tally_type == "neutron_fast_flux":
461+
if tally_type == "neutron_flux":
462+
additional_filters = [neutron_particle_filter]
463+
elif tally_type == "photon_flux":
464+
additional_filters = [photon_particle_filter]
465+
466+
elif tally_type == "neutron_heating":
467+
additional_filters = [neutron_particle_filter]
468+
elif tally_type == "photon_heating":
469+
additional_filters = [photon_particle_filter]
470+
471+
elif tally_type == "neutron_fast_flux":
455472
energy_bins = [1e6, 1000e6]
456473
energy_filter = openmc.EnergyFilter(energy_bins)
457474
additional_filters = [neutron_particle_filter, energy_filter]
458475
elif tally_type == "photon_fast_flux":
459476
energy_bins = [1e6, 1000e6]
460477
energy_filter = openmc.EnergyFilter(energy_bins)
461478
additional_filters = [photon_particle_filter, energy_filter]
479+
462480
elif tally_type == "neutron_spectra":
463481
energy_bins = openmc.mgxs.GROUP_STRUCTURES["CCFE-709"]
464482
energy_filter = openmc.EnergyFilter(energy_bins)
@@ -467,6 +485,7 @@ def compute_filters(tally_type):
467485
energy_bins = openmc.mgxs.GROUP_STRUCTURES["CCFE-709"]
468486
energy_filter = openmc.EnergyFilter(energy_bins)
469487
additional_filters = [photon_particle_filter, energy_filter]
488+
470489
elif tally_type == "neutron_effective_dose":
471490
energy_function_filter_n = openmc.EnergyFunctionFilter(
472491
energy_bins_n, dose_coeffs_n

openmc_dagmc_wrapper/utils.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ def process_results(
175175

176176
# access the tallies
177177
for tally in statepoint.tallies.values():
178-
print(f"processing {tally.name}")
179178
if tally.name.endswith("TBR"):
180179

181180
data_frame = tally.get_pandas_dataframe()
@@ -322,7 +321,6 @@ def process_results(
322321
",", "-"), )
323322

324323
elif "_on_3D_mesh" in tally.name:
325-
print(f"processing {tally.name}")
326324
mesh_id = 1
327325
mesh = statepoint.meshes[mesh_id]
328326

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
2+
import tarfile
3+
import unittest
4+
import urllib.request
5+
from pathlib import Path
6+
7+
import openmc
8+
import openmc_dagmc_wrapper as odw
9+
from openmc_plasma_source import FusionRingSource
10+
11+
12+
class TestMeshTally2D(unittest.TestCase):
13+
"""Tests the MeshTally2D class functionality"""
14+
15+
def setUp(self):
16+
17+
if not Path("tests/v0.0.2.tar.gz").is_file():
18+
url = "https://github.com/fusion-energy/neutronics_workflow/archive/refs/tags/v0.0.2.tar.gz"
19+
urllib.request.urlretrieve(url, "tests/v0.0.2.tar.gz")
20+
21+
tar = tarfile.open("tests/v0.0.2.tar.gz", "r:gz")
22+
tar.extractall("tests")
23+
tar.close()
24+
25+
self.h5m_filename_smaller = "tests/neutronics_workflow-0.0.2/example_01_single_volume_cell_tally/stage_2_output/dagmc.h5m"
26+
self.h5m_filename_bigger = "tests/neutronics_workflow-0.0.2/example_02_multi_volume_cell_tally/stage_2_output/dagmc.h5m"
27+
28+
def test_incorrect_mesh_tally_2d(self):
29+
"""Set a mesh_tally_2d that is not accepted which should raise an
30+
error"""
31+
def incorrect_mesh_tally_2d():
32+
odw.MeshTally2D("coucou", plane="xy")
33+
34+
self.assertRaises(ValueError, incorrect_mesh_tally_2d)
35+
36+
def test_incorrect_mesh_tally_2d_type(self):
37+
"""Set a mesh_tally_2d that is the wrong type which should raise an
38+
error"""
39+
def incorrect_mesh_tally_2d_type():
40+
odw.MeshTally2D(1, plane="xy")
41+
42+
self.assertRaises(TypeError, incorrect_mesh_tally_2d_type)
43+
44+
def test_shape_of_resulting_png(self):
45+
"""Runs a simulation with a 2d mesh tally and checks png images are
46+
produced"""
47+
48+
geometry = odw.Geometry(h5m_filename=self.h5m_filename_smaller)
49+
materials = odw.Materials(
50+
h5m_filename=self.h5m_filename_smaller,
51+
correspondence_dict={
52+
"mat1": "Be",
53+
},
54+
)
55+
tally1 = odw.MeshTally2D(
56+
tally_type="neutron_flux",
57+
plane="xy",
58+
bounding_box=self.h5m_filename_smaller,
59+
mesh_resolution=(10, 200)
60+
)
61+
tally2 = odw.MeshTally2D(
62+
tally_type="neutron_flux",
63+
plane="xz",
64+
bounding_box=self.h5m_filename_smaller,
65+
mesh_resolution=(20, 100)
66+
)
67+
tally3 = odw.MeshTally2D(
68+
tally_type="neutron_flux",
69+
plane="yz",
70+
bounding_box=self.h5m_filename_smaller,
71+
mesh_resolution=(30, 500)
72+
)
73+
74+
tallies = openmc.Tallies([tally1, tally2, tally3])
75+
76+
settings = odw.FusionSettings()
77+
settings.batches = 2
78+
settings.particles = 100
79+
settings.photon_transport = False
80+
settings.source = FusionRingSource(fuel="DT", radius=1)
81+
82+
my_model = openmc.Model(
83+
materials=materials,
84+
geometry=geometry,
85+
settings=settings,
86+
tallies=tallies)
87+
statepoint_file = my_model.run()
88+
89+
odw.process_results(statepoint_file, fusion_power=1e9)
90+
91+
assert Path('neutron_flux_on_2D_mesh_xy.png').exists()
92+
assert Path('neutron_flux_on_2D_mesh_xz.png').exists()
93+
assert Path('neutron_flux_on_2D_mesh_yz.png').exists()
Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
import tarfile
23
import unittest
34
import urllib.request
@@ -7,8 +8,8 @@
78
import openmc_dagmc_wrapper as odw
89

910

10-
class TestMeshTallies(unittest.TestCase):
11-
"""Tests the MeshTallies class functionality"""
11+
class TestMeshTally3D(unittest.TestCase):
12+
"""Tests the MeshTally3D class functionality"""
1213

1314
def setUp(self):
1415

@@ -23,22 +24,6 @@ def setUp(self):
2324
self.h5m_filename_smaller = "tests/neutronics_workflow-0.0.2/example_01_single_volume_cell_tally/stage_2_output/dagmc.h5m"
2425
self.h5m_filename_bigger = "tests/neutronics_workflow-0.0.2/example_02_multi_volume_cell_tally/stage_2_output/dagmc.h5m"
2526

26-
def test_incorrect_mesh_tally_2d(self):
27-
"""Set a mesh_tally_2d that is not accepted which should raise an
28-
error"""
29-
def incorrect_mesh_tally_2d():
30-
odw.MeshTally2D("coucou", plane="xy")
31-
32-
self.assertRaises(ValueError, incorrect_mesh_tally_2d)
33-
34-
def test_incorrect_mesh_tally_2d_type(self):
35-
"""Set a mesh_tally_2d that is the wrong type which should raise an
36-
error"""
37-
def incorrect_mesh_tally_2d_type():
38-
odw.MeshTally2D(1, plane="xy")
39-
40-
self.assertRaises(TypeError, incorrect_mesh_tally_2d_type)
41-
4227
def test_incorrect_mesh_tally_3d(self):
4328
"""Set a mesh_tally_3d that is not accepted which should raise an
4429
error"""

0 commit comments

Comments
 (0)