Skip to content

Commit

Permalink
Merge pull request #17 from fusion-energy/develop
Browse files Browse the repository at this point in the history
refactored code into core and utils, improved examples and CI
  • Loading branch information
shimwell authored Nov 3, 2021
2 parents 97c4689 + c8a5707 commit 82c51be
Show file tree
Hide file tree
Showing 18 changed files with 515 additions and 196 deletions.
21 changes: 16 additions & 5 deletions .github/workflows/ci_with_install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ jobs:
testing:
runs-on: ubuntu-latest
container:
image: continuumio/miniconda3:4.9.2
# image: openmc/openmc:latest-dagmc is missing the dagmc universe
image: openmc/openmc:develop-dagmc
steps:
- name: Checkout repository
uses: actions/checkout@v2
Expand All @@ -29,17 +30,27 @@ jobs:
run: |
python setup.py install
- name: install openmc
run: |
conda install -c conda-forge openmc
- name: install packages for tests
run: |
pip install -r requirements-test.txt
- name: Run test_utils
run: |
cp tests/example.stl .
pytest tests/ -v --cov=regular_mesh_plotter --cov-append --cov-report term --cov-report xml
- name: Upload to codecov
uses: codecov/codecov-action@v2

- name: Run examples
run: |
cd examples
python create_statepoint_file_with_meshes_openmc_dagmc.py
python create_statepoint_file_with_meshes_openmc.py
# python examples_from_readme.py # commented out as it requires entire neutronics workflow
python plot_regular_mesh_dose_tally.py
python plot_regular_mesh_dose_tally_with_geometry.py
python plot_regular_mesh_tally.py
python plot_regular_mesh_tally_with_geometry.py
python plot_regular_mesh_values.py
python plot_regular_mesh_values_with_geometry.py
119 changes: 111 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Mesh results in the form of Numpy arrays or OpenMC.tally objects can be plotted
with a single API call.

A Matplotlib.pyplot object is returned by all functions so one can make changes
to the legend, axis, colour map etc. However some key options are accessable
to the legend, axis, colour map etc. However some key options are accessible
in the function call directly.

There are additional options that allow
Expand All @@ -38,26 +38,129 @@ and other mesh tally results.

Example 1 shows a Numpy array plotted
```python
TODO
plot_regular_mesh_values(
values: np.ndarray,
filename: Optional[str] = None,
scale=None, # LogNorm(),
vmin=None,
label="",
base_plt=None,
extent=None,
x_label="X [cm]",
y_label="Y [cm]",
rotate_plot: float = 0,
)
```

Example 2 shows a Numpy array plotted with an underlying DAGMC geometry
```python
TODO
plot_regular_mesh_values_with_geometry(
values: np.ndarray,
dagmc_file_or_trimesh_object,
filename: Optional[str] = None,
scale=None, # LogNorm(),
vmin=None,
label="",
extent=None,
x_label="X [cm]",
y_label="Y [cm]",
plane_origin: List[float] = None,
plane_normal: List[float] = [0, 0, 1],
rotate_mesh: float = 0,
rotate_geometry: float = 0,
)
```

Example 3 shows a OpenMC tally plotted with an underlying DAGMC geometry
Example 3 shows a OpenMC tally plotted
```python
TODO
plot_regular_mesh_tally(
tally,
dagmc_file_or_trimesh_object,
std_dev_or_tally_value="tally_value",
filename: Optional[str] = None,
scale=None, # LogNorm(),
vmin=None,
label="",
x_label="X [cm]",
y_label="Y [cm]",
plane_origin: List[float] = None,
plane_normal: List[float] = [0, 0, 1],
rotate_mesh: float = 0,
rotate_geometry: float = 0,
required_units=None,
source_strength: float = None,
)
```

Example 4 shows how to rotate the underlying DAGMC geometry and mesh tally.
Example 4 shows a OpenMC tally plotted with an underlying DAGMC geometry
```python
plot_regular_mesh_tally_with_geometry(
tally,
dagmc_file_or_trimesh_object,
std_dev_or_tally_value="tally_value",
filename: Optional[str] = None,
scale=None, # LogNorm(),
vmin=None,
label="",
x_label="X [cm]",
y_label="Y [cm]",
plane_origin: List[float] = None,
plane_normal: List[float] = [0, 0, 1],
rotate_mesh: float = 0,
rotate_geometry: float = 0,
required_units=None,
source_strength: float = None,
)
```

Example 5 shows how to rotate the underlying DAGMC geometry and mesh tally.
This is sometimes necessary as the slice and mesh can get out of alignment
when changing the
when changing the plane normal
```python
TODO
plot_regular_mesh_tally_with_geometry(
tally,
dagmc_file_or_trimesh_object,
std_dev_or_tally_value="tally_value",
filename: Optional[str] = None,
scale=None, # LogNorm(),
vmin=None,
label="",
x_label="X [cm]",
y_label="Y [cm]",
plane_origin: List[float] = None,
plane_normal: List[float] = [0, 0, 1],
rotate_mesh: float = 0,
rotate_geometry: float = 0,
required_units=None,
source_strength: float = None,
)
```

