Skip to content

Commit 017b5a6

Browse files
authored
Merge pull request #57 from SteSeg/build_model
Added `_build_model()` and `self.model` in `OpenmcBenchmark` class
2 parents b4bc3b8 + 3b56200 commit 017b5a6

File tree

2 files changed

+37
-16
lines changed

2 files changed

+37
-16
lines changed

src/openmc_fusion_benchmarks/benchmark.py

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,35 @@ def __init__(self, name: str):
2525
self._read_metadata()
2626

2727
@abstractmethod
28-
def build_materials(self):
28+
def _build_materials(self):
2929
"""Build materials for the benchmark."""
3030
pass
3131

3232
@abstractmethod
33-
def build_geometry(self):
33+
def _build_geometry(self):
3434
"""Build geometry for the benchmark."""
3535
pass
3636

3737
@abstractmethod
38-
def build_source(self):
38+
def _build_source(self):
3939
"""Build source for the benchmark."""
4040
pass
4141

4242
@abstractmethod
43-
def build_settings(self):
43+
def _build_settings(self):
4444
"""Build settings for the benchmark."""
4545
pass
4646

4747
@abstractmethod
48-
def build_tallies(self):
48+
def _build_tallies(self):
4949
"""Build tallies for the benchmark."""
5050
pass
5151

52+
@abstractmethod
53+
def _build_model(self):
54+
"""Build the whole model for the benchmark."""
55+
pass
56+
5257
def _read_metadata(self):
5358
"""Read metadata from the benchmark specification."""
5459
metadata = self._benchmark_spec['metadata']
@@ -108,7 +113,9 @@ def __init__(self, name: str):
108113
self._settings = None
109114
self._tallies = None
110115

111-
def build_materials(self):
116+
self.model = self._build_model()
117+
118+
def _build_materials(self):
112119
# Implement the logic to build materials for OpenMC
113120
material_data = self._benchmark_spec['materials']
114121

@@ -135,7 +142,7 @@ def build_materials(self):
135142

136143
return materials
137144

138-
def build_geometry(self):
145+
def _build_geometry(self):
139146

140147
def build_mesh(cad_file: str, material_tags, set_size: dict, global_mesh_size_min: float, global_mesh_size_max: float, mesh_file: str = "mesh.h5m"):
141148

@@ -181,7 +188,7 @@ def build_mesh(cad_file: str, material_tags, set_size: dict, global_mesh_size_mi
181188

182189
return openmc.Geometry(root=dag_universe)
183190

184-
def build_source(self):
191+
def _build_source(self):
185192
source_data = self._benchmark_spec['sources']
186193

187194
def energy_conversion(values, units):
@@ -296,7 +303,7 @@ def angular_conversion(values, units):
296303

297304
return source
298305

299-
def build_tallies(self):
306+
def _build_tallies(self):
300307
tallies_data = self._benchmark_spec['tallies']
301308

302309
# Initialize openmc tallies
@@ -333,7 +340,7 @@ def build_tallies(self):
333340

334341
return tallies
335342

336-
def build_settings(self):
343+
def _build_settings(self):
337344
settings_data = self._benchmark_spec['settings']
338345

339346
settings = openmc.Settings()
@@ -353,3 +360,16 @@ def build_settings(self):
353360
settings.source = source
354361

355362
return settings
363+
364+
def _build_model(self):
365+
materials = self._build_materials()
366+
geometry = self._build_geometry()
367+
settings = self._build_settings()
368+
tallies = self._build_tallies()
369+
model = openmc.Model(
370+
materials=materials,
371+
geometry=geometry,
372+
settings=settings,
373+
tallies=tallies
374+
)
375+
return model

test/test_benchmark.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88

99
# Minimal subclass for testing abstract class
1010
class DummyBenchmark(Benchmark):
11-
def build_materials(self): return "materials"
12-
def build_geometry(self): return "geometry"
13-
def build_source(self): return "source"
14-
def build_settings(self): return "settings"
15-
def build_tallies(self): return "tallies"
11+
def _build_materials(self): return "materials"
12+
def _build_geometry(self): return "geometry"
13+
def _build_source(self): return "source"
14+
def _build_settings(self): return "settings"
15+
def _build_tallies(self): return "tallies"
16+
def _build_model(self): return "model"
1617

1718

1819
@pytest.fixture
@@ -34,7 +35,7 @@ def test_benchmark_success(mock_validate, valid_yaml):
3435

3536
assert bench.name == "dummy"
3637
assert bench._benchmark_spec["metadata"]["title"] == "Dummy"
37-
assert bench.build_materials() == "materials"
38+
assert bench._build_materials() == "materials"
3839

3940

4041
@patch("openmc_fusion_benchmarks.benchmark.validate_benchmark")

0 commit comments

Comments
 (0)