Skip to content

Commit

Permalink
added ci for toko
Browse files Browse the repository at this point in the history
  • Loading branch information
shimwell committed Jan 2, 2024
1 parent 83cc16d commit b414fb0
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 5 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/simple_tokamak_cad_to_dagmc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: two touching cuboids - cad to dagmc

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_simple_tokamak.py
2 changes: 0 additions & 2 deletions examples/compare_csg_cad_simpletokamak.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@

# 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

Expand All @@ -63,7 +62,6 @@

# 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=1., max_mesh_size=50.)
dag_model.materials = my_materials
dag_model.tallies = my_tallies
dag_model.settings = my_settings

Expand Down
7 changes: 4 additions & 3 deletions src/model_benchmark_zoo/simpletokamak.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ def csg_model(self):
cell3.fill = self.materials[1]

geometry = openmc.Geometry([cell1, cell2, cell3])
model = openmc.Model(geometry=geometry)
materials = openmc.Materials([self.materials[0], self.materials[1]])
model = openmc.Model(geometry=geometry, materials=materials)
return model

def cadquery_assembly(self):
Expand Down Expand Up @@ -57,9 +58,9 @@ def dagmc_model(self, filename="simpletokamak.h5m", min_mesh_size=10, max_mesh_s
filename=filename,
min_mesh_size=min_mesh_size,
max_mesh_size=max_mesh_size,
msh_filename='nestedshpere.msh' # this arg allows the gmsh file to be written out
)
universe = openmc.DAGMCUniverse(filename).bounded_universe()
geometry = openmc.Geometry(universe)
model = openmc.Model(geometry=geometry)
materials = openmc.Materials([self.materials[0], self.materials[1]])
model = openmc.Model(geometry=geometry, materials=materials)
return model
71 changes: 71 additions & 0 deletions tests/test_cad_to_dagmc/test_csg_cad_simple_tokamak.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
from model_benchmark_zoo import SimpleTokamak
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 = SimpleTokamak(materials=my_materials, radius1=10, radius2=1)
# just writing a CAD step file for visulisation
common_geometry_object.export_stp_file("SimpleTokamak.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.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(min_mesh_size=0.01, max_mesh_size=0.5)
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)

0 comments on commit b414fb0

Please sign in to comment.