From ea0bea32b0125e17a7a74237837ef0c06bada34b Mon Sep 17 00:00:00 2001 From: Erik B Knudsen Date: Mon, 18 Dec 2023 11:03:40 +0100 Subject: [PATCH 01/12] add cylinder test --- .../test_csg_cad_cylinder.py | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 tests/test_cad_to_openmc/test_csg_cad_cylinder.py diff --git a/tests/test_cad_to_openmc/test_csg_cad_cylinder.py b/tests/test_cad_to_openmc/test_csg_cad_cylinder.py new file mode 100644 index 0000000..4b009f6 --- /dev/null +++ b/tests/test_cad_to_openmc/test_csg_cad_cylinder.py @@ -0,0 +1,61 @@ +from model_benchmark_zoo import Cylinder +import openmc +import math + +def test_compare(): + # single material used in both simulations + mat1 = openmc.Material(name='1') + mat1.add_nuclide('Fe56', 1) + mat1.set_density('g/cm3', 1) + my_materials = openmc.Materials([mat1]) + + # geometry used in both simulations + common_geometry_object = Cylinder(materials=my_materials, radius=1, height=100) + # just writing a CAD step file for visulisation + common_geometry_object.export_stp_file("cylinder.stp") + + mat_filter = openmc.MaterialFilter(mat1) + tally = openmc.Tally(name='mat1_flux_tally') + tally.filters = [mat_filter] + tally.scores = ['flux'] + my_tallies = openmc.Tallies([tally]) + + my_settings = openmc.Settings() + my_settings.batches = 10 + my_settings.inactive = 0 + my_settings.particles = 500 + my_settings.run_mode = 'fixed source' + + # Create a DT point source + my_source = openmc.Source() + my_source.space = openmc.stats.Point((0, 0, 0)) + my_source.angle = openmc.stats.Isotropic() + my_source.energy = openmc.stats.Discrete([14e6], [1]) + my_settings.source = my_source + + # making openmc.Model with CSG geometry + csg_model = common_geometry_object.csg_model() + csg_model.materials = my_materials + csg_model.tallies = my_tallies + csg_model.settings = my_settings + + output_file_from_csg = csg_model.run() + + # extracting the tally result from the CSG simulation + with openmc.StatePoint(output_file_from_csg) as sp_from_csg: + csg_result = sp_from_csg.get_tally(name="mat1_flux_tally") + + # making openmc.Model with DAGMC geometry and specifying mesh sizes to get a good representation of a cylinder + dag_model = common_geometry_object.dagmc_model_with_cad_to_openmc() + dag_model.materials = my_materials + dag_model.tallies = my_tallies + dag_model.settings = my_settings + + output_file_from_cad = dag_model.run() + + # extracting the tally result from the DAGMC simulation + with openmc.StatePoint(output_file_from_cad) as sp_from_cad: + cad_result = sp_from_cad.get_tally(name="mat1_flux_tally") + + assert math.isclose(cad_result.mean, csg_result.mean) + From ff686821d90a79d51f0c54cc77125a1ee5d2e179 Mon Sep 17 00:00:00 2001 From: Erik B Knudsen Date: Mon, 18 Dec 2023 11:07:05 +0100 Subject: [PATCH 02/12] add workflow to do autotest --- .github/workflows/cylinder_cad_to_openmc.yml | 29 ++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .github/workflows/cylinder_cad_to_openmc.yml diff --git a/.github/workflows/cylinder_cad_to_openmc.yml b/.github/workflows/cylinder_cad_to_openmc.yml new file mode 100644 index 0000000..2ceb767 --- /dev/null +++ b/.github/workflows/cylinder_cad_to_openmc.yml @@ -0,0 +1,29 @@ +name: cylinder - cad to openmc + +on: + pull_request: + branches: + - develop + - main + push: + - main + +jobs: + testing: + runs-on: ubuntu-latest + steps: + + - name: checkout actions + uses: actions/checkout@v4 + + - name: use upstream test composite action + uses: ./.github/actions/dependencies + + - shell: bash + env: + OPENMC_CROSS_SECTIONS: /home/runner/work/model_benchmark_zoo/model_benchmark_zoo/cross_sections.xml + run: | + source "${HOME}/conda/etc/profile.d/conda.sh" + source "${HOME}/conda/etc/profile.d/mamba.sh" + mamba activate + pytest tests/test_cad_to_dagmc/test_csg_cad_cylinder.py From 795a5cb5bb1b7694e8956011c7f431439ccc012a Mon Sep 17 00:00:00 2001 From: Erik B Knudsen Date: Mon, 18 Dec 2023 11:27:29 +0100 Subject: [PATCH 03/12] actually add the cad_to_openmc model function for cylinder --- src/model_benchmark_zoo/cylinder.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/model_benchmark_zoo/cylinder.py b/src/model_benchmark_zoo/cylinder.py index 296b130..cadda50 100644 --- a/src/model_benchmark_zoo/cylinder.py +++ b/src/model_benchmark_zoo/cylinder.py @@ -46,3 +46,25 @@ def dagmc_model(self, filename="sphere.h5m", min_mesh_size=0.1, max_mesh_size=10 geometry = openmc.Geometry(universe) model = openmc.Model(geometry=geometry) return model + + def dagmc_model_with_cad_to_openmc(self, filename="cylinder.h5m"): + from CAD_to_OpenMC import assembly + import openmc + + self.export_stp_file() + + a=assembly.Assembly(["cylinder.step"]) + a.verbose=0 + assembly.mesher_config['threads']=1 + a.run( + backend='stl2', + merge=True, + h5m_filename=filename, + sequential_tags=[self.materials[0].name], + scale=1.0 + ) + + universe = openmc.DAGMCUniverse(filename, auto_geom_ids=True).bounded_universe() + geometry = openmc.Geometry(universe) + model = openmc.Model(geometry=geometry) + return model From 80809fc14073c145a494e2dc2b8308bdf4ae6d38 Mon Sep 17 00:00:00 2001 From: Erik B Knudsen Date: Mon, 18 Dec 2023 11:29:10 +0100 Subject: [PATCH 04/12] add cuboid test --- .github/workflows/cuboid_cad_to_openmc.yml | 29 +++++++++ src/model_benchmark_zoo/cuboid.py | 22 +++++++ .../test_cad_to_openmc/test_csg_cad_cuboid.py | 61 +++++++++++++++++++ 3 files changed, 112 insertions(+) create mode 100644 .github/workflows/cuboid_cad_to_openmc.yml create mode 100644 tests/test_cad_to_openmc/test_csg_cad_cuboid.py diff --git a/.github/workflows/cuboid_cad_to_openmc.yml b/.github/workflows/cuboid_cad_to_openmc.yml new file mode 100644 index 0000000..16126aa --- /dev/null +++ b/.github/workflows/cuboid_cad_to_openmc.yml @@ -0,0 +1,29 @@ +name: cuboid - cad to openmc + +on: + pull_request: + branches: + - develop + - main + push: + - main + +jobs: + testing: + runs-on: ubuntu-latest + steps: + + - name: checkout actions + uses: actions/checkout@v4 + + - name: use upstream test composite action + uses: ./.github/actions/dependencies + + - shell: bash + env: + OPENMC_CROSS_SECTIONS: /home/runner/work/model_benchmark_zoo/model_benchmark_zoo/cross_sections.xml + run: | + source "${HOME}/conda/etc/profile.d/conda.sh" + source "${HOME}/conda/etc/profile.d/mamba.sh" + mamba activate + pytest tests/test_cad_to_openmc/test_csg_cad_cuboid.py diff --git a/src/model_benchmark_zoo/cuboid.py b/src/model_benchmark_zoo/cuboid.py index afcc8c7..e7ea862 100644 --- a/src/model_benchmark_zoo/cuboid.py +++ b/src/model_benchmark_zoo/cuboid.py @@ -50,3 +50,25 @@ def dagmc_model(self, filename="Cuboid.h5m", min_mesh_size=0.1, max_mesh_size=10 geometry = openmc.Geometry(universe) model = openmc.Model(geometry=geometry) return model + + def dagmc_model_with_cad_to_openmc(self, filename="Cuboid.h5m"): + from CAD_to_OpenMC import assembly + import openmc + + self.export_stp_file() + + a=assembly.Assembly(["Cuboid.step"]) + a.verbose=0 + assembly.mesher_config['threads']=1 + a.run( + backend='stl2', + merge=True, + h5m_filename=filename, + sequential_tags=[self.materials[0].name], + scale=1.0 + ) + + universe = openmc.DAGMCUniverse(filename, auto_geom_ids=True).bounded_universe() + geometry = openmc.Geometry(universe) + model = openmc.Model(geometry=geometry) + return model diff --git a/tests/test_cad_to_openmc/test_csg_cad_cuboid.py b/tests/test_cad_to_openmc/test_csg_cad_cuboid.py new file mode 100644 index 0000000..7b2e78d --- /dev/null +++ b/tests/test_cad_to_openmc/test_csg_cad_cuboid.py @@ -0,0 +1,61 @@ +from model_benchmark_zoo import Cuboid +import openmc +import math + +def test_comparing(): + # single material used in both simulations + mat1 = openmc.Material(name='1') + mat1.add_nuclide('Fe56', 1) + mat1.set_density('g/cm3', 1) + my_materials = openmc.Materials([mat1]) + + # geometry used in both simulations + common_geometry_object = Cuboid(materials=my_materials, width=10) + # just writing a CAD step file for visulisation + common_geometry_object.export_stp_file("cuboid.stp") + + mat_filter = openmc.MaterialFilter(mat1) + tally = openmc.Tally(name='mat1_flux_tally') + tally.filters = [mat_filter] + tally.scores = ['flux'] + my_tallies = openmc.Tallies([tally]) + + my_settings = openmc.Settings() + my_settings.batches = 10 + my_settings.inactive = 0 + my_settings.particles = 500 + my_settings.run_mode = 'fixed source' + + # Create a DT point source + my_source = openmc.Source() + my_source.space = openmc.stats.Point((0, 0, 0)) + my_source.angle = openmc.stats.Isotropic() + my_source.energy = openmc.stats.Discrete([14e6], [1]) + my_settings.source = my_source + + # making openmc.Model with CSG geometry + csg_model = common_geometry_object.csg_model() + csg_model.materials = my_materials + csg_model.tallies = my_tallies + csg_model.settings = my_settings + + output_file_from_csg = csg_model.run() + + # extracting the tally result from the CSG simulation + with openmc.StatePoint(output_file_from_csg) as sp_from_csg: + csg_result = sp_from_csg.get_tally(name="mat1_flux_tally") + + # making openmc.Model with DAGMC geometry and specifying mesh sizes to get a good representation of a Cuboid + dag_model = common_geometry_object.dagmc_model_with_cad_to_openmc() + dag_model.materials = my_materials + dag_model.tallies = my_tallies + dag_model.settings = my_settings + + output_file_from_cad = dag_model.run() + + # extracting the tally result from the DAGMC simulation + with openmc.StatePoint(output_file_from_cad) as sp_from_cad: + cad_result = sp_from_cad.get_tally(name="mat1_flux_tally") + + assert math.isclose(cad_result.mean, csg_result.mean) + From 1fd7ac0b4966632e2d3d7b4097327d6f05077515 Mon Sep 17 00:00:00 2001 From: Erik B Knudsen Date: Mon, 18 Dec 2023 11:34:31 +0100 Subject: [PATCH 05/12] add sphere test --- .github/workflows/sphere_cad_to_openmc.yml | 29 +++++++++ src/model_benchmark_zoo/sphere.py | 22 +++++++ .../test_cad_to_openmc/test_csg_cad_sphere.py | 61 +++++++++++++++++++ 3 files changed, 112 insertions(+) create mode 100644 .github/workflows/sphere_cad_to_openmc.yml create mode 100644 tests/test_cad_to_openmc/test_csg_cad_sphere.py diff --git a/.github/workflows/sphere_cad_to_openmc.yml b/.github/workflows/sphere_cad_to_openmc.yml new file mode 100644 index 0000000..e717e2a --- /dev/null +++ b/.github/workflows/sphere_cad_to_openmc.yml @@ -0,0 +1,29 @@ +name: sphere - cad to openmc + +on: + pull_request: + branches: + - develop + - main + push: + - main + +jobs: + testing: + runs-on: ubuntu-latest + steps: + + - name: checkout actions + uses: actions/checkout@v4 + + - name: use upstream test composite action + uses: ./.github/actions/dependencies + + - shell: bash + env: + OPENMC_CROSS_SECTIONS: /home/runner/work/model_benchmark_zoo/model_benchmark_zoo/cross_sections.xml + run: | + source "${HOME}/conda/etc/profile.d/conda.sh" + source "${HOME}/conda/etc/profile.d/mamba.sh" + mamba activate + pytest tests/test_cad_to_openmc/test_csg_cad_sphere.py diff --git a/src/model_benchmark_zoo/sphere.py b/src/model_benchmark_zoo/sphere.py index 94faa04..c551c94 100644 --- a/src/model_benchmark_zoo/sphere.py +++ b/src/model_benchmark_zoo/sphere.py @@ -43,3 +43,25 @@ def dagmc_model(self, filename="sphere.h5m", min_mesh_size=0.1, max_mesh_size=10 geometry = openmc.Geometry(universe) model = openmc.Model(geometry=geometry) return model + + def dagmc_model_with_cad_to_openmc(self, filename="sphere.h5m"): + from CAD_to_OpenMC import assembly + import openmc + + self.export_stp_file() + + a=assembly.Assembly(["sphere.step"]) + a.verbose=0 + assembly.mesher_config['threads']=1 + a.run( + backend='stl2', + merge=True, + h5m_filename=filename, + sequential_tags=[self.materials[0].name], + scale=1.0 + ) + + universe = openmc.DAGMCUniverse(filename, auto_geom_ids=True).bounded_universe() + geometry = openmc.Geometry(universe) + model = openmc.Model(geometry=geometry) + return model diff --git a/tests/test_cad_to_openmc/test_csg_cad_sphere.py b/tests/test_cad_to_openmc/test_csg_cad_sphere.py new file mode 100644 index 0000000..2ee110a --- /dev/null +++ b/tests/test_cad_to_openmc/test_csg_cad_sphere.py @@ -0,0 +1,61 @@ +from model_benchmark_zoo import Sphere +import openmc +import math + +def test_compare(): + # single material used in both simulations + mat1 = openmc.Material(name='1') + mat1.add_nuclide('Fe56', 1) + mat1.set_density('g/cm3', 1) + my_materials = openmc.Materials([mat1]) + + # geometry used in both simulations + common_geometry_object = Sphere(materials=my_materials, radius=10) + # just writing a CAD step file for visulisation + common_geometry_object.export_stp_file("sphere.stp") + + mat_filter = openmc.MaterialFilter(mat1) + tally = openmc.Tally(name='mat1_flux_tally') + tally.filters = [mat_filter] + tally.scores = ['flux'] + my_tallies = openmc.Tallies([tally]) + + my_settings = openmc.Settings() + my_settings.batches = 10 + my_settings.inactive = 0 + my_settings.particles = 500 + my_settings.run_mode = 'fixed source' + + # Create a DT point source + my_source = openmc.Source() + my_source.space = openmc.stats.Point((0, 0, 0)) + my_source.angle = openmc.stats.Isotropic() + my_source.energy = openmc.stats.Discrete([14e6], [1]) + my_settings.source = my_source + + # making openmc.Model with CSG geometry + csg_model = common_geometry_object.csg_model() + csg_model.materials = my_materials + csg_model.tallies = my_tallies + csg_model.settings = my_settings + + output_file_from_csg = csg_model.run() + + # extracting the tally result from the CSG simulation + with openmc.StatePoint(output_file_from_csg) as sp_from_csg: + csg_result = sp_from_csg.get_tally(name="mat1_flux_tally") + + # making openmc.Model with DAGMC geometry and specifying mesh sizes to get a good representation of a sphere + dag_model = common_geometry_object.dagmc_model_with_cad_to_openmc() + dag_model.materials = my_materials + dag_model.tallies = my_tallies + dag_model.settings = my_settings + + output_file_from_cad = dag_model.run() + + # extracting the tally result from the DAGMC simulation + with openmc.StatePoint(output_file_from_cad) as sp_from_cad: + cad_result = sp_from_cad.get_tally(name="mat1_flux_tally") + + assert math.isclose(cad_result.mean, csg_result.mean) + From 5aef83f667933c8d5fe682c3f1ff6242f38aae7a Mon Sep 17 00:00:00 2001 From: Erik B Knudsen Date: Mon, 18 Dec 2023 11:50:18 +0100 Subject: [PATCH 06/12] add nested sphere test --- .../workflows/nested_sphere_cad_to_openmc.yml | 29 ++++++++ src/model_benchmark_zoo/nestedsphere.py | 22 ++++++ .../test_csg_cad_nestedsphere.py | 73 +++++++++++++++++++ 3 files changed, 124 insertions(+) create mode 100644 .github/workflows/nested_sphere_cad_to_openmc.yml create mode 100644 tests/test_cad_to_openmc/test_csg_cad_nestedsphere.py diff --git a/.github/workflows/nested_sphere_cad_to_openmc.yml b/.github/workflows/nested_sphere_cad_to_openmc.yml new file mode 100644 index 0000000..6d3fdef --- /dev/null +++ b/.github/workflows/nested_sphere_cad_to_openmc.yml @@ -0,0 +1,29 @@ +name: nested sphere - cad to openmc + +on: + pull_request: + branches: + - develop + - main + push: + - main + +jobs: + testing: + runs-on: ubuntu-latest + steps: + + - name: checkout actions + uses: actions/checkout@v4 + + - name: use upstream test composite action + uses: ./.github/actions/dependencies + + - shell: bash + env: + OPENMC_CROSS_SECTIONS: /home/runner/work/model_benchmark_zoo/model_benchmark_zoo/cross_sections.xml + run: | + source "${HOME}/conda/etc/profile.d/conda.sh" + source "${HOME}/conda/etc/profile.d/mamba.sh" + mamba activate + pytest tests/test_cad_to_openmc/test_csg_cad_nestedsphere.py diff --git a/src/model_benchmark_zoo/nestedsphere.py b/src/model_benchmark_zoo/nestedsphere.py index 6e385c1..468f692 100644 --- a/src/model_benchmark_zoo/nestedsphere.py +++ b/src/model_benchmark_zoo/nestedsphere.py @@ -50,3 +50,25 @@ def dagmc_model(self, filename="nestedshpere.h5m", min_mesh_size=0.1, max_mesh_s geometry = openmc.Geometry(universe) model = openmc.Model(geometry=geometry) return model + + def dagmc_model_with_cad_to_openmc(self, filename="nestedsphere.h5m"): + from CAD_to_OpenMC import assembly + import openmc + + self.export_stp_file() + + a=assembly.Assembly(["sphere.step"]) + a.verbose=2 + assembly.mesher_config['threads']=1 + a.run( + backend='stl2', + merge=True, + h5m_filename=filename, + sequential_tags=[self.materials[0].name, self.materials[1].name], + scale=1.0 + ) + + universe = openmc.DAGMCUniverse(filename, auto_geom_ids=True).bounded_universe() + geometry = openmc.Geometry(universe) + model = openmc.Model(geometry=geometry) + return model diff --git a/tests/test_cad_to_openmc/test_csg_cad_nestedsphere.py b/tests/test_cad_to_openmc/test_csg_cad_nestedsphere.py new file mode 100644 index 0000000..acb9c1e --- /dev/null +++ b/tests/test_cad_to_openmc/test_csg_cad_nestedsphere.py @@ -0,0 +1,73 @@ +from model_benchmark_zoo import NestedSphere +import openmc +import math + +def test_compare(): + # single material used in both simulations + mat1 = openmc.Material(name='1') + mat1.add_nuclide('Fe56', 1) + mat1.set_density('g/cm3', 1) + + mat2 = openmc.Material(name='2') + mat2.add_nuclide('Be9', 1) + mat2.set_density('g/cm3', 1) + my_materials = openmc.Materials([mat1, mat2]) + + # geometry used in both simulations + common_geometry_object = NestedSphere(materials=my_materials, radius1=10, radius2=1) + # just writing a CAD step file for visulisation + common_geometry_object.export_stp_file("nestedsphere.stp") + + mat1_filter = openmc.MaterialFilter(mat1) + tally1 = openmc.Tally(name='mat1_flux_tally') + tally1.filters = [mat1_filter] + tally1.scores = ['flux'] + + mat2_filter = openmc.MaterialFilter(mat2) + tally2 = openmc.Tally(name='mat2_flux_tally') + tally2.filters = [mat2_filter] + tally2.scores = ['flux'] + + my_tallies = openmc.Tallies([tally1, tally2]) + + my_settings = openmc.Settings() + my_settings.batches = 10 + my_settings.inactive = 0 + my_settings.particles = 500 + my_settings.run_mode = 'fixed source' + + # Create a DT point source + my_source = openmc.Source() + my_source.space = openmc.stats.Point((0, 0, 0)) + my_source.angle = openmc.stats.Isotropic() + my_source.energy = openmc.stats.Discrete([14e6], [1]) + my_settings.source = my_source + + # making openmc.Model with CSG geometry + csg_model = common_geometry_object.csg_model() + csg_model.materials = my_materials + csg_model.tallies = my_tallies + csg_model.settings = my_settings + + output_file_from_csg = csg_model.run() + + # extracting the tally result from the CSG simulation + with openmc.StatePoint(output_file_from_csg) as sp_from_csg: + csg_result_mat_1 = sp_from_csg.get_tally(name="mat1_flux_tally") + csg_result_mat_2 = sp_from_csg.get_tally(name="mat2_flux_tally") + + # making openmc.Model with DAGMC geometry and specifying mesh sizes to get a good representation of a sphere + dag_model = common_geometry_object.dagmc_model_with_cad_to_openmc() + dag_model.materials = my_materials + dag_model.tallies = my_tallies + dag_model.settings = my_settings + + output_file_from_cad = dag_model.run() + + # extracting the tally result from the DAGMC simulation + with openmc.StatePoint(output_file_from_cad) as sp_from_cad: + cad_result_mat_1 = sp_from_cad.get_tally(name="mat1_flux_tally") + cad_result_mat_2 = sp_from_cad.get_tally(name="mat2_flux_tally") + + assert math.isclose(cad_result_mat_1.mean, csg_result_mat_1.mean) + assert math.isclose(cad_result_mat_2.mean, csg_result_mat_2.mean) From 479cc8438e7888aae60935baa48e42c9316be5ce Mon Sep 17 00:00:00 2001 From: Erik B Knudsen Date: Mon, 18 Dec 2023 12:01:42 +0100 Subject: [PATCH 07/12] circ toroid test --- .../circular_torus_cad_to_openmc.yml | 29 +++++++++ src/model_benchmark_zoo/circulartorus.py | 22 +++++++ .../test_csg_cad_circulartorus.py | 65 +++++++++++++++++++ 3 files changed, 116 insertions(+) create mode 100644 .github/workflows/circular_torus_cad_to_openmc.yml create mode 100644 tests/test_cad_to_openmc/test_csg_cad_circulartorus.py diff --git a/.github/workflows/circular_torus_cad_to_openmc.yml b/.github/workflows/circular_torus_cad_to_openmc.yml new file mode 100644 index 0000000..7287185 --- /dev/null +++ b/.github/workflows/circular_torus_cad_to_openmc.yml @@ -0,0 +1,29 @@ +name: circular torus - cad to openmc + +on: + pull_request: + branches: + - develop + - main + push: + - main + +jobs: + testing: + runs-on: ubuntu-latest + steps: + + - name: checkout actions + uses: actions/checkout@v4 + + - name: use upstream test composite action + uses: ./.github/actions/dependencies + + - shell: bash + env: + OPENMC_CROSS_SECTIONS: /home/runner/work/model_benchmark_zoo/model_benchmark_zoo/cross_sections.xml + run: | + source "${HOME}/conda/etc/profile.d/conda.sh" + source "${HOME}/conda/etc/profile.d/mamba.sh" + mamba activate + pytest tests/test_cad_to_openmc/test_csg_cad_circulartorus.py diff --git a/src/model_benchmark_zoo/circulartorus.py b/src/model_benchmark_zoo/circulartorus.py index bba6094..ba3fa27 100644 --- a/src/model_benchmark_zoo/circulartorus.py +++ b/src/model_benchmark_zoo/circulartorus.py @@ -45,3 +45,25 @@ def dagmc_model(self, filename="circulartorus.h5m", min_mesh_size=0.1, max_mesh_ model = openmc.Model(geometry=geometry) return model + + def dagmc_model_with_cad_to_openmc(self, filename="circulartorus.h5m"): + from CAD_to_OpenMC import assembly + import openmc + + self.export_stp_file() + + a=assembly.Assembly(["circulartorus.step"]) + a.verbose=1 + assembly.mesher_config['threads']=1 + a.run( + backend='stl2', + merge=True, + h5m_filename=filename, + sequential_tags=[self.materials[0].name, self.materials[1].name], + scale=1.0 + ) + + universe = openmc.DAGMCUniverse(filename, auto_geom_ids=True).bounded_universe() + geometry = openmc.Geometry(universe) + model = openmc.Model(geometry=geometry) + return model diff --git a/tests/test_cad_to_openmc/test_csg_cad_circulartorus.py b/tests/test_cad_to_openmc/test_csg_cad_circulartorus.py new file mode 100644 index 0000000..294a2b8 --- /dev/null +++ b/tests/test_cad_to_openmc/test_csg_cad_circulartorus.py @@ -0,0 +1,65 @@ +from model_benchmark_zoo import Circulartorus +import openmc +import math +import numpy as np +def test_compare(): + # single material used in both simulations + mat1 = openmc.Material(name='1') + mat1.add_nuclide('Fe56', 1) + mat1.set_density('g/cm3', 1) + my_materials = openmc.Materials([mat1]) + + # geometry used in both simulations + major_radius = 10 + minor_radius = 4 + common_geometry_object = Circulartorus(materials=my_materials, major_radius=major_radius, minor_radius=minor_radius) + # just writing a CAD step file for visulisation + common_geometry_object.export_stp_file("circulartorus.stp") + + mat_filter = openmc.MaterialFilter(mat1) + tally = openmc.Tally(name='mat1_flux_tally') + tally.filters = [mat_filter] + tally.scores = ['flux'] + my_tallies = openmc.Tallies([tally]) + + my_settings = openmc.Settings() + my_settings.batches = 10 + my_settings.inactive = 0 + my_settings.particles = 500 + my_settings.run_mode = 'fixed source' + + # Create a DT point source + my_source = openmc.Source() + r = openmc.stats.Discrete([major_radius], [1]) + phi = openmc.stats.Uniform(0, 2*np.pi) + z = openmc.stats.Discrete([0], [1]) + my_source.space = openmc.stats.CylindricalIndependent(r, phi, z) + my_source.energy = openmc.stats.Discrete([14e6], [1]) + my_settings.source = my_source + + # making openmc.Model with CSG geometry + csg_model = common_geometry_object.csg_model() + csg_model.materials = my_materials + csg_model.tallies = my_tallies + csg_model.settings = my_settings + + output_file_from_csg = csg_model.run() + + # extracting the tally result from the CSG simulation + with openmc.StatePoint(output_file_from_csg) as sp_from_csg: + csg_result = sp_from_csg.get_tally(name="mat1_flux_tally") + + # making openmc.Model with DAGMC geometry and specifying mesh sizes to get a good representation of a circular torus + dag_model = common_geometry_object.dagmc_model_with_cad_to_openmc() + dag_model.materials = my_materials + dag_model.tallies = my_tallies + dag_model.settings = my_settings + + output_file_from_cad = dag_model.run() + + # extracting the tally result from the DAGMC simulation + with openmc.StatePoint(output_file_from_cad) as sp_from_cad: + cad_result = sp_from_cad.get_tally(name="mat1_flux_tally") + + assert math.isclose(cad_result.mean, csg_result.mean) + From 1ea26e4051bc2acbb4d16b0c20aaf843e3034368 Mon Sep 17 00:00:00 2001 From: Erik B Knudsen Date: Mon, 18 Dec 2023 12:05:13 +0100 Subject: [PATCH 08/12] add elliptical torus --- .../elliptical_torus_cad_to_openmc.yml | 29 ++++++++ src/model_benchmark_zoo/ellipticaltorus.py | 63 ++++++++++++++++++ .../test_csg_cad_ellipticaltorus.py | 66 +++++++++++++++++++ 3 files changed, 158 insertions(+) create mode 100644 .github/workflows/elliptical_torus_cad_to_openmc.yml create mode 100644 tests/test_cad_to_openmc/test_csg_cad_ellipticaltorus.py diff --git a/.github/workflows/elliptical_torus_cad_to_openmc.yml b/.github/workflows/elliptical_torus_cad_to_openmc.yml new file mode 100644 index 0000000..65c4095 --- /dev/null +++ b/.github/workflows/elliptical_torus_cad_to_openmc.yml @@ -0,0 +1,29 @@ +name: elliptical torus - cad to openmc + +on: + pull_request: + branches: + - develop + - main + push: + - main + +jobs: + testing: + runs-on: ubuntu-latest + steps: + + - name: checkout actions + uses: actions/checkout@v4 + + - name: use upstream test composite action + uses: ./.github/actions/dependencies + + - shell: bash + env: + OPENMC_CROSS_SECTIONS: /home/runner/work/model_benchmark_zoo/model_benchmark_zoo/cross_sections.xml + run: | + source "${HOME}/conda/etc/profile.d/conda.sh" + source "${HOME}/conda/etc/profile.d/mamba.sh" + mamba activate + pytest tests/test_cad_to_openmc/test_csg_cad_ellipticaltorus.py diff --git a/src/model_benchmark_zoo/ellipticaltorus.py b/src/model_benchmark_zoo/ellipticaltorus.py index c241a5a..cfd510c 100644 --- a/src/model_benchmark_zoo/ellipticaltorus.py +++ b/src/model_benchmark_zoo/ellipticaltorus.py @@ -51,3 +51,66 @@ def dagmc_model(self, filename="ellipticaltorus.h5m", min_mesh_size=0.1, max_mes model = openmc.Model(geometry=geometry) return model + def dagmc_model_with_cad_to_openmc(self, filename="ellipticaltorus.h5m"): + from CAD_to_OpenMC import assembly + import openmc + + self.export_stp_file() + + a=assembly.Assembly(["ellipticaltorus.step"]) + a.verbose=2 + assembly.mesher_config['threads']=1 + a.run( + backend='stl2', + merge=True, + h5m_filename=filename, + sequential_tags=[self.materials[0].name, self.materials[1].name], + scale=1.0 + ) + + universe = openmc.DAGMCUniverse(filename, auto_geom_ids=True).bounded_universe() + geometry = openmc.Geometry(universe) + model = openmc.Model(geometry=geometry) + return model + def dagmc_model_with_cad_to_openmc(self, filename="ellipticaltorus.h5m"): + from CAD_to_OpenMC import assembly + import openmc + + self.export_stp_file() + + a=assembly.Assembly(["ellipticaltorus.step"]) + a.verbose=2 + assembly.mesher_config['threads']=1 + a.run( + backend='stl2', + merge=True, + h5m_filename=filename, + sequential_tags=[self.materials[0].name, self.materials[1].name], + scale=1.0 + ) + + universe = openmc.DAGMCUniverse(filename, auto_geom_ids=True).bounded_universe() + geometry = openmc.Geometry(universe) + model = openmc.Model(geometry=geometry) + return model + def dagmc_model_with_cad_to_openmc(self, filename="ellipticaltorus.h5m"): + from CAD_to_OpenMC import assembly + import openmc + + self.export_stp_file() + + a=assembly.Assembly(["ellipticaltorus.step"]) + a.verbose=2 + assembly.mesher_config['threads']=1 + a.run( + backend='stl2', + merge=True, + h5m_filename=filename, + sequential_tags=[self.materials[0].name, self.materials[1].name], + scale=1.0 + ) + + universe = openmc.DAGMCUniverse(filename, auto_geom_ids=True).bounded_universe() + geometry = openmc.Geometry(universe) + model = openmc.Model(geometry=geometry) + return model diff --git a/tests/test_cad_to_openmc/test_csg_cad_ellipticaltorus.py b/tests/test_cad_to_openmc/test_csg_cad_ellipticaltorus.py new file mode 100644 index 0000000..d96ee7e --- /dev/null +++ b/tests/test_cad_to_openmc/test_csg_cad_ellipticaltorus.py @@ -0,0 +1,66 @@ +from model_benchmark_zoo import Ellipticaltorus +import openmc +import math +import numpy as np + +def test_compare(): + # single material used in both simulations + mat1 = openmc.Material(name='1') + mat1.add_nuclide('Fe56', 1) + mat1.set_density('g/cm3', 1) + my_materials = openmc.Materials([mat1]) + + # geometry used in both simulations + major_radius = 10 + minor_radius1 = 4 + minor_radius2 = 2 + common_geometry_object = Ellipticaltorus(materials = my_materials, major_radius=major_radius, minor_radius1=minor_radius1, minor_radius2 = minor_radius2) + # just writing a CAD step file for visulisation + common_geometry_object.export_stp_file("ellipticaltorus.stp") + + mat_filter = openmc.MaterialFilter(mat1) + tally = openmc.Tally(name='mat1_flux_tally') + tally.filters = [mat_filter] + tally.scores = ['flux'] + my_tallies = openmc.Tallies([tally]) + + my_settings = openmc.Settings() + my_settings.batches = 10 + my_settings.inactive = 0 + my_settings.particles = 500 + my_settings.run_mode = 'fixed source' + + # Create a DT point source + my_source = openmc.Source() + r = openmc.stats.Discrete([major_radius], [1]) + phi = openmc.stats.Uniform(0, 2*np.pi) + z = openmc.stats.Discrete([0], [1]) + my_source.space = openmc.stats.CylindricalIndependent(r, phi, z) + my_source.energy = openmc.stats.Discrete([14e6], [1]) + my_settings.source = my_source + + # making openmc.Model with CSG geometry + csg_model = common_geometry_object.csg_model() + csg_model.materials = my_materials + csg_model.tallies = my_tallies + csg_model.settings = my_settings + + output_file_from_csg = csg_model.run() + + # extracting the tally result from the CSG simulation + with openmc.StatePoint(output_file_from_csg) as sp_from_csg: + csg_result = sp_from_csg.get_tally(name="mat1_flux_tally") + + # making openmc.Model with DAGMC geometry and specifying mesh sizes to get a good representation of a Ellipticaltorus + dag_model = common_geometry_object.dagmc_model_with_cad_to_openmc() + dag_model.materials = my_materials + dag_model.tallies = my_tallies + dag_model.settings = my_settings + + output_file_from_cad = dag_model.run() + + # extracting the tally result from the DAGMC simulation + with openmc.StatePoint(output_file_from_cad) as sp_from_cad: + cad_result = sp_from_cad.get_tally(name="mat1_flux_tally") + + assert math.isclose(cad_result.mean, csg_result.mean) \ No newline at end of file From 1bba9408eefd0c9330ce6a17214cd0230b2ce782 Mon Sep 17 00:00:00 2001 From: Erik B Knudsen Date: Mon, 18 Dec 2023 12:09:27 +0100 Subject: [PATCH 09/12] add a nested cylinder test --- .../nested_cylinder_cad_to_openmc.yml | 29 ++++++++ src/model_benchmark_zoo/nestedcylinder.py | 22 ++++++ .../test_csg_cad_nestedcylinder.py | 73 +++++++++++++++++++ 3 files changed, 124 insertions(+) create mode 100644 .github/workflows/nested_cylinder_cad_to_openmc.yml create mode 100644 tests/test_cad_to_openmc/test_csg_cad_nestedcylinder.py diff --git a/.github/workflows/nested_cylinder_cad_to_openmc.yml b/.github/workflows/nested_cylinder_cad_to_openmc.yml new file mode 100644 index 0000000..8575bc4 --- /dev/null +++ b/.github/workflows/nested_cylinder_cad_to_openmc.yml @@ -0,0 +1,29 @@ +name: nested cylinder - cad to openmc + +on: + pull_request: + branches: + - develop + - main + push: + - main + +jobs: + testing: + runs-on: ubuntu-latest + steps: + + - name: checkout actions + uses: actions/checkout@v4 + + - name: use upstream test composite action + uses: ./.github/actions/dependencies + + - shell: bash + env: + OPENMC_CROSS_SECTIONS: /home/runner/work/model_benchmark_zoo/model_benchmark_zoo/cross_sections.xml + run: | + source "${HOME}/conda/etc/profile.d/conda.sh" + source "${HOME}/conda/etc/profile.d/mamba.sh" + mamba activate + pytest tests/test_cad_to_openmc/test_csg_cad_nestedcylinder.py diff --git a/src/model_benchmark_zoo/nestedcylinder.py b/src/model_benchmark_zoo/nestedcylinder.py index 2ee1978..1f17d5f 100644 --- a/src/model_benchmark_zoo/nestedcylinder.py +++ b/src/model_benchmark_zoo/nestedcylinder.py @@ -64,3 +64,25 @@ def dagmc_model(self, filename="nestedshpere.h5m", min_mesh_size=0.1, max_mesh_s geometry = openmc.Geometry(universe) model = openmc.Model(geometry=geometry) return model + + def dagmc_model_with_cad_to_openmc(self, filename="nestedcylinder.h5m"): + from CAD_to_OpenMC import assembly + import openmc + + self.export_stp_file() + + a=assembly.Assembly(["nestedcylinder.step"]) + a.verbose=2 + assembly.mesher_config['threads']=1 + a.run( + backend='stl2', + merge=True, + h5m_filename=filename, + sequential_tags=[self.materials[0].name, self.materials[1].name], + scale=1.0 + ) + + universe = openmc.DAGMCUniverse(filename, auto_geom_ids=True).bounded_universe() + geometry = openmc.Geometry(universe) + model = openmc.Model(geometry=geometry) + return model diff --git a/tests/test_cad_to_openmc/test_csg_cad_nestedcylinder.py b/tests/test_cad_to_openmc/test_csg_cad_nestedcylinder.py new file mode 100644 index 0000000..c0f74ab --- /dev/null +++ b/tests/test_cad_to_openmc/test_csg_cad_nestedcylinder.py @@ -0,0 +1,73 @@ +from model_benchmark_zoo import NestedCylinder +import openmc +import math + +def test_compare(): + # single material used in both simulations + mat1 = openmc.Material(name='1') + mat1.add_nuclide('Fe56', 1) + mat1.set_density('g/cm3', 1) + + mat2 = openmc.Material(name='2') + mat2.add_nuclide('Be9', 1) + mat2.set_density('g/cm3', 1) + my_materials = openmc.Materials([mat1, mat2]) + + # geometry used in both simulations + common_geometry_object = NestedCylinder(materials=my_materials) #default size + # just writing a CAD step file for visulisation + common_geometry_object.export_stp_file("nestedcylinders.stp") + + mat1_filter = openmc.MaterialFilter(mat1) + tally1 = openmc.Tally(name='mat1_flux_tally') + tally1.filters = [mat1_filter] + tally1.scores = ['flux'] + + mat2_filter = openmc.MaterialFilter(mat2) + tally2 = openmc.Tally(name='mat2_flux_tally') + tally2.filters = [mat2_filter] + tally2.scores = ['flux'] + + my_tallies = openmc.Tallies([tally1, tally2]) + + my_settings = openmc.Settings() + my_settings.batches = 10 + my_settings.inactive = 0 + my_settings.particles = 500 + my_settings.run_mode = 'fixed source' + + # Create a DT point source + my_source = openmc.Source() + my_source.space = openmc.stats.Point((0, 0, 0)) + my_source.angle = openmc.stats.Isotropic() + my_source.energy = openmc.stats.Discrete([14e6], [1]) + my_settings.source = my_source + + # making openmc.Model with CSG geometry + csg_model = common_geometry_object.csg_model() + csg_model.materials = my_materials + csg_model.tallies = my_tallies + csg_model.settings = my_settings + + output_file_from_csg = csg_model.run() + + # extracting the tally result from the CSG simulation + with openmc.StatePoint(output_file_from_csg) as sp_from_csg: + csg_result_mat_1 = sp_from_csg.get_tally(name="mat1_flux_tally") + csg_result_mat_2 = sp_from_csg.get_tally(name="mat2_flux_tally") + + # making openmc.Model with DAGMC geometry and specifying mesh sizes to get a good representation of a sphere + dag_model = common_geometry_object.dagmc_model_with_cad_to_openmc() + dag_model.materials = my_materials + dag_model.tallies = my_tallies + dag_model.settings = my_settings + + output_file_from_cad = dag_model.run() + + # extracting the tally result from the DAGMC simulation + with openmc.StatePoint(output_file_from_cad) as sp_from_cad: + cad_result_mat_1 = sp_from_cad.get_tally(name="mat1_flux_tally") + cad_result_mat_2 = sp_from_cad.get_tally(name="mat2_flux_tally") + + assert math.isclose(cad_result_mat_1.mean, csg_result_mat_1.mean) + assert math.isclose(cad_result_mat_2.mean, csg_result_mat_2.mean) From f3628ab5f3cbe1ad31e5b9452ee2ac7f156ae077 Mon Sep 17 00:00:00 2001 From: Erik B Knudsen Date: Mon, 18 Dec 2023 12:11:39 +0100 Subject: [PATCH 10/12] remove accidentally added multiple functions --- src/model_benchmark_zoo/ellipticaltorus.py | 41 ---------------------- 1 file changed, 41 deletions(-) diff --git a/src/model_benchmark_zoo/ellipticaltorus.py b/src/model_benchmark_zoo/ellipticaltorus.py index cfd510c..fafa697 100644 --- a/src/model_benchmark_zoo/ellipticaltorus.py +++ b/src/model_benchmark_zoo/ellipticaltorus.py @@ -51,48 +51,7 @@ def dagmc_model(self, filename="ellipticaltorus.h5m", min_mesh_size=0.1, max_mes model = openmc.Model(geometry=geometry) return model - def dagmc_model_with_cad_to_openmc(self, filename="ellipticaltorus.h5m"): - from CAD_to_OpenMC import assembly - import openmc - self.export_stp_file() - - a=assembly.Assembly(["ellipticaltorus.step"]) - a.verbose=2 - assembly.mesher_config['threads']=1 - a.run( - backend='stl2', - merge=True, - h5m_filename=filename, - sequential_tags=[self.materials[0].name, self.materials[1].name], - scale=1.0 - ) - - universe = openmc.DAGMCUniverse(filename, auto_geom_ids=True).bounded_universe() - geometry = openmc.Geometry(universe) - model = openmc.Model(geometry=geometry) - return model - def dagmc_model_with_cad_to_openmc(self, filename="ellipticaltorus.h5m"): - from CAD_to_OpenMC import assembly - import openmc - - self.export_stp_file() - - a=assembly.Assembly(["ellipticaltorus.step"]) - a.verbose=2 - assembly.mesher_config['threads']=1 - a.run( - backend='stl2', - merge=True, - h5m_filename=filename, - sequential_tags=[self.materials[0].name, self.materials[1].name], - scale=1.0 - ) - - universe = openmc.DAGMCUniverse(filename, auto_geom_ids=True).bounded_universe() - geometry = openmc.Geometry(universe) - model = openmc.Model(geometry=geometry) - return model def dagmc_model_with_cad_to_openmc(self, filename="ellipticaltorus.h5m"): from CAD_to_OpenMC import assembly import openmc From 9b1b246cead530ab534cbe920e2523b098b8289c Mon Sep 17 00:00:00 2001 From: Erik B Knudsen Date: Mon, 18 Dec 2023 13:28:08 +0100 Subject: [PATCH 11/12] only uses 1 material --- src/model_benchmark_zoo/circulartorus.py | 2 +- src/model_benchmark_zoo/ellipticaltorus.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/model_benchmark_zoo/circulartorus.py b/src/model_benchmark_zoo/circulartorus.py index ba3fa27..72068ec 100644 --- a/src/model_benchmark_zoo/circulartorus.py +++ b/src/model_benchmark_zoo/circulartorus.py @@ -59,7 +59,7 @@ def dagmc_model_with_cad_to_openmc(self, filename="circulartorus.h5m"): backend='stl2', merge=True, h5m_filename=filename, - sequential_tags=[self.materials[0].name, self.materials[1].name], + sequential_tags=[self.materials[0].name], scale=1.0 ) diff --git a/src/model_benchmark_zoo/ellipticaltorus.py b/src/model_benchmark_zoo/ellipticaltorus.py index fafa697..dd0a306 100644 --- a/src/model_benchmark_zoo/ellipticaltorus.py +++ b/src/model_benchmark_zoo/ellipticaltorus.py @@ -65,7 +65,7 @@ def dagmc_model_with_cad_to_openmc(self, filename="ellipticaltorus.h5m"): backend='stl2', merge=True, h5m_filename=filename, - sequential_tags=[self.materials[0].name, self.materials[1].name], + sequential_tags=[self.materials[0].name], scale=1.0 ) From 86fa413419d91d64176615f99e48e7ed453c5ca4 Mon Sep 17 00:00:00 2001 From: Erik B Knudsen Date: Mon, 18 Dec 2023 13:28:34 +0100 Subject: [PATCH 12/12] use correct file name --- src/model_benchmark_zoo/nestedcylinder.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/model_benchmark_zoo/nestedcylinder.py b/src/model_benchmark_zoo/nestedcylinder.py index 1f17d5f..4a8fbf5 100644 --- a/src/model_benchmark_zoo/nestedcylinder.py +++ b/src/model_benchmark_zoo/nestedcylinder.py @@ -69,7 +69,7 @@ def dagmc_model_with_cad_to_openmc(self, filename="nestedcylinder.h5m"): from CAD_to_OpenMC import assembly import openmc - self.export_stp_file() + self.export_stp_file("nestedcylinder.step") a=assembly.Assembly(["nestedcylinder.step"]) a.verbose=2