-
Notifications
You must be signed in to change notification settings - Fork 1
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 #2 from fusion-energy/adding_tests
added first test and CI
- Loading branch information
Showing
8 changed files
with
249 additions
and
28 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,32 @@ | ||
name: black | ||
|
||
on: | ||
push: | ||
paths: | ||
- '**.py' | ||
|
||
defaults: | ||
run: | ||
shell: bash | ||
|
||
jobs: | ||
black: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
ref: ${{ github.head_ref }} | ||
- name: Setup Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.x | ||
- name: Install black | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install black | ||
- name: Run black | ||
run: | | ||
black . | ||
- uses: stefanzweifel/git-auto-commit-action@v4 | ||
with: | ||
commit_message: "[skip ci] Apply formatting changes" |
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,51 @@ | ||
# This CI will launch a Docker image that contains all the dependencies required | ||
# within that image the pytest test suite is run | ||
|
||
name: CI with install | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- develop | ||
- main | ||
paths-ignore: | ||
- 'docs/**' | ||
- '.gitignore' | ||
- '*.md' | ||
- 'CITATION.cff' | ||
- 'LICENSE.txt' | ||
- 'readthedocs.yml' | ||
|
||
jobs: | ||
testing: | ||
runs-on: ubuntu-latest | ||
container: | ||
# image: continuumio/miniconda3:4.10.3 | ||
image: openmc/openmc:latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
# - name: install dependencies | ||
# run: | | ||
# conda install -c conda-forge mamba | ||
# mamba install -c conda-forge openmc | ||
|
||
- name: install package | ||
run: | | ||
pip install --upgrade pip | ||
pip install . | ||
python -c "import cylindrical_mesh_plotter" | ||
- name: install packages for tests | ||
run: | | ||
pip install .[tests] | ||
- name: Run test_utils | ||
run: | | ||
pytest tests | ||
- name: Run examples | ||
run: | | ||
cd examples | ||
python plot_rz_slices.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,40 @@ | ||
# This yml file will trigger a Github Actions event that builds and upload the | ||
# Python package to PiPy. This makes use of Twine and is triggered when a push | ||
# to the main branch occures. For more information see: | ||
# https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries | ||
# and for details on the Autobump version section see: | ||
# https://github.com/grst/python-ci-versioneer | ||
|
||
name: Upload Python Package | ||
|
||
on: | ||
# allows us to run workflows manually | ||
workflow_dispatch: | ||
release: | ||
types: [created] | ||
|
||
jobs: | ||
deploy: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.x' | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install setuptools wheel build twine | ||
- name: Build and publish | ||
env: | ||
TWINE_USERNAME: __token__ | ||
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} | ||
run: | | ||
python -m build | ||
twine check dist/* | ||
twine upload dist/* |
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 |
---|---|---|
@@ -1,10 +1,41 @@ | ||
[build-system] | ||
requires = [ | ||
"setuptools >= 45", | ||
"wheel", | ||
"setuptools_scm[toml] >= 6.2", | ||
] | ||
requires = ["setuptools >= 65.4.0", "setuptools_scm[toml]>=7.0.5"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[project] | ||
name = "cylindrical_mesh_plotter" | ||
authors = [ | ||
{ name="Jonathan Shimwell", email="[email protected]" }, | ||
] | ||
license = {file = "LICENSE.txt"} | ||
description = "A Python package for creating publication quality plots of cylindrical mesh tallies" | ||
readme = "README.md" | ||
requires-python = ">=3.8" | ||
keywords = ["cylindrical", "mesh", "openmc", "tally", "plot", "slice"] | ||
classifiers = [ | ||
"Programming Language :: Python :: 3", | ||
"License :: OSI Approved :: MIT License", | ||
"Operating System :: OS Independent", | ||
] | ||
dependencies = [ | ||
"numpy>=1.21.1", | ||
"matplotlib>=3.4.2", | ||
] | ||
dynamic = ["version"] | ||
|
||
|
||
[tool.setuptools_scm] | ||
write_to = "src/openmc_cylindrical_mesh_plotter/_version.py" | ||
write_to = "src/cylindrical_mesh_plotter/_version.py" | ||
|
||
|
||
[project.optional-dependencies] | ||
tests = [ | ||
"pytest", | ||
] | ||
|
||
[project.urls] | ||
"Homepage" = "https://github.com/fusion-energy/cylindrical_mesh_plotter" | ||
"Bug Tracker" = "https://github.com/fusion-energy/cylindrical_mesh_plotter/issues" | ||
|
||
[tool.setuptools] | ||
package-dir = {"" = "src"} |
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 |
---|---|---|
@@ -1 +1 @@ | ||
from .core import * | ||
from .core import * |
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,72 @@ | ||
import openmc | ||
import numpy as np | ||
from math import pi | ||
import matplotlib.pyplot as plt | ||
import openmc_cylindrical_mesh_plotter # adds slice_of_data method to CylindricalMesh | ||
|
||
|
||
def test_slice_of_data(): | ||
mesh = openmc.CylindricalMesh() | ||
mesh.phi_grid = np.linspace(0.0, 2 * pi, 10) | ||
mesh.r_grid = np.linspace(0, 10, 4) | ||
mesh.z_grid = np.linspace(0, 5, 5) | ||
|
||
tally = openmc.Tally(name="my_tally") | ||
mesh_filter = openmc.MeshFilter(mesh) | ||
tally.filters.append(mesh_filter) | ||
tally.scores.append("flux") | ||
tallies = openmc.Tallies([tally]) | ||
|
||
outer_surface = openmc.Sphere(r=100, boundary_type="vacuum") | ||
cell = openmc.Cell(region=-outer_surface) | ||
|
||
material = openmc.Material() | ||
material.add_nuclide("Fe56", 1) | ||
material.set_density("g/cm3", 0.1) | ||
my_materials = openmc.Materials([material]) | ||
|
||
universe = openmc.Universe(cells=[cell]) | ||
my_geometry = openmc.Geometry(universe) | ||
|
||
my_source = openmc.Source() | ||
|
||
# the distribution of radius is just a single value | ||
radius = openmc.stats.Discrete([5], [1]) | ||
# the distribution of source z values is just a single value | ||
z_values = openmc.stats.Discrete([2.5], [1]) | ||
# the distribution of source azimuthal angles values is a uniform distribution between 0 and 2 Pi | ||
angle = openmc.stats.Uniform(a=0.0, b=2 * 3.14159265359) | ||
# this makes the ring source using the three distributions and a radius | ||
# could do a point source instead with my_source.space = openmc.stats.Point((5,5., 5)) | ||
my_source.space = openmc.stats.CylindricalIndependent( | ||
r=radius, phi=angle, z=z_values, origin=(0.0, 0.0, 0.0) | ||
) | ||
# sets the direction to isotropic | ||
my_source.angle = openmc.stats.Isotropic() | ||
|
||
my_settings = openmc.Settings() | ||
# my_settings.inactive = 0 | ||
my_settings.run_mode = "fixed source" | ||
my_settings.batches = 10 | ||
my_settings.particles = 100000 | ||
my_settings.source = my_source | ||
|
||
model = openmc.model.Model(my_geometry, my_materials, my_settings, tallies) | ||
sp_filename = model.run() | ||
|
||
statepoint = openmc.StatePoint(sp_filename) | ||
|
||
my_tally_result = statepoint.get_tally(name="my_tally") | ||
|
||
for slice_index in range(len(mesh.phi_grid) - 1): | ||
data = mesh.slice_of_data( | ||
dataset=my_tally_result.mean, | ||
slice_index=slice_index, | ||
volume_normalization=True, | ||
) | ||
extent = mesh.get_mpl_plot_extent() | ||
x_label, y_label = mesh.get_axis_labels() | ||
plt.xlabel(x_label) | ||
plt.ylabel(y_label) | ||
plt.imshow(data, extent=extent) | ||
assert data.shape == (4, 3) |