Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

moved to src layout #85

Merged
merged 13 commits into from
Jan 17, 2024
46 changes: 22 additions & 24 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
name: CI
name: CI testing

on:
pull_request:
branches:
- develop
- main
pull_request:
push:
branches:
- develop
- main

- main

jobs:
testing:
runs-on: ubuntu-latest
container:
image: openmc/openmc:develop
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Install
run: |
python3 -m pip install --upgrade pip
python3 -m pip install .[tests]

- name: Run tests
run: |
python3 -m pytest -v tests
- name: checkout actions
uses: actions/checkout@v4

- name: Run examples
- name: install dependencies
shell: bash
run: |
python3 examples/point_source_example.py
python3 examples/ring_source_example.py
python3 examples/tokamak_source_example.py

wget -O Miniforge3.sh "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh"
bash Miniforge3.sh -b -p "${HOME}/conda"
source "${HOME}/conda/etc/profile.d/conda.sh"
source "${HOME}/conda/etc/profile.d/mamba.sh"
mamba activate
mamba install -y -c conda-forge openmc
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
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ authors:
- family-names: "Faisal"
given-names: "Mohammed"
title: "OpenMC Plasma Source"
version: 0.2.4
date-released: 2022-01-31
version: 0.3.0
date-released: 2023-01-12
url: "https://github.com/fusion-energy/openmc-plasma-source"
4 changes: 4 additions & 0 deletions examples/cross_sections.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version='1.0' encoding='utf-8'?>
<cross_sections>
<library materials="H1" path="neutron/H1.h5" type="neutron" />
</cross_sections>
38 changes: 10 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
from pathlib import Path

my_source = FusionPointSource(coordinate=(0, 0, 0), temperature=20000.0, fuel="DT")
# just making use of a local cross section xml file, replace with your own cross sections or comment out
openmc.config["cross_sections"] = Path(__file__).parent.resolve() / "cross_sections.xml"

# Create a single material
iron = openmc.Material()
iron.set_density("g/cm3", 5.0)
iron.add_element("Fe", 1.0)
mats = openmc.Materials([iron])
# minimal geometry
sphere_surface = openmc.Sphere(r=1000.0, boundary_type="vacuum")
cell = openmc.Cell(region=-sphere_surface)
geometry = openmc.Geometry([cell])

# 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)
# 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,7 @@
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
)
model = openmc.model.Model(materials=None, geometry=geometry, settings=settings)

model.run()
43 changes: 12 additions & 31 deletions examples/ring_source_example.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,30 @@
import openmc
from openmc_plasma_source import FusionRingSource
import math
from pathlib import Path

# just making use of a local cross section xml file, replace with your own cross sections or comment out
openmc.config["cross_sections"] = Path(__file__).parent.resolve() / "cross_sections.xml"

# 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
)
model = openmc.model.Model(materials=None, geometry=geometry, settings=settings)

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

# just making use of a local cross section xml file, replace with your own cross sections or comment out
openmc.config["cross_sections"] = Path(__file__).parent.resolve() / "cross_sections.xml"


# 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 +31,14 @@
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
)
model = openmc.model.Model(materials=None, geometry=geometry, settings=settings)

model.run()
41 changes: 36 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,42 @@
[build-system]
requires = [
"setuptools >= 45",
"wheel",
"setuptools_scm[toml] >= 6.2",
"setuptools_scm_git_archive",
"setuptools>=65.5.0",
"setuptools_scm[toml]>=7.0.5"
]
build-backend = "setuptools.build_meta"

[project]
name = "openmc_plasma_source"
dynamic = ["version"]
description = "Creates tokamak and ICF plasma sources for OpenMC"
readme = "README.md"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]
authors = [
{ name="Rémi Delaporte-Mathurin" },
]
requires-python = ">=3.8"
keywords = ["python", "neutron", "fusion", "source", "openmc", "energy", "tokamak"]
dependencies = [
"numpy>=1.9",
"matplotlib>=3.2.2",
]

[project.urls]
"Homepage" = "https://github.com/fusion-energy/openmc-plasma-source"
"Bug Tracker" = "https://github.com/fusion-energy/openmc-plasma-source/issues"

[tool.setuptools_scm]
write_to = "openmc_plasma_source/_version.py"
write_to = "src/_version.py"

[project.optional-dependencies]
tests = [
"pytest>=5.4.3",
"hypothesis"
]

[tool.setuptools]
package-dir = {"" = "src"}
36 changes: 0 additions & 36 deletions setup.cfg

This file was deleted.

4 changes: 0 additions & 4 deletions setup.py

This file was deleted.

File renamed without changes.
6 changes: 3 additions & 3 deletions tests/test_tokamak_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,15 +264,15 @@ def tokamak_source_strategy(draw):
st.floats(
min_value=1e-5 * major_radius,
max_value=np.nextafter(major_radius, major_radius - 1),
**finites
**finites,
)
)

pedestal_radius = draw(
st.floats(
min_value=0.8 * minor_radius,
max_value=np.nextafter(minor_radius, minor_radius - 1),
**finites
**finites,
)
)

Expand All @@ -288,7 +288,7 @@ def tokamak_source_strategy(draw):
st.floats(
min_value=np.nextafter(-0.5 * minor_radius, +1),
max_value=np.nextafter(0.5 * minor_radius, -1),
**finites
**finites,
)
)

Expand Down