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/.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/.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 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/.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/.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/.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/circulartorus.py b/src/model_benchmark_zoo/circulartorus.py index e3713e7..c094404 100644 --- a/src/model_benchmark_zoo/circulartorus.py +++ b/src/model_benchmark_zoo/circulartorus.py @@ -47,3 +47,25 @@ def dagmc_model(self, filename="circulartorus.h5m", min_mesh_size=0.1, max_mesh_ model = openmc.Model(geometry=geometry, materials=materials) 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], + 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/src/model_benchmark_zoo/cuboid.py b/src/model_benchmark_zoo/cuboid.py index 3728f47..8a291a0 100644 --- a/src/model_benchmark_zoo/cuboid.py +++ b/src/model_benchmark_zoo/cuboid.py @@ -52,3 +52,25 @@ def dagmc_model(self, filename="Cuboid.h5m", min_mesh_size=0.1, max_mesh_size=10 materials = openmc.Materials([self.materials[0]]) model = openmc.Model(geometry=geometry, materials=materials) 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/src/model_benchmark_zoo/cylinder.py b/src/model_benchmark_zoo/cylinder.py index 5e32bdd..df01703 100644 --- a/src/model_benchmark_zoo/cylinder.py +++ b/src/model_benchmark_zoo/cylinder.py @@ -48,3 +48,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, materials=materials) 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 diff --git a/src/model_benchmark_zoo/ellipticaltorus.py b/src/model_benchmark_zoo/ellipticaltorus.py index cd9b616..60018ba 100644 --- a/src/model_benchmark_zoo/ellipticaltorus.py +++ b/src/model_benchmark_zoo/ellipticaltorus.py @@ -53,3 +53,25 @@ def dagmc_model(self, filename="ellipticaltorus.h5m", min_mesh_size=0.1, max_mes model = openmc.Model(geometry=geometry, materials=materials) 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], + 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/src/model_benchmark_zoo/nestedcylinder.py b/src/model_benchmark_zoo/nestedcylinder.py index 7aa5abc..965928b 100644 --- a/src/model_benchmark_zoo/nestedcylinder.py +++ b/src/model_benchmark_zoo/nestedcylinder.py @@ -66,3 +66,25 @@ def dagmc_model(self, filename="nestedshpere.h5m", min_mesh_size=0.1, max_mesh_s materials = openmc.Materials([self.materials[0], self.materials[1]]) model = openmc.Model(geometry=geometry, materials=materials) 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("nestedcylinder.step") + + 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/src/model_benchmark_zoo/nestedsphere.py b/src/model_benchmark_zoo/nestedsphere.py index 282045c..128a65f 100644 --- a/src/model_benchmark_zoo/nestedsphere.py +++ b/src/model_benchmark_zoo/nestedsphere.py @@ -52,3 +52,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, materials=materials) 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/src/model_benchmark_zoo/sphere.py b/src/model_benchmark_zoo/sphere.py index 8925cb6..8d0f8d2 100644 --- a/src/model_benchmark_zoo/sphere.py +++ b/src/model_benchmark_zoo/sphere.py @@ -45,3 +45,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, materials=materials) 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_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) + 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) + 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) + 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 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) 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) 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) +