Example 6 shows how to plot a dose tally with the underlying DAGMC geometry.
This also includes unit conversion from the base tally units to the requested
units.
```python
plot_regular_mesh_dose_tally_with_geometry(
tally,
dagmc_file_or_trimesh_object,
filename: Optional[str] = None,
scale=None, # LogNorm(),
vmin=None,
label="",
x_label="X [cm]",
y_label="Y [cm]",
plane_origin: List[float] = None,
plane_normal: List[float] = [0, 0, 1],
rotate_mesh: float = 0,
rotate_geometry: float = 0,
required_units="picosievert cm **2 / simulated_particle",
source_strength: float = None,
std_dev_or_tally_value: str = "tally_value",
):
```

Additional examples can be found in the [examples folder in the GitHub repository](https://github.com/fusion-energy/regular_mesh_plotter/tree/main/examples)

# Related packages

If you want to plot the DAGMC geometry without a mesh tally then take a look at
Expand Down
2 changes: 1 addition & 1 deletion examples/create_statepoint_file_with_meshes_openmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
)

settings = odw.FusionSettings()
settings.batches = 2
settings.batches = 3
settings.particles = 1000000
# assigns a ring source of DT energy neutrons to the source using the
# openmc_plasma_source package
Expand Down
20 changes: 10 additions & 10 deletions examples/create_statepoint_file_with_meshes_openmc_dagmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
import openmc
import openmc_dagmc_wrapper as odw
import openmc_plasma_source as ops
import paramak
from stl_to_h5m import stl_to_h5m

my_shape = paramak.ExtrudeStraightShape(
points=[(1, 1), (1, 200), (600, 200), (600, 1)],
distance=180,
)

my_shape.export_stl("example.stl")
# code used to create example.stl
# import paramak
# my_shape = paramak.ExtrudeStraightShape(
# points=[(1, 1), (1, 200), (600, 200), (600, 1)],
# distance=180,
# )
# my_shape.export_stl("example.stl")

# This script converts the CAD stl files generated into h5m files that can be
# used in DAGMC enabled codes. h5m files created in this way are imprinted,
Expand All @@ -33,13 +33,13 @@
)

materials = odw.Materials(
h5m_filename="dagmc.h5m", correspondence_dict={"mat1": "eurofer"}
h5m_filename="dagmc.h5m", correspondence_dict={"mat1": "FLiNaK"}
)

