From ea4b8c15797df12d81ea86125103d3cbe071c1f9 Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Thu, 9 Jan 2025 12:52:04 +0100 Subject: [PATCH 01/30] adding vacuum test --- tests/unit_tests/dagmc/test_model.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/unit_tests/dagmc/test_model.py b/tests/unit_tests/dagmc/test_model.py index 9fdfbcebc68..981237656d0 100644 --- a/tests/unit_tests/dagmc/test_model.py +++ b/tests/unit_tests/dagmc/test_model.py @@ -254,3 +254,28 @@ def test_dagmc_xml(model): for xml_mats, model_mats in zip(xml_dagmc_univ._material_overrides.values(), dag_univ._material_overrides.values()): assert all([xml_mat.id == orig_mat.id for xml_mat, orig_mat in zip(xml_mats, model_mats)]) + + +def test_dagmc_vacuum(model): + # Set the environment + mats = {} + mats["Vacuum"] = openmc.Material(1, name="Vacuum") + mats["Vacuum"].add_nuclide("U235", 0.03) + mats["Vacuum"].add_nuclide("U238", 0.97) + mats["Vacuum"].add_nuclide("O16", 2.0) + mats["Vacuum"].set_density("g/cm3", 10.0) + + for univ in model.geometry.get_all_universes().values(): + if isinstance(univ, openmc.DAGMCUniverse): + dag_univ = univ + break + + for mat in dag_univ.material_names: + dag_univ.replace_material_assignment(mat, mats["Vacuum"]) + + model.export_to_xml() + # ensure that particles will be lost when cell intersections can't be found + # due to the removed triangles in this model + with pytest.raises(RuntimeError, match='Maximum number of lost particles has been reached.'): + openmc.run() + \ No newline at end of file From 4c4206880d837a9ca3bf25021458e88bddde7e7a Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Thu, 9 Jan 2025 15:48:01 +0100 Subject: [PATCH 02/30] testing vacuum keyword detection with DAGMC geometry --- tests/unit_tests/dagmc/test_model.py | 38 +++++++++++++++++++++------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/tests/unit_tests/dagmc/test_model.py b/tests/unit_tests/dagmc/test_model.py index 981237656d0..fee655cbc42 100644 --- a/tests/unit_tests/dagmc/test_model.py +++ b/tests/unit_tests/dagmc/test_model.py @@ -257,25 +257,45 @@ def test_dagmc_xml(model): def test_dagmc_vacuum(model): - # Set the environment - mats = {} - mats["Vacuum"] = openmc.Material(1, name="Vacuum") - mats["Vacuum"].add_nuclide("U235", 0.03) - mats["Vacuum"].add_nuclide("U238", 0.97) - mats["Vacuum"].add_nuclide("O16", 2.0) - mats["Vacuum"].set_density("g/cm3", 10.0) + + # Verify Not_A_Vacuum is not detected as a Vacuum + mat_not_a_vacuum = openmc.Material(1, name="Not_A_Vacuum") + mat_not_a_vacuum.add_nuclide("U235", 0.03) + mat_not_a_vacuum.add_nuclide("U238", 0.97) + mat_not_a_vacuum.add_nuclide("O16", 2.0) + mat_not_a_vacuum.set_density("g/cm3", 10.0) + + for univ in model.geometry.get_all_universes().values(): + if isinstance(univ, openmc.DAGMCUniverse): + dag_univ = univ + break + + # Replacing all the materials with vacuum + for mat in dag_univ.material_names: + dag_univ.replace_material_assignment(mat, mat_not_a_vacuum) + + model.export_to_xml() + # Ensure this run as expected. + openmc.run() + + # Verify that the vacuum is detected as a Vacuum + mat_a_vacuum = openmc.Material(1, name="Vacuum") + mat_a_vacuum.add_nuclide("U235", 0.03) + mat_a_vacuum.add_nuclide("U238", 0.97) + mat_a_vacuum.add_nuclide("O16", 2.0) + mat_a_vacuum.set_density("g/cm3", 10.0) for univ in model.geometry.get_all_universes().values(): if isinstance(univ, openmc.DAGMCUniverse): dag_univ = univ break + # Replacing all the materials with vacuum for mat in dag_univ.material_names: - dag_univ.replace_material_assignment(mat, mats["Vacuum"]) + dag_univ.replace_material_assignment(mat, at_a_vacuum) model.export_to_xml() # ensure that particles will be lost when cell intersections can't be found # due to the removed triangles in this model with pytest.raises(RuntimeError, match='Maximum number of lost particles has been reached.'): openmc.run() - \ No newline at end of file From 6f303738b3927d9551b198931922223a6c0c1689 Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Thu, 9 Jan 2025 17:45:17 +0100 Subject: [PATCH 03/30] does it run by default ? --- tests/unit_tests/dagmc/test_model.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/unit_tests/dagmc/test_model.py b/tests/unit_tests/dagmc/test_model.py index fee655cbc42..28a6eedc6fa 100644 --- a/tests/unit_tests/dagmc/test_model.py +++ b/tests/unit_tests/dagmc/test_model.py @@ -258,6 +258,8 @@ def test_dagmc_xml(model): def test_dagmc_vacuum(model): + openmc.run() + # Verify Not_A_Vacuum is not detected as a Vacuum mat_not_a_vacuum = openmc.Material(1, name="Not_A_Vacuum") mat_not_a_vacuum.add_nuclide("U235", 0.03) From ef6f0837d87060ec2c6d9fd3fc9fd05ae6266dda Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Fri, 10 Jan 2025 16:01:12 +0100 Subject: [PATCH 04/30] set my box boundary as vacuum --- tests/unit_tests/dagmc/test_model.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit_tests/dagmc/test_model.py b/tests/unit_tests/dagmc/test_model.py index 28a6eedc6fa..0477a1bdb5c 100644 --- a/tests/unit_tests/dagmc/test_model.py +++ b/tests/unit_tests/dagmc/test_model.py @@ -41,6 +41,7 @@ def model(request): [daguniv, daguniv]] box = openmc.model.RectangularParallelepiped(-pitch, pitch, -pitch, pitch, -5, 5) + box.boundary_type = "vacuum" root = openmc.Universe(cells=[openmc.Cell(region=-box, fill=lattice)]) From ce1646a7015394995f2fbd9dbe1d924fd41e2a42 Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Sun, 12 Jan 2025 11:18:14 +0100 Subject: [PATCH 05/30] typo --- tests/unit_tests/dagmc/test_model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit_tests/dagmc/test_model.py b/tests/unit_tests/dagmc/test_model.py index 0477a1bdb5c..b7dfa321c5a 100644 --- a/tests/unit_tests/dagmc/test_model.py +++ b/tests/unit_tests/dagmc/test_model.py @@ -295,7 +295,7 @@ def test_dagmc_vacuum(model): # Replacing all the materials with vacuum for mat in dag_univ.material_names: - dag_univ.replace_material_assignment(mat, at_a_vacuum) + dag_univ.replace_material_assignment(mat, mat_a_vacuum) model.export_to_xml() # ensure that particles will be lost when cell intersections can't be found From af7726fcdba61d572728a52dd0664d5aea08bf46 Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Mon, 13 Jan 2025 12:50:43 +0100 Subject: [PATCH 06/30] test tally --- tests/unit_tests/dagmc/test_model.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/unit_tests/dagmc/test_model.py b/tests/unit_tests/dagmc/test_model.py index b7dfa321c5a..14464e0b7fd 100644 --- a/tests/unit_tests/dagmc/test_model.py +++ b/tests/unit_tests/dagmc/test_model.py @@ -5,7 +5,7 @@ import pytest import openmc from openmc.utility_funcs import change_directory - +import openmc.lib pytestmark = pytest.mark.skipif( not openmc.lib._dagmc_enabled(), reason="DAGMC CAD geometry is not enabled.") @@ -259,8 +259,6 @@ def test_dagmc_xml(model): def test_dagmc_vacuum(model): - openmc.run() - # Verify Not_A_Vacuum is not detected as a Vacuum mat_not_a_vacuum = openmc.Material(1, name="Not_A_Vacuum") mat_not_a_vacuum.add_nuclide("U235", 0.03) @@ -277,6 +275,12 @@ def test_dagmc_vacuum(model): for mat in dag_univ.material_names: dag_univ.replace_material_assignment(mat, mat_not_a_vacuum) + current = openmc.Tally() + current.scores = ['current'] + model._tallies.append(current) + src = openmc.IndependentSource(space=openmc.stats.Point()) + model.settings.source = src + model.export_to_xml() # Ensure this run as expected. openmc.run() From 4a9b560cdfa1ee142a8f6fe98530443748c88c25 Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Mon, 13 Jan 2025 16:26:09 +0100 Subject: [PATCH 07/30] new suf tally --- tests/unit_tests/dagmc/test_model.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/unit_tests/dagmc/test_model.py b/tests/unit_tests/dagmc/test_model.py index 14464e0b7fd..eaaf9cf6055 100644 --- a/tests/unit_tests/dagmc/test_model.py +++ b/tests/unit_tests/dagmc/test_model.py @@ -275,9 +275,13 @@ def test_dagmc_vacuum(model): for mat in dag_univ.material_names: dag_univ.replace_material_assignment(mat, mat_not_a_vacuum) + + pitch = 1.26 + box = openmc.SurfaceFilter(openmc.Sphere(r=pitch)) current = openmc.Tally() current.scores = ['current'] - model._tallies.append(current) + current.filters = [box] + model.tallies.append(current) src = openmc.IndependentSource(space=openmc.stats.Point()) model.settings.source = src From 35830117f55b7047f8aa75ffee7b48cdf00d54cb Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Mon, 13 Jan 2025 18:45:31 +0100 Subject: [PATCH 08/30] printing tally content --- tests/unit_tests/dagmc/test_model.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/unit_tests/dagmc/test_model.py b/tests/unit_tests/dagmc/test_model.py index eaaf9cf6055..9cec4e1e256 100644 --- a/tests/unit_tests/dagmc/test_model.py +++ b/tests/unit_tests/dagmc/test_model.py @@ -288,7 +288,14 @@ def test_dagmc_vacuum(model): model.export_to_xml() # Ensure this run as expected. openmc.run() - + # Read the statepoint file. + sp = openmc.StatePoint("statepoint.100.h5") + + # Extract the tally data as a Pandas DataFrame. + tally_dfs = [t.get_pandas_dataframe() for t in sp.tallies.values()] + df = pd.concat(tally_dfs, ignore_index=True) + print(df) + # Verify that the vacuum is detected as a Vacuum mat_a_vacuum = openmc.Material(1, name="Vacuum") mat_a_vacuum.add_nuclide("U235", 0.03) From 8f6d1bdb4aa2dae9cfe360dcd3fad3794114a2fe Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Tue, 14 Jan 2025 17:13:14 +0100 Subject: [PATCH 09/30] add vacuum test --- tests/unit_tests/dagmc/test_model.py | 127 +++++++++++++++++++-------- 1 file changed, 89 insertions(+), 38 deletions(-) diff --git a/tests/unit_tests/dagmc/test_model.py b/tests/unit_tests/dagmc/test_model.py index 9cec4e1e256..4fa5b7cc7cf 100644 --- a/tests/unit_tests/dagmc/test_model.py +++ b/tests/unit_tests/dagmc/test_model.py @@ -1,5 +1,6 @@ from pathlib import Path +import pandas as pd import lxml.etree as ET import numpy as np import pytest @@ -256,64 +257,114 @@ def test_dagmc_xml(model): for xml_mats, model_mats in zip(xml_dagmc_univ._material_overrides.values(), dag_univ._material_overrides.values()): assert all([xml_mat.id == orig_mat.id for xml_mat, orig_mat in zip(xml_mats, model_mats)]) +def test_dagmc_vacuum(request, run_in_tmpdir): + + import shutil + shutil.copyfile(Path(request.fspath).parent / "dagmc.h5m", Path(request.fspath).parent / "dagmc_not_a_vacuum.h5m") -def test_dagmc_vacuum(model): - - # Verify Not_A_Vacuum is not detected as a Vacuum - mat_not_a_vacuum = openmc.Material(1, name="Not_A_Vacuum") - mat_not_a_vacuum.add_nuclide("U235", 0.03) - mat_not_a_vacuum.add_nuclide("U238", 0.97) - mat_not_a_vacuum.add_nuclide("O16", 2.0) - mat_not_a_vacuum.set_density("g/cm3", 10.0) + mats = {} + mats["not_a_vacuum"] = openmc.Material(1, name="not_a_vacuum") + mats["not_a_vacuum"].add_nuclide("U235", 0.03) + mats["not_a_vacuum"].add_nuclide("U238", 0.97) + mats["not_a_vacuum"].add_nuclide("O16", 2.0) + mats["not_a_vacuum"].set_density("g/cm3", 10.0) + + mats["vacuum"] = openmc.Material(name="vacuum") + mats["vacuum"].add_nuclide("U235", 0.03) + mats["vacuum"].add_nuclide("U238", 0.97) + mats["vacuum"].add_nuclide("O16", 2.0) + mats["vacuum"].set_density("g/cm3", 10.0) + mats["41"] = openmc.Material(name="41") + mats["41"].add_nuclide("U235", 0.03) + mats["41"].add_nuclide("U238", 0.97) + mats["41"].add_nuclide("O16", 2.0) + mats["41"].set_density("g/cm3", 10.0) + + import h5py + hf = h5py.File(Path(request.fspath).parent / "dagmc_not_a_vacuum.h5m", 'r+') + new_assignment = 'mat:not_a_vacuum'.encode('utf-8') + hf['/tstt/tags/NAME']['values'][1] = new_assignment + hf.close() + + p = Path(request.fspath).parent / "dagmc_not_a_vacuum.h5m" + daguniv = openmc.DAGMCUniverse(p, auto_geom_ids=True).bounded_universe() + settings = openmc.Settings() + settings.batches = 100 + settings.inactive = 10 + settings.particles = 1000 + model = openmc.Model() + model.materials = openmc.Materials(mats.values()) + model.geometry = openmc.Geometry(root=daguniv) + model.settings = settings + model.init_lib() + model.sync_dagmc_universes() for univ in model.geometry.get_all_universes().values(): if isinstance(univ, openmc.DAGMCUniverse): dag_univ = univ break - # Replacing all the materials with vacuum - for mat in dag_univ.material_names: - dag_univ.replace_material_assignment(mat, mat_not_a_vacuum) - + my_tally = openmc.Tally() + cell_filter = openmc.CellFilter([x.id for x in dag_univ.get_all_cells().values()]) - pitch = 1.26 - box = openmc.SurfaceFilter(openmc.Sphere(r=pitch)) - current = openmc.Tally() - current.scores = ['current'] - current.filters = [box] - model.tallies.append(current) + my_tally.scores = ['nu-fission'] + my_tally.filters = [cell_filter] + model.tallies.append(my_tally) src = openmc.IndependentSource(space=openmc.stats.Point()) model.settings.source = src - model.export_to_xml() - # Ensure this run as expected. - openmc.run() + model.export_to_model_xml('sub_dir_not_a_vacuum/model.xml',) + openmc.run(cwd='sub_dir_not_a_vacuum') # Read the statepoint file. - sp = openmc.StatePoint("statepoint.100.h5") + sp = openmc.StatePoint("sub_dir_not_a_vacuum/statepoint.100.h5") # Extract the tally data as a Pandas DataFrame. tally_dfs = [t.get_pandas_dataframe() for t in sp.tallies.values()] df = pd.concat(tally_dfs, ignore_index=True) - print(df) - - # Verify that the vacuum is detected as a Vacuum - mat_a_vacuum = openmc.Material(1, name="Vacuum") - mat_a_vacuum.add_nuclide("U235", 0.03) - mat_a_vacuum.add_nuclide("U238", 0.97) - mat_a_vacuum.add_nuclide("O16", 2.0) - mat_a_vacuum.set_density("g/cm3", 10.0) + # not detected as vacuum so tally should be non-zero + assert df['mean'].loc[0] > 0 + + shutil.copyfile(Path(request.fspath).parent / "dagmc.h5m", Path(request.fspath).parent / "dagmc_a_vacuum.h5m") + hf = h5py.File(Path(request.fspath).parent / "dagmc_a_vacuum.h5m", 'r+') + new_assignment = 'mat:vacuum'.encode('utf-8') + hf['/tstt/tags/NAME']['values'][1] = new_assignment + hf.close() + + p = Path(request.fspath).parent / "dagmc_a_vacuum.h5m" + daguniv = openmc.DAGMCUniverse(p, auto_geom_ids=True).bounded_universe() + settings = openmc.Settings() + settings.batches = 100 + settings.inactive = 10 + settings.particles = 1000 + model = openmc.Model() + model.materials = openmc.Materials(mats.values()) + model.geometry = openmc.Geometry(root=daguniv) + model.settings = settings + model.init_lib() + model.sync_dagmc_universes() for univ in model.geometry.get_all_universes().values(): if isinstance(univ, openmc.DAGMCUniverse): dag_univ = univ break - # Replacing all the materials with vacuum - for mat in dag_univ.material_names: - dag_univ.replace_material_assignment(mat, mat_a_vacuum) + my_tally = openmc.Tally() + cell_filter = openmc.CellFilter([x.id for x in dag_univ.get_all_cells().values()]) + + my_tally.scores = ['nu-fission'] + my_tally.filters = [cell_filter] + model.tallies.append(my_tally) + src = openmc.IndependentSource(space=openmc.stats.Point()) + model.settings.source = src + + model.export_to_model_xml('sub_dir_vacuum/model.xml',) + openmc.run(cwd='sub_dir_vacuum') + # Read the statepoint file. + sp = openmc.StatePoint("sub_dir_vacuum/statepoint.100.h5") - model.export_to_xml() - # ensure that particles will be lost when cell intersections can't be found - # due to the removed triangles in this model - with pytest.raises(RuntimeError, match='Maximum number of lost particles has been reached.'): - openmc.run() + # Extract the tally data as a Pandas DataFrame. + tally_dfs = [t.get_pandas_dataframe() for t in sp.tallies.values()] + df = pd.concat(tally_dfs, ignore_index=True) + # detected as vacuum so tally should be zero + assert df['mean'].loc[0] == 0 + From f2aded519e49f4a59d04a64454b61338ca51d150 Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Tue, 14 Jan 2025 17:23:09 +0100 Subject: [PATCH 10/30] now all run in tmp --- tests/unit_tests/dagmc/test_model.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/tests/unit_tests/dagmc/test_model.py b/tests/unit_tests/dagmc/test_model.py index 4fa5b7cc7cf..36acbc4f4c8 100644 --- a/tests/unit_tests/dagmc/test_model.py +++ b/tests/unit_tests/dagmc/test_model.py @@ -257,10 +257,10 @@ def test_dagmc_xml(model): for xml_mats, model_mats in zip(xml_dagmc_univ._material_overrides.values(), dag_univ._material_overrides.values()): assert all([xml_mat.id == orig_mat.id for xml_mat, orig_mat in zip(xml_mats, model_mats)]) -def test_dagmc_vacuum(request, run_in_tmpdir): +def test_dagmc_vacuum(request, run_in_tmpdir, tmpdir): import shutil - shutil.copyfile(Path(request.fspath).parent / "dagmc.h5m", Path(request.fspath).parent / "dagmc_not_a_vacuum.h5m") + shutil.copyfile(Path(request.fspath).parent / "dagmc.h5m", tmpdir/"dagmc_not_a_vacuum.h5m") mats = {} mats["not_a_vacuum"] = openmc.Material(1, name="not_a_vacuum") @@ -282,12 +282,12 @@ def test_dagmc_vacuum(request, run_in_tmpdir): mats["41"].set_density("g/cm3", 10.0) import h5py - hf = h5py.File(Path(request.fspath).parent / "dagmc_not_a_vacuum.h5m", 'r+') + hf = h5py.File(tmpdir/ "dagmc_not_a_vacuum.h5m", 'r+') new_assignment = 'mat:not_a_vacuum'.encode('utf-8') hf['/tstt/tags/NAME']['values'][1] = new_assignment hf.close() - p = Path(request.fspath).parent / "dagmc_not_a_vacuum.h5m" + p = tmpdir/"dagmc_not_a_vacuum.h5m" daguniv = openmc.DAGMCUniverse(p, auto_geom_ids=True).bounded_universe() settings = openmc.Settings() settings.batches = 100 @@ -324,14 +324,13 @@ def test_dagmc_vacuum(request, run_in_tmpdir): # not detected as vacuum so tally should be non-zero assert df['mean'].loc[0] > 0 - shutil.copyfile(Path(request.fspath).parent / "dagmc.h5m", Path(request.fspath).parent / "dagmc_a_vacuum.h5m") - hf = h5py.File(Path(request.fspath).parent / "dagmc_a_vacuum.h5m", 'r+') + shutil.copyfile(Path(request.fspath).parent / "dagmc.h5m", tmpdir/"dagmc_a_vacuum.h5m") + hf = h5py.File(tmpdir/ "dagmc_a_vacuum.h5m", 'r+') new_assignment = 'mat:vacuum'.encode('utf-8') hf['/tstt/tags/NAME']['values'][1] = new_assignment hf.close() - p = Path(request.fspath).parent / "dagmc_a_vacuum.h5m" - + p = tmpdir/"dagmc_a_vacuum.h5m" daguniv = openmc.DAGMCUniverse(p, auto_geom_ids=True).bounded_universe() settings = openmc.Settings() settings.batches = 100 From 16169d34f8ee4cb7f0f76e27a9d4473295ab9564 Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot <15145274+bam241@users.noreply.github.com> Date: Tue, 14 Jan 2025 17:38:56 +0100 Subject: [PATCH 11/30] Apply suggestions from code review Co-authored-by: Jonathan Shimwell --- tests/unit_tests/dagmc/test_model.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/unit_tests/dagmc/test_model.py b/tests/unit_tests/dagmc/test_model.py index 36acbc4f4c8..21dff3d24ff 100644 --- a/tests/unit_tests/dagmc/test_model.py +++ b/tests/unit_tests/dagmc/test_model.py @@ -1,5 +1,7 @@ from pathlib import Path +import h5py +import shutil import pandas as pd import lxml.etree as ET import numpy as np @@ -259,7 +261,6 @@ def test_dagmc_xml(model): def test_dagmc_vacuum(request, run_in_tmpdir, tmpdir): - import shutil shutil.copyfile(Path(request.fspath).parent / "dagmc.h5m", tmpdir/"dagmc_not_a_vacuum.h5m") mats = {} @@ -281,7 +282,6 @@ def test_dagmc_vacuum(request, run_in_tmpdir, tmpdir): mats["41"].add_nuclide("O16", 2.0) mats["41"].set_density("g/cm3", 10.0) - import h5py hf = h5py.File(tmpdir/ "dagmc_not_a_vacuum.h5m", 'r+') new_assignment = 'mat:not_a_vacuum'.encode('utf-8') hf['/tstt/tags/NAME']['values'][1] = new_assignment @@ -291,7 +291,6 @@ def test_dagmc_vacuum(request, run_in_tmpdir, tmpdir): daguniv = openmc.DAGMCUniverse(p, auto_geom_ids=True).bounded_universe() settings = openmc.Settings() settings.batches = 100 - settings.inactive = 10 settings.particles = 1000 model = openmc.Model() model.materials = openmc.Materials(mats.values()) From 30ca476a838dbb04ce00a66e303dd62338d998ea Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Tue, 14 Jan 2025 17:39:40 +0100 Subject: [PATCH 12/30] revert 2 change --- tests/unit_tests/dagmc/test_model.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/unit_tests/dagmc/test_model.py b/tests/unit_tests/dagmc/test_model.py index 21dff3d24ff..01386b4ad6a 100644 --- a/tests/unit_tests/dagmc/test_model.py +++ b/tests/unit_tests/dagmc/test_model.py @@ -8,7 +8,6 @@ import pytest import openmc from openmc.utility_funcs import change_directory -import openmc.lib pytestmark = pytest.mark.skipif( not openmc.lib._dagmc_enabled(), reason="DAGMC CAD geometry is not enabled.") @@ -44,7 +43,6 @@ def model(request): [daguniv, daguniv]] box = openmc.model.RectangularParallelepiped(-pitch, pitch, -pitch, pitch, -5, 5) - box.boundary_type = "vacuum" root = openmc.Universe(cells=[openmc.Cell(region=-box, fill=lattice)]) From 5fb1640f56948945919ac9cc92d71e5272d06349 Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot <15145274+bam241@users.noreply.github.com> Date: Tue, 14 Jan 2025 18:07:39 +0100 Subject: [PATCH 13/30] Update tests/unit_tests/dagmc/test_model.py Co-authored-by: Jonathan Shimwell --- tests/unit_tests/dagmc/test_model.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit_tests/dagmc/test_model.py b/tests/unit_tests/dagmc/test_model.py index 01386b4ad6a..63c159561be 100644 --- a/tests/unit_tests/dagmc/test_model.py +++ b/tests/unit_tests/dagmc/test_model.py @@ -354,9 +354,9 @@ def test_dagmc_vacuum(request, run_in_tmpdir, tmpdir): model.settings.source = src model.export_to_model_xml('sub_dir_vacuum/model.xml',) - openmc.run(cwd='sub_dir_vacuum') + sp_filename = openmc.run(cwd='sub_dir_vacuum') # Read the statepoint file. - sp = openmc.StatePoint("sub_dir_vacuum/statepoint.100.h5") + sp = openmc.StatePoint(sp_filename) # Extract the tally data as a Pandas DataFrame. tally_dfs = [t.get_pandas_dataframe() for t in sp.tallies.values()] From a483ab18d2c13ef6cceb34e2d44d72441a1d1189 Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot <15145274+bam241@users.noreply.github.com> Date: Wed, 15 Jan 2025 08:50:39 +0100 Subject: [PATCH 14/30] Update tests/unit_tests/dagmc/test_model.py Co-authored-by: Jonathan Shimwell --- tests/unit_tests/dagmc/test_model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit_tests/dagmc/test_model.py b/tests/unit_tests/dagmc/test_model.py index 63c159561be..d2f4511ce4a 100644 --- a/tests/unit_tests/dagmc/test_model.py +++ b/tests/unit_tests/dagmc/test_model.py @@ -330,7 +330,7 @@ def test_dagmc_vacuum(request, run_in_tmpdir, tmpdir): p = tmpdir/"dagmc_a_vacuum.h5m" daguniv = openmc.DAGMCUniverse(p, auto_geom_ids=True).bounded_universe() settings = openmc.Settings() - settings.batches = 100 + settings.batches = 2 settings.inactive = 10 settings.particles = 1000 model = openmc.Model() From bc7fa45412550e21fc9329194fdebf6083dd1059 Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot <15145274+bam241@users.noreply.github.com> Date: Wed, 15 Jan 2025 08:50:50 +0100 Subject: [PATCH 15/30] Update tests/unit_tests/dagmc/test_model.py Co-authored-by: Jonathan Shimwell --- tests/unit_tests/dagmc/test_model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit_tests/dagmc/test_model.py b/tests/unit_tests/dagmc/test_model.py index d2f4511ce4a..38ce92c45cb 100644 --- a/tests/unit_tests/dagmc/test_model.py +++ b/tests/unit_tests/dagmc/test_model.py @@ -332,7 +332,7 @@ def test_dagmc_vacuum(request, run_in_tmpdir, tmpdir): settings = openmc.Settings() settings.batches = 2 settings.inactive = 10 - settings.particles = 1000 + settings.particles = 100 model = openmc.Model() model.materials = openmc.Materials(mats.values()) model.geometry = openmc.Geometry(root=daguniv) From 63ccfe04682bca5360c4bde4ac4e7ca438b822b3 Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Wed, 15 Jan 2025 10:34:21 +0100 Subject: [PATCH 16/30] This look good --- tests/unit_tests/dagmc/test_model.py | 115 +++++++++++++++------------ 1 file changed, 64 insertions(+), 51 deletions(-) diff --git a/tests/unit_tests/dagmc/test_model.py b/tests/unit_tests/dagmc/test_model.py index 38ce92c45cb..30ee8f58e2f 100644 --- a/tests/unit_tests/dagmc/test_model.py +++ b/tests/unit_tests/dagmc/test_model.py @@ -8,6 +8,7 @@ import pytest import openmc from openmc.utility_funcs import change_directory +import openmc.lib pytestmark = pytest.mark.skipif( not openmc.lib._dagmc_enabled(), reason="DAGMC CAD geometry is not enabled.") @@ -259,20 +260,8 @@ def test_dagmc_xml(model): def test_dagmc_vacuum(request, run_in_tmpdir, tmpdir): - shutil.copyfile(Path(request.fspath).parent / "dagmc.h5m", tmpdir/"dagmc_not_a_vacuum.h5m") - + # Required initial mats. mats = {} - mats["not_a_vacuum"] = openmc.Material(1, name="not_a_vacuum") - mats["not_a_vacuum"].add_nuclide("U235", 0.03) - mats["not_a_vacuum"].add_nuclide("U238", 0.97) - mats["not_a_vacuum"].add_nuclide("O16", 2.0) - mats["not_a_vacuum"].set_density("g/cm3", 10.0) - - mats["vacuum"] = openmc.Material(name="vacuum") - mats["vacuum"].add_nuclide("U235", 0.03) - mats["vacuum"].add_nuclide("U238", 0.97) - mats["vacuum"].add_nuclide("O16", 2.0) - mats["vacuum"].set_density("g/cm3", 10.0) mats["41"] = openmc.Material(name="41") mats["41"].add_nuclide("U235", 0.03) @@ -280,87 +269,111 @@ def test_dagmc_vacuum(request, run_in_tmpdir, tmpdir): mats["41"].add_nuclide("O16", 2.0) mats["41"].set_density("g/cm3", 10.0) - hf = h5py.File(tmpdir/ "dagmc_not_a_vacuum.h5m", 'r+') + # Not a vacuum material + na_vacuum_str = "not_a_vacuum" + mats[na_vacuum_str] = openmc.Material(name=na_vacuum_str) + mats[na_vacuum_str].add_nuclide("U235", 0.03) + mats[na_vacuum_str].add_nuclide("U238", 0.97) + mats[na_vacuum_str].add_nuclide("O16", 2.0) + mats[na_vacuum_str].set_density("g/cm3", 10.0) + + # Tweaking the h5m file to change the material assignment + na_vacuum_h5 = tmpdir / f"dagmc_{na_vacuum_str}.h5m" + shutil.copyfile(Path(request.fspath).parent / "dagmc.h5m", + na_vacuum_h5) + hf = h5py.File(na_vacuum_h5, 'r+') new_assignment = 'mat:not_a_vacuum'.encode('utf-8') hf['/tstt/tags/NAME']['values'][1] = new_assignment hf.close() - - p = tmpdir/"dagmc_not_a_vacuum.h5m" - daguniv = openmc.DAGMCUniverse(p, auto_geom_ids=True).bounded_universe() + + # Set the Model + daguniv = openmc.DAGMCUniverse(na_vacuum_h5, + auto_geom_ids=True).bounded_universe() settings = openmc.Settings() - settings.batches = 100 - settings.particles = 1000 + settings.batches = 10 + settings.particles = 100 model = openmc.Model() model.materials = openmc.Materials(mats.values()) model.geometry = openmc.Geometry(root=daguniv) model.settings = settings + + # Set the Tally model.init_lib() model.sync_dagmc_universes() for univ in model.geometry.get_all_universes().values(): if isinstance(univ, openmc.DAGMCUniverse): dag_univ = univ break - my_tally = openmc.Tally() cell_filter = openmc.CellFilter([x.id for x in dag_univ.get_all_cells().values()]) - my_tally.scores = ['nu-fission'] my_tally.filters = [cell_filter] model.tallies.append(my_tally) + + # Only a confined point source src = openmc.IndependentSource(space=openmc.stats.Point()) model.settings.source = src - model.export_to_model_xml('sub_dir_not_a_vacuum/model.xml',) - openmc.run(cwd='sub_dir_not_a_vacuum') - # Read the statepoint file. - sp = openmc.StatePoint("sub_dir_not_a_vacuum/statepoint.100.h5") - - # Extract the tally data as a Pandas DataFrame. - tally_dfs = [t.get_pandas_dataframe() for t in sp.tallies.values()] - df = pd.concat(tally_dfs, ignore_index=True) - # not detected as vacuum so tally should be non-zero - assert df['mean'].loc[0] > 0 - - shutil.copyfile(Path(request.fspath).parent / "dagmc.h5m", tmpdir/"dagmc_a_vacuum.h5m") - hf = h5py.File(tmpdir/ "dagmc_a_vacuum.h5m", 'r+') + # Run and check the results + sub_dir = f"sub_dir_{na_vacuum_str}" + model.export_to_model_xml(f'{sub_dir}/model.xml',) + openmc.run(cwd=sub_dir) + # If cell are not vacuum, fission site should not spread to other cells + with openmc.StatePoint(f"{sub_dir}/statepoint.{settings.batches}.h5") as sp: + tally = list(sp.tallies.values())[0] + non_zero_tal = [x for x in tally.mean.flatten() if x > 0] + assert len(non_zero_tal) > 1 + + # Not a vacuum material + vacuum_str = "vacuum" + mats[vacuum_str] = openmc.Material(name=vacuum_str) + mats[vacuum_str].add_nuclide("U235", 0.03) + mats[vacuum_str].add_nuclide("U238", 0.97) + mats[vacuum_str].add_nuclide("O16", 2.0) + mats[vacuum_str].set_density("g/cm3", 10.0) + + # Tweaking the h5m file to change the material assignment + vacuum_h5 = tmpdir / f"dagmc_{vacuum_str}.h5m" + shutil.copyfile(Path(request.fspath).parent / "dagmc.h5m", vacuum_h5) + hf = h5py.File(vacuum_h5, 'r+') new_assignment = 'mat:vacuum'.encode('utf-8') hf['/tstt/tags/NAME']['values'][1] = new_assignment hf.close() - p = tmpdir/"dagmc_a_vacuum.h5m" - daguniv = openmc.DAGMCUniverse(p, auto_geom_ids=True).bounded_universe() + # Set the Model + daguniv = openmc.DAGMCUniverse(vacuum_h5, + auto_geom_ids=True).bounded_universe() settings = openmc.Settings() - settings.batches = 2 - settings.inactive = 10 + settings.batches = 10 settings.particles = 100 model = openmc.Model() model.materials = openmc.Materials(mats.values()) model.geometry = openmc.Geometry(root=daguniv) model.settings = settings + + # Set the Tally model.init_lib() model.sync_dagmc_universes() for univ in model.geometry.get_all_universes().values(): if isinstance(univ, openmc.DAGMCUniverse): dag_univ = univ break - my_tally = openmc.Tally() cell_filter = openmc.CellFilter([x.id for x in dag_univ.get_all_cells().values()]) - my_tally.scores = ['nu-fission'] my_tally.filters = [cell_filter] model.tallies.append(my_tally) + + # Only a confined point source src = openmc.IndependentSource(space=openmc.stats.Point()) model.settings.source = src - model.export_to_model_xml('sub_dir_vacuum/model.xml',) - sp_filename = openmc.run(cwd='sub_dir_vacuum') - # Read the statepoint file. - sp = openmc.StatePoint(sp_filename) - - # Extract the tally data as a Pandas DataFrame. - tally_dfs = [t.get_pandas_dataframe() for t in sp.tallies.values()] - df = pd.concat(tally_dfs, ignore_index=True) - # detected as vacuum so tally should be zero - assert df['mean'].loc[0] == 0 - + # Run and check the results + sub_dir = f"sub_dir_{vacuum_str}" + model.export_to_model_xml(f'{sub_dir}/model.xml',) + openmc.run(cwd=sub_dir) + # If cell are not vacuum, fission site should not spread to other cells + with openmc.StatePoint(f"{sub_dir}/statepoint.{settings.batches}.h5") as sp: + tally = list(sp.tallies.values())[0] + non_zero_tal = [x for x in tally.mean.flatten() if x > 0] + assert len(non_zero_tal) == 1 From b36da05bb3ddd4b9c0f3ec34f8d94ff54bf449d4 Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Wed, 15 Jan 2025 10:35:14 +0100 Subject: [PATCH 17/30] fixing comments --- tests/unit_tests/dagmc/test_model.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/unit_tests/dagmc/test_model.py b/tests/unit_tests/dagmc/test_model.py index 30ee8f58e2f..423941864a7 100644 --- a/tests/unit_tests/dagmc/test_model.py +++ b/tests/unit_tests/dagmc/test_model.py @@ -259,10 +259,8 @@ def test_dagmc_xml(model): assert all([xml_mat.id == orig_mat.id for xml_mat, orig_mat in zip(xml_mats, model_mats)]) def test_dagmc_vacuum(request, run_in_tmpdir, tmpdir): - # Required initial mats. mats = {} - mats["41"] = openmc.Material(name="41") mats["41"].add_nuclide("U235", 0.03) mats["41"].add_nuclide("U238", 0.97) @@ -324,7 +322,7 @@ def test_dagmc_vacuum(request, run_in_tmpdir, tmpdir): non_zero_tal = [x for x in tally.mean.flatten() if x > 0] assert len(non_zero_tal) > 1 - # Not a vacuum material + # Vacuum material vacuum_str = "vacuum" mats[vacuum_str] = openmc.Material(name=vacuum_str) mats[vacuum_str].add_nuclide("U235", 0.03) From ea29f54e93c01d2c4c8d2fd5174a1129a8acfa19 Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot <15145274+bam241@users.noreply.github.com> Date: Wed, 15 Jan 2025 10:41:21 +0100 Subject: [PATCH 18/30] Apply suggestions from code review Co-authored-by: Jonathan Shimwell --- tests/unit_tests/dagmc/test_model.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/tests/unit_tests/dagmc/test_model.py b/tests/unit_tests/dagmc/test_model.py index 423941864a7..18a35e22e75 100644 --- a/tests/unit_tests/dagmc/test_model.py +++ b/tests/unit_tests/dagmc/test_model.py @@ -2,7 +2,6 @@ import h5py import shutil -import pandas as pd import lxml.etree as ET import numpy as np import pytest @@ -262,18 +261,14 @@ def test_dagmc_vacuum(request, run_in_tmpdir, tmpdir): # Required initial mats. mats = {} mats["41"] = openmc.Material(name="41") - mats["41"].add_nuclide("U235", 0.03) - mats["41"].add_nuclide("U238", 0.97) - mats["41"].add_nuclide("O16", 2.0) - mats["41"].set_density("g/cm3", 10.0) + mats["41"].add_nuclide("U235", 1) + mats["41"].set_density("g/cm3", 0.03) # Not a vacuum material na_vacuum_str = "not_a_vacuum" mats[na_vacuum_str] = openmc.Material(name=na_vacuum_str) - mats[na_vacuum_str].add_nuclide("U235", 0.03) - mats[na_vacuum_str].add_nuclide("U238", 0.97) - mats[na_vacuum_str].add_nuclide("O16", 2.0) - mats[na_vacuum_str].set_density("g/cm3", 10.0) + mats[na_vacuum_str].add_nuclide("U235", 1) + mats[na_vacuum_str].set_density("g/cm3", 0.03) # Tweaking the h5m file to change the material assignment na_vacuum_h5 = tmpdir / f"dagmc_{na_vacuum_str}.h5m" From 6915706ff90fd085291ef536e77a1d24b2dcce81 Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Wed, 15 Jan 2025 10:43:16 +0100 Subject: [PATCH 19/30] increasing density a bit --- tests/unit_tests/dagmc/test_model.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit_tests/dagmc/test_model.py b/tests/unit_tests/dagmc/test_model.py index 18a35e22e75..308dd271545 100644 --- a/tests/unit_tests/dagmc/test_model.py +++ b/tests/unit_tests/dagmc/test_model.py @@ -262,13 +262,13 @@ def test_dagmc_vacuum(request, run_in_tmpdir, tmpdir): mats = {} mats["41"] = openmc.Material(name="41") mats["41"].add_nuclide("U235", 1) - mats["41"].set_density("g/cm3", 0.03) + mats["41"].set_density("g/cm3", 1) # Not a vacuum material na_vacuum_str = "not_a_vacuum" mats[na_vacuum_str] = openmc.Material(name=na_vacuum_str) mats[na_vacuum_str].add_nuclide("U235", 1) - mats[na_vacuum_str].set_density("g/cm3", 0.03) + mats[na_vacuum_str].set_density("g/cm3", 1) # Tweaking the h5m file to change the material assignment na_vacuum_h5 = tmpdir / f"dagmc_{na_vacuum_str}.h5m" From d4c45f8121a132ceefe891974565e08b3e3cea7b Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Wed, 15 Jan 2025 10:43:34 +0100 Subject: [PATCH 20/30] Revmoving locally required import --- tests/unit_tests/dagmc/test_model.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/unit_tests/dagmc/test_model.py b/tests/unit_tests/dagmc/test_model.py index 308dd271545..e2e1e8d771a 100644 --- a/tests/unit_tests/dagmc/test_model.py +++ b/tests/unit_tests/dagmc/test_model.py @@ -7,7 +7,6 @@ import pytest import openmc from openmc.utility_funcs import change_directory -import openmc.lib pytestmark = pytest.mark.skipif( not openmc.lib._dagmc_enabled(), reason="DAGMC CAD geometry is not enabled.") From de6d8ba53802ab639042a3504c5f8786b74c6267 Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Wed, 15 Jan 2025 14:18:28 +0100 Subject: [PATCH 21/30] working --- tests/unit_tests/dagmc/test_model.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit_tests/dagmc/test_model.py b/tests/unit_tests/dagmc/test_model.py index e2e1e8d771a..308dd271545 100644 --- a/tests/unit_tests/dagmc/test_model.py +++ b/tests/unit_tests/dagmc/test_model.py @@ -7,6 +7,7 @@ import pytest import openmc from openmc.utility_funcs import change_directory +import openmc.lib pytestmark = pytest.mark.skipif( not openmc.lib._dagmc_enabled(), reason="DAGMC CAD geometry is not enabled.") From 85802f58e29cd3a589bec2dab7529a5261d468a5 Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Wed, 15 Jan 2025 14:57:51 +0100 Subject: [PATCH 22/30] trying to tweak tempdir --- tests/unit_tests/dagmc/test_model.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/unit_tests/dagmc/test_model.py b/tests/unit_tests/dagmc/test_model.py index 308dd271545..7645251deca 100644 --- a/tests/unit_tests/dagmc/test_model.py +++ b/tests/unit_tests/dagmc/test_model.py @@ -1,5 +1,6 @@ from pathlib import Path +import os import h5py import shutil import lxml.etree as ET @@ -257,7 +258,8 @@ def test_dagmc_xml(model): for xml_mats, model_mats in zip(xml_dagmc_univ._material_overrides.values(), dag_univ._material_overrides.values()): assert all([xml_mat.id == orig_mat.id for xml_mat, orig_mat in zip(xml_mats, model_mats)]) -def test_dagmc_vacuum(request, run_in_tmpdir, tmpdir): +def test_dagmc_vacuum(request, run_in_tmpdir): + tmpdir = Path(os.getcwd()) # Required initial mats. mats = {} mats["41"] = openmc.Material(name="41") From ae2812504ed2aa500317f5a5924c7d5964da8002 Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Wed, 15 Jan 2025 19:03:21 +0100 Subject: [PATCH 23/30] update path management --- tests/unit_tests/dagmc/test_model.py | 37 +++++++++++++++------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/tests/unit_tests/dagmc/test_model.py b/tests/unit_tests/dagmc/test_model.py index 7645251deca..bcd8bb1a3b3 100644 --- a/tests/unit_tests/dagmc/test_model.py +++ b/tests/unit_tests/dagmc/test_model.py @@ -258,8 +258,9 @@ def test_dagmc_xml(model): for xml_mats, model_mats in zip(xml_dagmc_univ._material_overrides.values(), dag_univ._material_overrides.values()): assert all([xml_mat.id == orig_mat.id for xml_mat, orig_mat in zip(xml_mats, model_mats)]) -def test_dagmc_vacuum(request, run_in_tmpdir): - tmpdir = Path(os.getcwd()) +def test_dagmc_vacuum(run_in_tmpdir, request): + h5m = Path(request.fspath).parent / "dagmc.h5m" + # Required initial mats. mats = {} mats["41"] = openmc.Material(name="41") @@ -273,16 +274,17 @@ def test_dagmc_vacuum(request, run_in_tmpdir): mats[na_vacuum_str].set_density("g/cm3", 1) # Tweaking the h5m file to change the material assignment - na_vacuum_h5 = tmpdir / f"dagmc_{na_vacuum_str}.h5m" - shutil.copyfile(Path(request.fspath).parent / "dagmc.h5m", - na_vacuum_h5) + subdir = Path(na_vacuum_str) + subdir.mkdir() + na_vacuum_h5 = subdir / f"dagmc_{na_vacuum_str}.h5m" + shutil.copy(h5m, na_vacuum_h5) hf = h5py.File(na_vacuum_h5, 'r+') new_assignment = 'mat:not_a_vacuum'.encode('utf-8') hf['/tstt/tags/NAME']['values'][1] = new_assignment hf.close() # Set the Model - daguniv = openmc.DAGMCUniverse(na_vacuum_h5, + daguniv = openmc.DAGMCUniverse(na_vacuum_h5.absolute(), auto_geom_ids=True).bounded_universe() settings = openmc.Settings() settings.batches = 10 @@ -310,11 +312,10 @@ def test_dagmc_vacuum(request, run_in_tmpdir): model.settings.source = src # Run and check the results - sub_dir = f"sub_dir_{na_vacuum_str}" - model.export_to_model_xml(f'{sub_dir}/model.xml',) - openmc.run(cwd=sub_dir) + model.export_to_model_xml((subdir / 'model.xml').absolute()) + openmc.run(cwd=subdir.absolute()) # If cell are not vacuum, fission site should not spread to other cells - with openmc.StatePoint(f"{sub_dir}/statepoint.{settings.batches}.h5") as sp: + with openmc.StatePoint(subdir / f"statepoint.{settings.batches}.h5") as sp: tally = list(sp.tallies.values())[0] non_zero_tal = [x for x in tally.mean.flatten() if x > 0] assert len(non_zero_tal) > 1 @@ -328,15 +329,18 @@ def test_dagmc_vacuum(request, run_in_tmpdir): mats[vacuum_str].set_density("g/cm3", 10.0) # Tweaking the h5m file to change the material assignment - vacuum_h5 = tmpdir / f"dagmc_{vacuum_str}.h5m" - shutil.copyfile(Path(request.fspath).parent / "dagmc.h5m", vacuum_h5) + subdir = Path(vacuum_str) + subdir.mkdir() + vacuum_h5 = subdir / f"dagmc_{vacuum_str}.h5m" + shutil.copy(h5m, vacuum_h5) + hf = h5py.File(vacuum_h5, 'r+') hf = h5py.File(vacuum_h5, 'r+') new_assignment = 'mat:vacuum'.encode('utf-8') hf['/tstt/tags/NAME']['values'][1] = new_assignment hf.close() # Set the Model - daguniv = openmc.DAGMCUniverse(vacuum_h5, + daguniv = openmc.DAGMCUniverse(vacuum_h5.absolute(), auto_geom_ids=True).bounded_universe() settings = openmc.Settings() settings.batches = 10 @@ -364,11 +368,10 @@ def test_dagmc_vacuum(request, run_in_tmpdir): model.settings.source = src # Run and check the results - sub_dir = f"sub_dir_{vacuum_str}" - model.export_to_model_xml(f'{sub_dir}/model.xml',) - openmc.run(cwd=sub_dir) + model.export_to_model_xml((subdir / 'model.xml').absolute()) + openmc.run(cwd=subdir.absolute()) # If cell are not vacuum, fission site should not spread to other cells - with openmc.StatePoint(f"{sub_dir}/statepoint.{settings.batches}.h5") as sp: + with openmc.StatePoint(subdir / f"statepoint.{settings.batches}.h5") as sp: tally = list(sp.tallies.values())[0] non_zero_tal = [x for x in tally.mean.flatten() if x > 0] assert len(non_zero_tal) == 1 From 761d22c51b522d1b55ea93708a035129d3505e5e Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Thu, 16 Jan 2025 09:49:47 +0100 Subject: [PATCH 24/30] enabling ssh --- .github/workflows/ci.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c5051b8d0bb..37d8a2d2c49 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -153,6 +153,11 @@ jobs: CTEST_OUTPUT_ON_FAILURE=1 make test -C $GITHUB_WORKSPACE/build/ $GITHUB_WORKSPACE/tools/ci/gha-script.sh + - name: Setup tmate debug session + continue-on-error: true + uses: mxschmitt/action-tmate@v3 + timeout-minutes: 60 + - name: after_success shell: bash run: | From ef989df57a211da2dab7e9427307b500e809fa8a Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Thu, 16 Jan 2025 09:50:47 +0100 Subject: [PATCH 25/30] fixing formating --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 37d8a2d2c49..b97c3544263 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -154,9 +154,9 @@ jobs: $GITHUB_WORKSPACE/tools/ci/gha-script.sh - name: Setup tmate debug session - continue-on-error: true - uses: mxschmitt/action-tmate@v3 - timeout-minutes: 60 + continue-on-error: true + uses: mxschmitt/action-tmate@v3 + timeout-minutes: 60 - name: after_success shell: bash From d2c48820713990d7058eb4674251087886f19781 Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Thu, 16 Jan 2025 11:11:47 +0100 Subject: [PATCH 26/30] putting ssh session at the right place --- .github/workflows/ci.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b97c3544263..31336ea6823 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -146,6 +146,11 @@ jobs: - name: before shell: bash run: $GITHUB_WORKSPACE/tools/ci/gha-before-script.sh + + - name: Setup tmate debug session + continue-on-error: true + uses: mxschmitt/action-tmate@v3 + timeout-minutes: 60 - name: test shell: bash @@ -153,10 +158,7 @@ jobs: CTEST_OUTPUT_ON_FAILURE=1 make test -C $GITHUB_WORKSPACE/build/ $GITHUB_WORKSPACE/tools/ci/gha-script.sh - - name: Setup tmate debug session - continue-on-error: true - uses: mxschmitt/action-tmate@v3 - timeout-minutes: 60 + - name: after_success shell: bash From 9958ac050aa42204a81abcecada96dc17f2e195b Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Thu, 16 Jan 2025 12:08:20 +0100 Subject: [PATCH 27/30] tweaking mat composition --- .github/workflows/ci.yml | 5 ----- tests/unit_tests/dagmc/test_model.py | 12 ++++++++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 31336ea6823..fa8cdab9c61 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -146,11 +146,6 @@ jobs: - name: before shell: bash run: $GITHUB_WORKSPACE/tools/ci/gha-before-script.sh - - - name: Setup tmate debug session - continue-on-error: true - uses: mxschmitt/action-tmate@v3 - timeout-minutes: 60 - name: test shell: bash diff --git a/tests/unit_tests/dagmc/test_model.py b/tests/unit_tests/dagmc/test_model.py index bcd8bb1a3b3..f681993ecca 100644 --- a/tests/unit_tests/dagmc/test_model.py +++ b/tests/unit_tests/dagmc/test_model.py @@ -264,14 +264,18 @@ def test_dagmc_vacuum(run_in_tmpdir, request): # Required initial mats. mats = {} mats["41"] = openmc.Material(name="41") - mats["41"].add_nuclide("U235", 1) - mats["41"].set_density("g/cm3", 1) + mats["41"].add_nuclide("U235", 0.03) + mats["41"].add_nuclide("U238", 0.97) + mats["41"].add_nuclide("O16", 2.0) + mats["41"].set_density("g/cm3", 10.0) # Not a vacuum material na_vacuum_str = "not_a_vacuum" mats[na_vacuum_str] = openmc.Material(name=na_vacuum_str) - mats[na_vacuum_str].add_nuclide("U235", 1) - mats[na_vacuum_str].set_density("g/cm3", 1) + mats[na_vacuum_str].add_nuclide("U235", 0.03) + mats[na_vacuum_str].add_nuclide("U238", 0.97) + mats[na_vacuum_str].add_nuclide("O16", 2.0) + mats[na_vacuum_str].set_density("g/cm3", 10.0) # Tweaking the h5m file to change the material assignment subdir = Path(na_vacuum_str) From ee84c13cfe63526cc0c6526b562c1bd0b5a8668a Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Thu, 16 Jan 2025 12:13:29 +0100 Subject: [PATCH 28/30] restoring the exact ci.yml --- .github/workflows/ci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fa8cdab9c61..c5051b8d0bb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -153,8 +153,6 @@ jobs: CTEST_OUTPUT_ON_FAILURE=1 make test -C $GITHUB_WORKSPACE/build/ $GITHUB_WORKSPACE/tools/ci/gha-script.sh - - - name: after_success shell: bash run: | From ffe27fddc7a184afc29214b9e0b1a5805d6e37c8 Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Thu, 16 Jan 2025 16:09:12 +0100 Subject: [PATCH 29/30] woudl a finalize() help ? --- tests/unit_tests/dagmc/test_model.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit_tests/dagmc/test_model.py b/tests/unit_tests/dagmc/test_model.py index f681993ecca..8c91ad36d4f 100644 --- a/tests/unit_tests/dagmc/test_model.py +++ b/tests/unit_tests/dagmc/test_model.py @@ -379,3 +379,4 @@ def test_dagmc_vacuum(run_in_tmpdir, request): tally = list(sp.tallies.values())[0] non_zero_tal = [x for x in tally.mean.flatten() if x > 0] assert len(non_zero_tal) == 1 + openmc.lib.finalize() From d806829b256954eaae4d1a41abb3d7a11a1ebd62 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 21 Jan 2025 14:17:05 -0600 Subject: [PATCH 30/30] Simplifying vacuum assignment test --- tests/unit_tests/dagmc/test_model.py | 110 ++++++--------------------- 1 file changed, 22 insertions(+), 88 deletions(-) diff --git a/tests/unit_tests/dagmc/test_model.py b/tests/unit_tests/dagmc/test_model.py index 8c91ad36d4f..9016d918d05 100644 --- a/tests/unit_tests/dagmc/test_model.py +++ b/tests/unit_tests/dagmc/test_model.py @@ -259,29 +259,29 @@ def test_dagmc_xml(model): assert all([xml_mat.id == orig_mat.id for xml_mat, orig_mat in zip(xml_mats, model_mats)]) def test_dagmc_vacuum(run_in_tmpdir, request): - h5m = Path(request.fspath).parent / "dagmc.h5m" - - # Required initial mats. + # Required initial mats mats = {} mats["41"] = openmc.Material(name="41") - mats["41"].add_nuclide("U235", 0.03) - mats["41"].add_nuclide("U238", 0.97) - mats["41"].add_nuclide("O16", 2.0) - mats["41"].set_density("g/cm3", 10.0) + mats["41"].add_nuclide("H1", 1.0) + mats["41"].set_density("g/cm3", 1.0) # Not a vacuum material na_vacuum_str = "not_a_vacuum" mats[na_vacuum_str] = openmc.Material(name=na_vacuum_str) - mats[na_vacuum_str].add_nuclide("U235", 0.03) - mats[na_vacuum_str].add_nuclide("U238", 0.97) - mats[na_vacuum_str].add_nuclide("O16", 2.0) + mats[na_vacuum_str].add_nuclide("U238", 1.0) mats[na_vacuum_str].set_density("g/cm3", 10.0) + model = openmc.Model() + model.settings = openmc.Settings() + model.settings.batches = 10 + model.settings.particles = 100 + model.materials = openmc.Materials(mats.values()) + + orig_h5m = Path(request.fspath).parent / "dagmc.h5m" + # Tweaking the h5m file to change the material assignment - subdir = Path(na_vacuum_str) - subdir.mkdir() - na_vacuum_h5 = subdir / f"dagmc_{na_vacuum_str}.h5m" - shutil.copy(h5m, na_vacuum_h5) + na_vacuum_h5 = Path(f"dagmc_{na_vacuum_str}.h5m") + shutil.copy(orig_h5m, na_vacuum_h5) hf = h5py.File(na_vacuum_h5, 'r+') new_assignment = 'mat:not_a_vacuum'.encode('utf-8') hf['/tstt/tags/NAME']['values'][1] = new_assignment @@ -290,93 +290,27 @@ def test_dagmc_vacuum(run_in_tmpdir, request): # Set the Model daguniv = openmc.DAGMCUniverse(na_vacuum_h5.absolute(), auto_geom_ids=True).bounded_universe() - settings = openmc.Settings() - settings.batches = 10 - settings.particles = 100 - model = openmc.Model() - model.materials = openmc.Materials(mats.values()) model.geometry = openmc.Geometry(root=daguniv) - model.settings = settings - - # Set the Tally - model.init_lib() - model.sync_dagmc_universes() - for univ in model.geometry.get_all_universes().values(): - if isinstance(univ, openmc.DAGMCUniverse): - dag_univ = univ - break - my_tally = openmc.Tally() - cell_filter = openmc.CellFilter([x.id for x in dag_univ.get_all_cells().values()]) - my_tally.scores = ['nu-fission'] - my_tally.filters = [cell_filter] - model.tallies.append(my_tally) - - # Only a confined point source - src = openmc.IndependentSource(space=openmc.stats.Point()) - model.settings.source = src - - # Run and check the results - model.export_to_model_xml((subdir / 'model.xml').absolute()) - openmc.run(cwd=subdir.absolute()) - # If cell are not vacuum, fission site should not spread to other cells - with openmc.StatePoint(subdir / f"statepoint.{settings.batches}.h5") as sp: - tally = list(sp.tallies.values())[0] - non_zero_tal = [x for x in tally.mean.flatten() if x > 0] - assert len(non_zero_tal) > 1 # Vacuum material vacuum_str = "vacuum" - mats[vacuum_str] = openmc.Material(name=vacuum_str) - mats[vacuum_str].add_nuclide("U235", 0.03) - mats[vacuum_str].add_nuclide("U238", 0.97) - mats[vacuum_str].add_nuclide("O16", 2.0) - mats[vacuum_str].set_density("g/cm3", 10.0) # Tweaking the h5m file to change the material assignment - subdir = Path(vacuum_str) - subdir.mkdir() - vacuum_h5 = subdir / f"dagmc_{vacuum_str}.h5m" - shutil.copy(h5m, vacuum_h5) + vacuum_h5 = Path(f"dagmc_{vacuum_str}.h5m") + shutil.copy(orig_h5m, vacuum_h5) hf = h5py.File(vacuum_h5, 'r+') hf = h5py.File(vacuum_h5, 'r+') new_assignment = 'mat:vacuum'.encode('utf-8') hf['/tstt/tags/NAME']['values'][1] = new_assignment hf.close() - # Set the Model + # Create a new DAGMC unvierse daguniv = openmc.DAGMCUniverse(vacuum_h5.absolute(), auto_geom_ids=True).bounded_universe() - settings = openmc.Settings() - settings.batches = 10 - settings.particles = 100 - model = openmc.Model() - model.materials = openmc.Materials(mats.values()) + # Update the model geometry model.geometry = openmc.Geometry(root=daguniv) - model.settings = settings - # Set the Tally - model.init_lib() - model.sync_dagmc_universes() - for univ in model.geometry.get_all_universes().values(): - if isinstance(univ, openmc.DAGMCUniverse): - dag_univ = univ - break - my_tally = openmc.Tally() - cell_filter = openmc.CellFilter([x.id for x in dag_univ.get_all_cells().values()]) - my_tally.scores = ['nu-fission'] - my_tally.filters = [cell_filter] - model.tallies.append(my_tally) - - # Only a confined point source - src = openmc.IndependentSource(space=openmc.stats.Point()) - model.settings.source = src - - # Run and check the results - model.export_to_model_xml((subdir / 'model.xml').absolute()) - openmc.run(cwd=subdir.absolute()) - # If cell are not vacuum, fission site should not spread to other cells - with openmc.StatePoint(subdir / f"statepoint.{settings.batches}.h5") as sp: - tally = list(sp.tallies.values())[0] - non_zero_tal = [x for x in tally.mean.flatten() if x > 0] - assert len(non_zero_tal) == 1 - openmc.lib.finalize() + model.export_to_model_xml() + with openmc.lib.run_in_memory(): + material = openmc.lib.find_material((0, 0, 0)) + assert material is None \ No newline at end of file