Skip to content

Commit

Permalink
simpler examples
Browse files Browse the repository at this point in the history
  • Loading branch information
shimwell committed Jan 17, 2024
1 parent db4372d commit 7e7bba8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 103 deletions.
25 changes: 7 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,10 @@ jobs:
source "${HOME}/conda/etc/profile.d/mamba.sh"
mamba activate
mamba install -y -c conda-forge openmc
pip install openmc_data_downloader
openmc_data_downloader -l ENDFB-7.1-NNDC -i Fe56 Be9 Li6 Li7
- name: Install
run: |
python3 -m pip install .
python3 -c "import openmc_plasma_source"
- name: Run tests
run: |
python3 -m pip install .[tests]
python3 -m pytest -v tests
- name: Run examples
run: |
python3 examples/point_source_example.py
python3 examples/ring_source_example.py
python3 examples/tokamak_source_example.py
pip install .
python -c "import openmc_plasma_source"
pip install .[tests]
pytest -v tests
python examples/point_source_example.py
python examples/ring_source_example.py
python examples/tokamak_source_example.py
40 changes: 12 additions & 28 deletions examples/point_source_example.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
import openmc
from openmc_plasma_source import FusionPointSource

my_source = FusionPointSource(coordinate=(0, 0, 0), temperature=20000.0, fuel="DT")

# Create a single material
iron = openmc.Material()
iron.set_density("g/cm3", 5.0)
iron.add_element("Fe", 1.0)
mats = openmc.Materials([iron])

# Create a 5 cm x 5 cm box filled with iron
cells = []
inner_box1 = openmc.ZCylinder(r=600.0)
inner_box2 = openmc.ZCylinder(r=1400.0)
outer_box = openmc.model.rectangular_prism(4000.0, 4000.0, boundary_type="vacuum")
cells += [openmc.Cell(fill=iron, region=-inner_box1)]
cells += [openmc.Cell(fill=None, region=+inner_box1 & -inner_box2)]
cells += [openmc.Cell(fill=iron, region=+inner_box2 & outer_box)]
geometry = openmc.Geometry(cells)
# minimal geometry
sphere_surface = openmc.Sphere(r=1000.0, boundary_type='vacuum')
cell = openmc.Cell(region=-sphere_surface)
geometry = openmc.Geometry([cell])

# define the source
my_source = FusionPointSource(
coordinate=(0, 0, 0),
temperature=20000.0,
fuel="DT"
)

# Tell OpenMC we're going to use our custom source
settings = openmc.Settings()
Expand All @@ -26,19 +20,9 @@
settings.particles = 1000
settings.source = my_source

# Finally, define a mesh tally so that we can see the resulting flux
mesh = openmc.RegularMesh()
mesh.lower_left = (-2000.0, -2000.0)
mesh.upper_right = (2000.0, 2000.0)
mesh.dimension = (50, 50)

tally = openmc.Tally()
tally.filters = [openmc.MeshFilter(mesh)]
tally.scores = ["flux"]
tallies = openmc.Tallies([tally])

model = openmc.model.Model(
materials=mats, geometry=geometry, settings=settings, tallies=tallies
materials=None, geometry=geometry, settings=settings
)

model.run()
37 changes: 8 additions & 29 deletions examples/ring_source_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,27 @@
from openmc_plasma_source import FusionRingSource
import math

# minimal geometry
sphere_surface = openmc.Sphere(r=1000.0, boundary_type='vacuum')
cell = openmc.Cell(region=-sphere_surface)
geometry = openmc.Geometry([cell])

# define the source
my_source = FusionRingSource(
radius=700,
angles=(0.0, 2 * math.pi), # 360deg source
temperature=20000.0,
)

# Create a single material
iron = openmc.Material()
iron.set_density("g/cm3", 5.0)
iron.add_element("Fe", 1.0)
mats = openmc.Materials([iron])

# Create a 5 cm x 5 cm box filled with iron
cells = []
inner_box1 = openmc.ZCylinder(r=600.0)
inner_box2 = openmc.ZCylinder(r=1400.0)
outer_box = openmc.model.rectangular_prism(4000.0, 4000.0, boundary_type="vacuum")
cells += [openmc.Cell(fill=iron, region=-inner_box1)]
cells += [openmc.Cell(fill=None, region=+inner_box1 & -inner_box2)]
cells += [openmc.Cell(fill=iron, region=+inner_box2 & outer_box)]
geometry = openmc.Geometry(cells)

# Tell OpenMC we're going to use our custom source
settings = openmc.Settings()
settings.run_mode = "fixed source"
settings.batches = 10
settings.particles = 1000
# tell OpenMC we're going to use our custom source
settings.source = my_source

# Finally, define a mesh tally so that we can see the resulting flux
mesh = openmc.RegularMesh()
mesh.lower_left = (-2000.0, -2000.0)
mesh.upper_right = (2000.0, 2000.0)
mesh.dimension = (50, 50)

tally = openmc.Tally()
tally.filters = [openmc.MeshFilter(mesh)]
tally.scores = ["flux"]
tallies = openmc.Tallies([tally])

model = openmc.model.Model(
materials=mats, geometry=geometry, settings=settings, tallies=tallies
materials=None, geometry=geometry, settings=settings
)

model.run()
33 changes: 5 additions & 28 deletions examples/tokamak_source_example.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import openmc
from openmc_plasma_source import TokamakSource

# minimal geometry
sphere_surface = openmc.Sphere(r=1000.0, boundary_type='vacuum')
cell = openmc.Cell(region=-sphere_surface)
geometry = openmc.Geometry([cell])

# create a plasma source
my_plasma = TokamakSource(
Expand All @@ -22,43 +26,16 @@
ion_temperature_beta=6,
)


# Create a single material
iron = openmc.Material()
iron.set_density("g/cm3", 5.0)
iron.add_element("Fe", 1.0)
mats = openmc.Materials([iron])

# Create a 5 cm x 5 cm box filled with iron
cells = []
inner_box1 = openmc.ZCylinder(r=600.0)
inner_box2 = openmc.ZCylinder(r=1400.0)
outer_box = openmc.model.rectangular_prism(4000.0, 4000.0, boundary_type="vacuum")
cells += [openmc.Cell(fill=iron, region=-inner_box1)]
cells += [openmc.Cell(fill=None, region=+inner_box1 & -inner_box2)]
cells += [openmc.Cell(fill=iron, region=+inner_box2 & outer_box)]
geometry = openmc.Geometry(cells)

# Tell OpenMC we're going to use our custom source
settings = openmc.Settings()
settings.run_mode = "fixed source"
settings.batches = 10
settings.particles = 1000
settings.source = my_plasma.sources

# Finally, define a mesh tally so that we can see the resulting flux
mesh = openmc.RegularMesh()
mesh.lower_left = (-2000.0, -2000.0)
mesh.upper_right = (2000.0, 2000.0)
mesh.dimension = (50, 50)

tally = openmc.Tally()
tally.filters = [openmc.MeshFilter(mesh)]
tally.scores = ["flux"]
tallies = openmc.Tallies([tally])

model = openmc.model.Model(
materials=mats, geometry=geometry, settings=settings, tallies=tallies
materials=None, geometry=geometry, settings=settings
)

model.run()

0 comments on commit 7e7bba8

Please sign in to comment.