tally1 = odw.MeshTally2D(
tally_type="neutron_effective_dose",
plane="xy",
mesh_resolution=(10, ),
mesh_resolution=(10, 5),
bounding_box="dagmc.h5m",
)
tally2 = odw.MeshTally2D(
Expand All @@ -57,7 +57,7 @@
tally4 = odw.MeshTally2D(
tally_type="neutron_effective_dose",
plane="xy",
mesh_resolution=(10, ),
mesh_resolution=(10, 10),
bounding_box="dagmc.h5m",
)
tally5 = odw.MeshTally2D(
Expand Down
86 changes: 86 additions & 0 deletions examples/example.stl
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
solid
facet normal -1.000000e+00 0.000000e+00 -0.000000e+00
outer loop
vertex 1.000000e+00 9.000000e+01 2.000000e+02
vertex 1.000000e+00 9.000000e+01 1.000000e+00
vertex 1.000000e+00 -9.000000e+01 1.000000e+00
endloop
endfacet
facet normal -1.000000e+00 0.000000e+00 0.000000e+00
outer loop
vertex 1.000000e+00 -9.000000e+01 2.000000e+02
vertex 1.000000e+00 9.000000e+01 2.000000e+02
vertex 1.000000e+00 -9.000000e+01 1.000000e+00
endloop
endfacet
facet normal 0.000000e+00 0.000000e+00 -1.000000e+00
outer loop
vertex 1.000000e+00 -9.000000e+01 1.000000e+00
vertex 6.000000e+02 9.000000e+01 1.000000e+00
vertex 6.000000e+02 -9.000000e+01 1.000000e+00
endloop
endfacet
facet normal 0.000000e+00 0.000000e+00 -1.000000e+00
outer loop
vertex 1.000000e+00 -9.000000e+01 1.000000e+00
vertex 1.000000e+00 9.000000e+01 1.000000e+00
vertex 6.000000e+02 9.000000e+01 1.000000e+00
endloop
endfacet
facet normal 0.000000e+00 -0.000000e+00 1.000000e+00
outer loop
vertex 6.000000e+02 -9.000000e+01 2.000000e+02
vertex 6.000000e+02 9.000000e+01 2.000000e+02
vertex 1.000000e+00 9.000000e+01 2.000000e+02
endloop
endfacet
facet normal 0.000000e+00 0.000000e+00 1.000000e+00
outer loop
vertex 6.000000e+02 -9.000000e+01 2.000000e+02
vertex 1.000000e+00 9.000000e+01 2.000000e+02
vertex 1.000000e+00 -9.000000e+01 2.000000e+02
endloop
endfacet
facet normal 0.000000e+00 1.000000e+00 0.000000e+00
outer loop
vertex 6.000000e+02 9.000000e+01 2.000000e+02
vertex 1.000000e+00 9.000000e+01 1.000000e+00
vertex 1.000000e+00 9.000000e+01 2.000000e+02
endloop
endfacet
facet normal 0.000000e+00 1.000000e+00 0.000000e+00
outer loop
vertex 6.000000e+02 9.000000e+01 2.000000e+02
vertex 6.000000e+02 9.000000e+01 1.000000e+00
vertex 1.000000e+00 9.000000e+01 1.000000e+00
endloop
endfacet
facet normal 1.000000e+00 0.000000e+00 -0.000000e+00
outer loop
vertex 6.000000e+02 9.000000e+01 1.000000e+00
vertex 6.000000e+02 9.000000e+01 2.000000e+02
vertex 6.000000e+02 -9.000000e+01 2.000000e+02
endloop
endfacet
facet normal 1.000000e+00 0.000000e+00 0.000000e+00
outer loop
vertex 6.000000e+02 -9.000000e+01 1.000000e+00
vertex 6.000000e+02 9.000000e+01 1.000000e+00
vertex 6.000000e+02 -9.000000e+01 2.000000e+02
endloop
endfacet
facet normal -0.000000e+00 -1.000000e+00 0.000000e+00
outer loop
vertex 6.000000e+02 -9.000000e+01 2.000000e+02
vertex 1.000000e+00 -9.000000e+01 2.000000e+02
vertex 1.000000e+00 -9.000000e+01 1.000000e+00
endloop
endfacet
facet normal 0.000000e+00 -1.000000e+00 -0.000000e+00
outer loop
vertex 6.000000e+02 -9.000000e+01 2.000000e+02
vertex 1.000000e+00 -9.000000e+01 1.000000e+00
vertex 6.000000e+02 -9.000000e+01 1.000000e+00
endloop
endfacet
endsolid
8 changes: 4 additions & 4 deletions examples/plot_regular_mesh_dose_tally.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
# creates a plot of the mesh tally
my_plot = rmp.plot_regular_mesh_dose_tally(
tally=my_tally, # the openmc tally object to plot, must be a 2d mesh tally
filename='plot_regular_mesh_dose_tally.png', # the filename of the picture file saved
filename="plot_regular_mesh_dose_tally.png", # the filename of the picture file saved
scale=None, # LogNorm(),
vmin=None,
label="",
x_label="X [cm]",
y_label="Y [cm]",
rotate_plot = 0,
required_units='picosievert cm **2 / simulated_particle',
source_strength = None,
rotate_plot=0,
required_units="picosievert cm **2 / simulated_particle",
source_strength=None,
)

# displays the plot
Expand Down
14 changes: 7 additions & 7 deletions examples/plot_regular_mesh_dose_tally_with_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@
my_plot = rmp.plot_regular_mesh_dose_tally_with_geometry(
tally=my_tally,
dagmc_file_or_trimesh_object="dagmc.h5m",
filename = 'plot_regular_mesh_dose_tally_with_geometry.png',
filename="plot_regular_mesh_dose_tally_with_geometry.png",
scale=None, # LogNorm(),
vmin=None,
label="",
x_label="X [cm]",
y_label="Y [cm]",
plane_origin = None, # this could be skipped as it defaults to None, which uses the center of the mesh
plane_normal = [0, 0, 1],
rotate_mesh = 0,
rotate_geometry = 0,
required_units='picosievert cm **2 / simulated_particle',
source_strength = None,
plane_origin=None, # this could be skipped as it defaults to None, which uses the center of the mesh
plane_normal=[0, 0, 1],
rotate_mesh=0,
rotate_geometry=0,
required_units="picosievert cm **2 / simulated_particle",
source_strength=None,
)

my_plot.show()
5 changes: 2 additions & 3 deletions examples/plot_regular_mesh_tally.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import regular_mesh_plotter as rmp
import openmc

Expand All @@ -11,7 +10,7 @@
# creates a plot of the mesh
rmp.plot_regular_mesh_tally(
tally=my_tally,
filename= 'neutron_effective_dose_on_2D_mesh_xy.png',
filename="neutron_effective_dose_on_2D_mesh_xy.png",
scale=None, # LogNorm(),
vmin=None,
label="",
Expand All @@ -21,4 +20,4 @@
# rotate_plot: float = 0,
# required_units: str = None,
# source_strength: float = None,
)
)
Loading

0 comments on commit 82c51be

Please sign in to comment.