-
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 #36 from fusion-energy/adding_toka_2
Adding a simple tokamak model
- Loading branch information
Showing
10 changed files
with
383 additions
and
3 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: simple tokamak - cad to dagmc | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- develop | ||
- main | ||
push: | ||
branches: | ||
- 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_cad_to_dagmc | ||
|
||
- 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 |
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: simple tokamak - cad to openmc | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- develop | ||
- main | ||
push: | ||
branches: | ||
- 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_cad_to_openmc | ||
|
||
- 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_simple_tokamak.py |
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
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
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,96 @@ | ||
from model_benchmark_zoo import SimpleTokamak | ||
import openmc | ||
import math | ||
|
||
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) | ||
|
||
# geometry used in both simulations | ||
common_geometry_object = SimpleTokamak( | ||
radius=500, | ||
blanket_thicknesses=100, | ||
center_column_thicknesses=150, | ||
center_column_extent_beyond_blanket=20, | ||
) | ||
# 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 ring source | ||
my_source = openmc.IndependentSource() | ||
source_r = common_geometry_object.center_column_thicknesses + (common_geometry_object.radius-common_geometry_object.center_column_thicknesses) /2 | ||
r = openmc.stats.Discrete([source_r], [1]) | ||
phi = openmc.stats.Uniform(0, 2*math.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(materials=[mat1, mat2]) | ||
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_2.mean} std dev {csg_result_mat_2.std_dev}' | ||
|
||
common_geometry_object.export_h5m_file_with_cad_to_dagmc( | ||
h5m_filename='simpletokamak.h5m', | ||
material_tags=['1', '2'], | ||
# the small mesh sizes make a large detailed mesh which is needed to get similar answers | ||
min_mesh_size=0.01, | ||
max_mesh_size=0.5 | ||
) | ||
# 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( | ||
h5m_filename='simpletokamak.h5m', materials=[mat1, mat2]) | ||
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") | ||
|
||
cad_result_mat_1_str = f'CAD tally mean {cad_result_mat_1.mean} std dev {cad_result_mat_1.std_dev}' | ||
cad_result_mat_2_str = f'CAD tally mean {cad_result_mat_2.mean} std dev {cad_result_mat_2.std_dev}' | ||
|
||
# printing both tally results | ||
print(csg_result_mat_1_str) | ||
print(cad_result_mat_1_str) | ||
print(csg_result_mat_2_str) | ||
print(cad_result_mat_2_str) | ||
|
||
assert math.isclose(cad_result_mat_1.mean, csg_result_mat_1.mean, rel_tol=0.01) | ||
assert math.isclose(cad_result_mat_2.mean, csg_result_mat_2.mean, rel_tol=0.01) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,62 @@ | ||
|
||
from .utils import BaseCommonGeometryObject | ||
|
||
class SimpleTokamak(BaseCommonGeometryObject): | ||
def __init__( | ||
self, | ||
radius=500, | ||
blanket_thicknesses=100, | ||
center_column_thicknesses=150, | ||
center_column_extent_beyond_blanket=10, | ||
): | ||
self.radius = radius | ||
self.blanket_thicknesses = blanket_thicknesses | ||
self.center_column_thicknesses = center_column_thicknesses | ||
self.center_column_extent_beyond_blanket = center_column_extent_beyond_blanket | ||
|
||
def csg_model(self, materials): | ||
import openmc | ||
|
||
center_column_height = (self.radius + self.blanket_thicknesses + self.center_column_extent_beyond_blanket)*2 | ||
|
||
surface_inner_wall = openmc.Sphere(r=self.radius) | ||
surface_outer_wall = openmc.Sphere(r=self.radius + self.blanket_thicknesses) | ||
surface_center_cylinder = openmc.ZCylinder(r=self.center_column_thicknesses) | ||
surface_top_cy = openmc.ZPlane(z0=center_column_height/2, boundary_type='vacuum') | ||
surface_bot_cy = openmc.ZPlane(z0=-center_column_height/2, boundary_type='vacuum') | ||
outer_surface = openmc.ZCylinder(r=self.radius + self.blanket_thicknesses, boundary_type='vacuum') | ||
|
||
region1 = -surface_inner_wall & +surface_center_cylinder # plasma | ||
region2 = +surface_inner_wall & -surface_outer_wall & +surface_center_cylinder # blanket | ||
region3 = -surface_top_cy & +surface_bot_cy & -surface_center_cylinder # center column | ||
region4 = +surface_outer_wall & -surface_top_cy & +surface_bot_cy & +surface_center_cylinder & -outer_surface # outer vessel | ||
|
||
cell1 = openmc.Cell(region=region1) # plasma | ||
cell2 = openmc.Cell(region=region2) # blanket | ||
cell2.fill = materials[0] | ||
cell3 = openmc.Cell(region=region3) # center column | ||
cell3.fill = materials[1] | ||
cell4 = openmc.Cell(region=region4) # outer vessel | ||
|
||
geometry = openmc.Geometry([cell1, cell2, cell3, cell4]) | ||
materials = openmc.Materials([materials[0], materials[1]]) | ||
model = openmc.Model(geometry=geometry, materials=materials) | ||
return model | ||
|
||
def cadquery_assembly(self): | ||
import cadquery as cq | ||
|
||
assembly = cq.Assembly(name="simpletokamak") | ||
|
||
center_column_height = self.radius + self.blanket_thicknesses + self.center_column_extent_beyond_blanket | ||
|
||
sphere1 = cq.Workplane().sphere(self.radius) | ||
sphere2 = cq.Workplane().sphere(self.radius + self.blanket_thicknesses) | ||
|
||
center_column = cq.Workplane("XY").circle(self.center_column_thicknesses).extrude(center_column_height, both=True) | ||
|
||
sphere2 = sphere2.cut(sphere1).cut(center_column) | ||
|
||
assembly.add(sphere2) | ||
assembly.add(center_column) | ||
return assembly |
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,81 @@ | ||
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) | ||
|
||
# geometry used in both simulations | ||
common_geometry_object = SimpleTokamak( | ||
radius=500, | ||
blanket_thicknesses=100, | ||
center_column_thicknesses=50 | ||
) | ||
|
||
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 ring source | ||
my_source = openmc.IndependentSource() | ||
source_r = common_geometry_object.center_column_thicknesses + (common_geometry_object.radius-common_geometry_object.center_column_thicknesses) /2 | ||
r = openmc.stats.Discrete([source_r], [1]) | ||
phi = openmc.stats.Uniform(0, 2*math.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(materials=[mat1, mat2]) | ||
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") | ||
|
||
common_geometry_object.export_h5m_file_with_cad_to_dagmc( | ||
h5m_filename='simpletokamak.h5m', | ||
material_tags=['1', '2'], | ||
max_mesh_size=5, | ||
min_mesh_size=0.05 | ||
) | ||
# 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(h5m_filename='simpletokamak.h5m', materials=[mat1, mat2]) | ||
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, rel_tol=0.01) | ||
assert math.isclose(cad_result_mat_2.mean, csg_result_mat_2.mean, rel_tol=0.01) |
Oops, something went wrong.