Skip to content

Commit 4e3bc96

Browse files
authored
Merge pull request #47 from fusion-energy/develop
adding tally finding utlis
2 parents 892e088 + 2f04be0 commit 4e3bc96

File tree

4 files changed

+113
-0
lines changed

4 files changed

+113
-0
lines changed

src/regular_mesh_plotter/core.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,41 @@
33
import openmc
44

55

6+
def get_tallies_with_regular_mesh_filters(statepoint: openmc.StatePoint):
7+
"""scans the statepoint object to find all tallies and with regular mesh
8+
filters, returns a list of tally indexes"""
9+
10+
matching_tally_ids = []
11+
for tally_id, tally in statepoint.tallies.items():
12+
print("tally id", tally_id)
13+
try:
14+
mf = tally.find_filter(filter_type=openmc.MeshFilter)
15+
if isinstance(mf.mesh, openmc.RegularMesh):
16+
matching_tally_ids.append(tally.id)
17+
print("found regmeshfilter")
18+
except ValueError:
19+
mf = None
20+
21+
return sorted(matching_tally_ids)
22+
23+
24+
def get_regularmesh_tallies_and_scores(statepoint: openmc.StatePoint):
25+
"""scans the statepoint object to find all tallies and scores,
26+
returns list of dictionaries. Each dictionary contains tally id,
27+
score and tally name"""
28+
29+
tallies_of_interest = get_tallies_with_regular_mesh_filters(statepoint)
30+
31+
tally_score_info = []
32+
for tally_id in tallies_of_interest:
33+
tally = statepoint.tallies[tally_id]
34+
for score in tally.scores:
35+
entry = {"id": tally.id, "score": score, "name": tally.name}
36+
tally_score_info.append(entry)
37+
38+
return tally_score_info
39+
40+
641
def get_mpl_plot_extent(self, view_direction: str = "x"):
742
"""Returns the (x_min, x_max, y_min, y_max) of the bounding box. The
843
view_direction is taken into account and can be set using
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import openmc
2+
3+
4+
mat1 = openmc.Material()
5+
mat1.add_nuclide("He4", 1)
6+
mat1.set_density("g/cm3", 1)
7+
my_materials = openmc.Materials([mat1])
8+
surf1 = openmc.Sphere(r=10, boundary_type="vacuum")
9+
region1 = -surf1
10+
cell1 = openmc.Cell(region=region1)
11+
my_geometry = openmc.Geometry([cell1])
12+
my_settings = openmc.Settings()
13+
my_settings.batches = 3
14+
my_settings.particles = 500
15+
my_settings.run_mode = "fixed source"
16+
my_source = openmc.Source()
17+
my_source.space = openmc.stats.Point((0, 0, 0))
18+
my_source.angle = openmc.stats.Isotropic()
19+
my_source.energy = openmc.stats.Discrete([14e6], [1])
20+
my_settings.source = my_source
21+
cymesh = openmc.CylindricalMesh().from_domain(my_geometry)
22+
regmesh = openmc.RegularMesh().from_domain(my_geometry)
23+
regmesh_filter = openmc.MeshFilter(regmesh)
24+
cmesh_filter = openmc.MeshFilter(cymesh)
25+
cell_filter = openmc.CellFilter(cell1)
26+
27+
cell_tally_1 = openmc.Tally(name="tallies_on_cell_flux_and_heating")
28+
cell_tally_1.id = 1
29+
cell_tally_1.filters = [cell_filter]
30+
cell_tally_1.scores = ["flux", "heating"]
31+
32+
mesh_tally_1 = openmc.Tally(name="tallies_on_regmesh_flux_and_heating")
33+
mesh_tally_1.id = 4
34+
mesh_tally_1.filters = [regmesh_filter]
35+
mesh_tally_1.scores = ["flux", "heating"]
36+
37+
mesh_tally_2 = openmc.Tally(name="tallies_on_regmesh_absorption")
38+
mesh_tally_2.id = 3
39+
mesh_tally_2.filters = [regmesh_filter]
40+
mesh_tally_2.scores = ["absorption"]
41+
42+
mesh_tally_3 = openmc.Tally(name="tallies_on_cymesh_absorption")
43+
mesh_tally_3.id = 5
44+
mesh_tally_3.filters = [cmesh_filter]
45+
mesh_tally_3.scores = ["absorption"]
46+
47+
my_tallies = openmc.Tallies([cell_tally_1, mesh_tally_1, mesh_tally_2, mesh_tally_3])
48+
model = openmc.model.Model(my_geometry, my_materials, my_settings, my_tallies)
49+
output_filename = model.run()

tests/test_tally_finding.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import openmc
2+
from regular_mesh_plotter import (
3+
get_tallies_with_regular_mesh_filters,
4+
get_regularmesh_tallies_and_scores,
5+
)
6+
7+
8+
def test_tally_with_reg_mesh_finding():
9+
# checks the correct number of tally score combinations are found
10+
11+
statepoint = openmc.StatePoint("statepoint.3.h5")
12+
13+
# one tally has a cell filter and another one has a cylinder mesh filter
14+
assert len(statepoint.tallies) == 4
15+
16+
t_and_scores = get_tallies_with_regular_mesh_filters(statepoint)
17+
assert t_and_scores == [3, 4]
18+
19+
20+
def test_get_regularmesh_tallies_and_scores():
21+
statepoint = openmc.StatePoint("statepoint.3.h5")
22+
23+
t_and_c = get_regularmesh_tallies_and_scores(statepoint)
24+
25+
assert t_and_c == [
26+
{"id": 3, "name": "tallies_on_regmesh_absorption", "score": "absorption"},
27+
{"id": 4, "name": "tallies_on_regmesh_flux_and_heating", "score": "flux"},
28+
{"id": 4, "name": "tallies_on_regmesh_flux_and_heating", "score": "heating"},
29+
]

0 commit comments

Comments
 (0)