-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from fusion-energy/adding_ci
added ci and tests
- Loading branch information
Showing
5 changed files
with
299 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
name: CI with install | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- develop | ||
- main | ||
|
||
jobs: | ||
testing: | ||
runs-on: ubuntu-latest | ||
container: | ||
image: docker pull continuumio/miniconda3 | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: install dependencies | ||
run: | | ||
conda install -c conda-forge mamba | ||
mamba install -c cadquery -c conda-forge moab gmsh python-gmsh cadquery=master -y | ||
- name: install package with tests | ||
run: | | ||
pip install . | ||
- name: Run tests | ||
run: | | ||
pytest tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(min_mesh_size=0.01, max_mesh_size=0.5) | ||
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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(min_mesh_size=0.01, max_mesh_size=0.5) | ||
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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
from model_benchmark_zoo import SphericalShell | ||
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 = SphericalShell(materials=my_materials, radius1=10, radius2=1) | ||
# just writing a CAD step file for visulisation | ||
common_geometry_object.export_stp_file("sphericalshell.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") | ||
csg_result_mat_1_str = f'CSG tally mean {csg_result_mat_1.mean} std dev {csg_result_mat_1.std_dev}' | ||
csg_result_mat_2_str = f'CSG tally mean {csg_result_mat_1.mean} std dev {csg_result_mat_1.std_dev}' | ||
|
||
# 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(min_mesh_size=0.01, max_mesh_size=0.5) | ||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
from model_benchmark_zoo import TwoTouchingCuboids | ||
import openmc | ||
import math | ||
|
||
def test_compare(): | ||
# materials 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('Fe56', 1) | ||
mat2.set_density('g/cm3', 1) | ||
my_materials = openmc.Materials([mat1, mat2]) | ||
|
||
# geometry used in both simulations | ||
common_geometry_object = TwoTouchingCuboids( | ||
materials=my_materials, width1=10, width2=4) | ||
# just writing a CAD step file for visulisation | ||
common_geometry_object.export_stp_file("TwoTouchingCuboids.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_result1 = sp_from_csg.get_tally(name="mat1_flux_tally") | ||
csg_result2 = 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 TwoTouchingCuboids | ||
dag_model = common_geometry_object.dagmc_model(min_mesh_size=0.01, max_mesh_size=0.5) | ||
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_result1 = sp_from_cad.get_tally(name="mat1_flux_tally") | ||
cad_result2 = sp_from_cad.get_tally(name="mat2_flux_tally") | ||
|
||
assert math.isclose(cad_result1.mean, csg_result1.mean) | ||
assert math.isclose(cad_result2.mean, csg_result2.mean) |