diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c1c6ac4..a475db9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/CITATION.cff b/CITATION.cff index 889e4b9..e3e21d3 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -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" diff --git a/examples/cross_sections.xml b/examples/cross_sections.xml new file mode 100644 index 0000000..71fa4da --- /dev/null +++ b/examples/cross_sections.xml @@ -0,0 +1,4 @@ + + + + diff --git a/examples/point_source_example.py b/examples/point_source_example.py index f8db0d9..fb040a1 100644 --- a/examples/point_source_example.py +++ b/examples/point_source_example.py @@ -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() @@ -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() diff --git a/examples/ring_source_example.py b/examples/ring_source_example.py index e33e52b..f09d570 100644 --- a/examples/ring_source_example.py +++ b/examples/ring_source_example.py @@ -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() diff --git a/examples/tokamak_source_example.py b/examples/tokamak_source_example.py index e311fe7..9c98390 100644 --- a/examples/tokamak_source_example.py +++ b/examples/tokamak_source_example.py @@ -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( @@ -22,23 +31,6 @@ 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" @@ -46,19 +38,7 @@ 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() diff --git a/pyproject.toml b/pyproject.toml index bc250d5..c421db0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"} \ No newline at end of file diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index dba17a5..0000000 --- a/setup.cfg +++ /dev/null @@ -1,36 +0,0 @@ -[metadata] -name = openmc_plasma_source -author = The openmc-plasma-source Development Team -author_email = rdelaportemathurin@gmail.com -description = Creates tokamak plasma sources for OpenMC -long_description = file: README.md -long_description_content_type = text/markdown -url = https://github.com/fusion-energy/openmc-plasma-source -license = MIT -license_file = LICENSE.txt -classifiers = - Natural Language :: English - Topic :: Scientific/Engineering - Programming Language :: Python :: 3 - Programming Language :: Python :: 3.6 - Programming Language :: Python :: 3.7 - Programming Language :: Python :: 3.8 - Programming Language :: Python :: 3.9 - License :: OSI Approved :: MIT License - Operating System :: OS Independent -project_urls = - Source = https://github.com/fusion-energy/openmc-plasma-source - Tracker = https://github.com/fusion-energy/openmc-plasma-source/issues - -[options] -packages = find: -python_requires= >=3.6 -install_requires= - numpy >= 1.9 - matplotlib >= 3.2.2 - importlib-metadata; python_version < "3.8" - -[options.extras_require] -tests = - pytest >= 5.4.3 - hypothesis diff --git a/setup.py b/setup.py deleted file mode 100644 index 1abbd06..0000000 --- a/setup.py +++ /dev/null @@ -1,4 +0,0 @@ -import setuptools - -if __name__ == "__main__": - setuptools.setup() diff --git a/openmc_plasma_source/__init__.py b/src/openmc_plasma_source/__init__.py similarity index 100% rename from openmc_plasma_source/__init__.py rename to src/openmc_plasma_source/__init__.py diff --git a/openmc_plasma_source/fuel_types.py b/src/openmc_plasma_source/fuel_types.py similarity index 100% rename from openmc_plasma_source/fuel_types.py rename to src/openmc_plasma_source/fuel_types.py diff --git a/openmc_plasma_source/plotting/__init__.py b/src/openmc_plasma_source/plotting/__init__.py similarity index 100% rename from openmc_plasma_source/plotting/__init__.py rename to src/openmc_plasma_source/plotting/__init__.py diff --git a/openmc_plasma_source/plotting/plot_tokamak_source.py b/src/openmc_plasma_source/plotting/plot_tokamak_source.py similarity index 100% rename from openmc_plasma_source/plotting/plot_tokamak_source.py rename to src/openmc_plasma_source/plotting/plot_tokamak_source.py diff --git a/openmc_plasma_source/point_source.py b/src/openmc_plasma_source/point_source.py similarity index 100% rename from openmc_plasma_source/point_source.py rename to src/openmc_plasma_source/point_source.py diff --git a/openmc_plasma_source/ring_source.py b/src/openmc_plasma_source/ring_source.py similarity index 100% rename from openmc_plasma_source/ring_source.py rename to src/openmc_plasma_source/ring_source.py diff --git a/openmc_plasma_source/tokamak_source.py b/src/openmc_plasma_source/tokamak_source.py similarity index 100% rename from openmc_plasma_source/tokamak_source.py rename to src/openmc_plasma_source/tokamak_source.py diff --git a/tests/test_tokamak_source.py b/tests/test_tokamak_source.py index 875ca8b..27379aa 100644 --- a/tests/test_tokamak_source.py +++ b/tests/test_tokamak_source.py @@ -264,7 +264,7 @@ def tokamak_source_strategy(draw): st.floats( min_value=1e-5 * major_radius, max_value=np.nextafter(major_radius, major_radius - 1), - **finites + **finites, ) ) @@ -272,7 +272,7 @@ def tokamak_source_strategy(draw): st.floats( min_value=0.8 * minor_radius, max_value=np.nextafter(minor_radius, minor_radius - 1), - **finites + **finites, ) ) @@ -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, ) )