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

cleaned readme #55

Merged
merged 18 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions .github/workflows/ci_with_install.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# This CI will lauch a Docker image that contains all the dependencies required
# 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/**'
Expand All @@ -20,22 +19,16 @@ jobs:
testing:
runs-on: ubuntu-latest
container:
# image: continuumio/miniconda3:4.10.3
image: ghcr.io/openmc-data-storage/miniconda3_4.9.2_endfb-7.1_nndc_tendl_2019
image: openmc/openmc:develop
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: install dependancies
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 regular_mesh_plotter"
python -c "import openmc_regular_mesh_plotter"

- name: install packages for tests
run: |
Expand All @@ -48,4 +41,6 @@ jobs:
- name: Run examples
run: |
cd examples
python plot_regular_mesh_tally_with_csg_geometry.py
python plot_minimal_example.py
python plot_with_custom_color_map.py
python plot_sweep_through_slice_indexes.py
8 changes: 4 additions & 4 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors:
- family-names: "Delaporte-Mathurin"
given-names: "Rémi"
orcid: "https://orcid.org/0000-0003-1064-8882"
title: "A Python package for plotting regular mesh tally results from neutronics simulations."
version: 0.1.0
date-released: 2021-10-30
url: "https://github.com/fusion-energy/regular_mesh_plotter"
title: "A Python package for plotting OpenMC regular mesh tally results with underlying geometry from neutronics simulations."
version: 1.0.0
date-released: 2022-09-01
url: "https://github.com/fusion-energy/openmc_regular_mesh_plotter"
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

[![CI with install](https://github.com/fusion-energy/openmc_regular_mesh_plotter/actions/workflows/ci_with_install.yml/badge.svg?branch=develop)](https://github.com/fusion-energy/openmc_regular_mesh_plotter/actions/workflows/ci_with_install.yml)

[![PyPI](https://img.shields.io/pypi/v/regular-mesh-plotter?color=brightgreen&label=pypi&logo=grebrightgreenen&logoColor=green)](https://pypi.org/project/regular-mesh-plotter/)
[![PyPI](https://img.shields.io/pypi/v/openmc-regular-mesh-plotter?color=brightgreen&label=pypi&logo=grebrightgreenen&logoColor=green)](https://pypi.org/project/openmc-regular-mesh-plotter/)

[![codecov](https://codecov.io/gh/fusion-energy/openmc_regular_mesh_plotter/branch/main/graph/badge.svg)](https://codecov.io/gh/fusion-energy/openmc_regular_mesh_plotter)

## A minimal Python package that extracts 2D mesh tally results for plotting convenience.
# A minimal Python package that plots slices of OpenMC regular mesh tallies with the model geometry.

This package is deployed on [xsplot.com](https://www.xsplot.com) as part of the ```openmc_plot``` suite of plotting apps
![example regular mesh tally plot 1](https://user-images.githubusercontent.com/8583900/265032335-27463ee9-8960-4f5e-a662-dab0b6cd9fc5.png)

# Local install

Expand All @@ -21,3 +20,7 @@ pip install openmc_regular_mesh_plotter
# Usage

See the [examples folder](https://github.com/fusion-energy/openmc_regular_mesh_plotter/tree/main/examples) for example scripts

# Web App

This package is deployed on [xsplot.com](https://www.xsplot.com) as part of the ```openmc_plot``` suite of plotting apps
10 changes: 6 additions & 4 deletions examples/plot_minimal_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@
my_settings.particles = 5000
my_settings.run_mode = "fixed source"
# Create a DT point source
source = openmc.Source()
try:
source = openmc.IndependentSource()
except:
# work with older versions of openmc
source = openmc.Source()
source.space = openmc.stats.Point((100, 0, 0))
source.angle = openmc.stats.Isotropic()
source.energy = openmc.stats.Discrete([14e6], [1])
Expand Down Expand Up @@ -76,9 +80,7 @@
outline=True, # enables an outline around the geometry
geometry=my_geometry,
outline_by="material",
colorbar_kwargs={
"label": r"Heating $\\MJcm^{-3}s^{-1}$"
}, # labels support latex formatting
colorbar_kwargs={"label": "Heating MJ/cm3/s"},
outline_kwargs={
"colors": "grey",
"linewidths": 2,
Expand Down
160 changes: 160 additions & 0 deletions examples/plot_sweep_through_slice_indexes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# this example is used to make the animation in the readme.
# It is also set up to accept any geometry and the mesh tally will adapt to the geometry dimensions


import openmc
import numpy as np
from matplotlib.colors import LogNorm
from openmc_regular_mesh_plotter import plot_mesh_tally
from matplotlib import cm

# MATERIALS

breeder_material = openmc.Material() # Pb84.2Li15.8
breeder_material.add_element("Pb", 84.2, percent_type="ao")
breeder_material.add_element(
"Li",
15.8,
percent_type="ao",
enrichment=7.0,
enrichment_target="Li6",
enrichment_type="ao",
) # natural enrichment = 7% Li6
breeder_material.set_density("atom/b-cm", 3.2720171e-2) # around 11 g/cm3

copper_material = openmc.Material()
copper_material.set_density("g/cm3", 8.5)
copper_material.add_element("Cu", 1.0)

eurofer_material = openmc.Material()
eurofer_material.set_density("g/cm3", 7.75)
eurofer_material.add_element("Fe", 89.067, percent_type="wo")

my_materials = openmc.Materials([breeder_material, eurofer_material, copper_material])


# GEOMETRY

# surfaces
central_sol_surface = openmc.ZCylinder(r=100)
central_shield_outer_surface = openmc.ZCylinder(r=110)
vessel_inner_surface = openmc.Sphere(r=500)
first_wall_outer_surface = openmc.Sphere(r=510)
breeder_blanket_outer_surface = openmc.Sphere(r=610, boundary_type="vacuum")
# regions
central_sol_region = -central_sol_surface & -breeder_blanket_outer_surface
central_shield_region = (
+central_sol_surface
& -central_shield_outer_surface
& -breeder_blanket_outer_surface
)
inner_vessel_region = -vessel_inner_surface & +central_shield_outer_surface
first_wall_region = -first_wall_outer_surface & +vessel_inner_surface
breeder_blanket_region = (
+first_wall_outer_surface
& -breeder_blanket_outer_surface
& +central_shield_outer_surface
)
# cells
central_sol_cell = openmc.Cell(region=central_sol_region)
central_shield_cell = openmc.Cell(region=central_shield_region)
inner_vessel_cell = openmc.Cell(region=inner_vessel_region)
first_wall_cell = openmc.Cell(region=first_wall_region)
breeder_blanket_cell = openmc.Cell(region=breeder_blanket_region)
# filling cells with materials
central_sol_cell.fill = copper_material
first_wall_cell.fill = eurofer_material
central_shield_cell.fill = eurofer_material
breeder_blanket_cell.fill = breeder_material

my_geometry = openmc.Geometry(
[
central_sol_cell,
central_shield_cell,
inner_vessel_cell,
first_wall_cell,
breeder_blanket_cell,
]
)

# source
# work with older versions of openmc
try:
source = openmc.IndependentSource()
except:
source = openmc.Source()
source.angle = openmc.stats.Isotropic()
source.energy = openmc.stats.Discrete([14e6], [1])
radius = openmc.stats.Discrete([150], [1])
z_values = openmc.stats.Discrete([300], [1])
angle = openmc.stats.Uniform(a=0.0, b=2 * 3.14159265359)
source.space = openmc.stats.CylindricalIndependent(
r=radius, phi=angle, z=z_values, origin=(0.0, 0.0, 0.0)
)

# Instantiate a Settings object
my_settings = openmc.Settings()
my_settings.output = {"tallies": False}
my_settings.batches = 2
my_settings.particles = (
50000 # increase this to 5000000 to make the same plot as the readme
)
my_settings.run_mode = "fixed source"
my_settings.source = source

# tallies
bb = my_geometry.bounding_box
wedge_length = 40 # set to 4 to make plot from readme
# this just makes the number of mesh voxels in each dimension proportional to the size of the geometry in that dimension.
# this means we get cube shaped voxels instead of stretched out rectangles
dimension = [
int(bb.width[0] / wedge_length),
int(bb.width[1] / wedge_length),
int(bb.width[2] / wedge_length),
]
mesh = openmc.RegularMesh().from_domain(my_geometry, dimension=dimension)
mesh_filter = openmc.MeshFilter(mesh)
mesh_tally = openmc.Tally(name="mesh_tally")
mesh_tally.filters = [mesh_filter]
mesh_tally.scores = ["(n,Xt)"] # tritium production
my_tallies = openmc.Tallies([mesh_tally])

model = openmc.Model(my_geometry, my_materials, my_settings, my_tallies)

statepoint_filename = model.run()

# makes use of a context manager "with" to automatically close the statepoint file
with openmc.StatePoint(statepoint_filename) as statepoint:
my_mesh_tally_result = statepoint.get_tally(name="mesh_tally")

# set the same color range across all the plots
data = my_mesh_tally_result.mean.flatten()
lower_limit = np.min(data[np.nonzero(data)])
upper_limit = np.max(data[np.nonzero(data)])

for slice_index in range(0, mesh.dimension[1]):
plot = plot_mesh_tally(
tally=my_mesh_tally_result,
basis="xz",
slice_index=slice_index,
outline=True, # enables an outline around the geometry
geometry=my_geometry,
outline_by="cell",
pixels=80000, # double the default pixels to get a better resolution on the geometry outline curve
outline_kwargs={
"colors": "green",
"linewidths": 2,
}, # setting the outline color and thickness, otherwise this defaults to black and 1
norm=LogNorm(vmin=lower_limit, vmax=upper_limit), # log scale
volume_normalization=False,
# colorbar=False, removing color bar from plot
cmap=cm.get_cmap("gnuplot"), # color map contrasts with outline color
)

# adding a title to the plot
plot.title.set_text(f"Slice {slice_index}.")
plot.figure.savefig(f"plot_slice_index_{str(slice_index).zfill(4)}.png")

import os

os.system("convert -delay 20 plot_slice*.png animated_openmc_regular_mesh_tally.gif")
12 changes: 9 additions & 3 deletions examples/plot_with_custom_color_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from matplotlib.colors import LogNorm
from openmc_regular_mesh_plotter import plot_mesh_tally
from matplotlib import cm
import matplotlib.pyplot as plt


# materials
mat_concrete = openmc.Material()
Expand Down Expand Up @@ -129,13 +131,17 @@
# all (100%) of source particles are 2.5MeV energy
energy = openmc.stats.Discrete([2.5e6], [1.0])

source = openmc.IndependentSource(space=space, angle=angle, energy=energy)
# work with older versions of openmc
try:
source = openmc.IndependentSource(space=space, angle=angle, energy=energy)
except:
source = openmc.Source(space=space, angle=angle, energy=energy)
source.particle = "neutron"
# Instantiate a Settings object
my_settings = openmc.Settings()
my_settings.output = {"tallies": False}
my_settings.batches = 2
my_settings.particles = 500000000 # set this to 500000000 to get a full image
my_settings.particles = 50 # set this to 500000000 to get a full image
my_settings.run_mode = "fixed source"
my_settings.source = source

Expand Down Expand Up @@ -186,7 +192,7 @@
"colors": "darkgrey",
"linewidths": 2,
}, # setting the outline color and thickness, otherwise this defaults to black and 1
norm=LogNorm(), # log scale
norm=LogNorm(vmin=1e-2, vmax=1e8), # log scale
scaling_factor=1e10, # multiplies the tally result by scaling_factor which is source strength (neutrons per second)
volume_normalization=True,
cmap=cmap,
Expand Down
9 changes: 0 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ classifiers = [
dependencies = [
"numpy>=1.21.1",
"matplotlib>=3.4.2",
"trimesh",
"shapely",
"scipy",
"pandas",
"dagmc_geometry_slice_plotter",
"openmc_tally_unit_converter",
"setuptools_scm",
]
dynamic = ["version"]
Expand All @@ -38,9 +32,6 @@ write_to = "src/openmc_regular_mesh_plotter/_version.py"
[project.optional-dependencies]
tests = [
"pytest",
"pytest-cov>=2.12.1",
"openmc_plasma_source",
"openmc_regular_mesh_plotter",
]

[project.urls]
Expand Down
11 changes: 9 additions & 2 deletions src/openmc_regular_mesh_plotter/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@
import openmc.checkvalue as cv
import matplotlib.pyplot as plt

plt.rcParams["text.usetex"] = True
from packaging import version

if version.parse(openmc.__version__) < version.parse("0.13.3"):
msg = (
"openmc_regular_mesh_plotter package requires OpenMC version 0.13.4 "
f"or newer. You currently have OpenMC version {openmc.__version__}"
)
raise ValueError(msg)

_BASES = ["xy", "xz", "yz"]

Expand Down Expand Up @@ -52,7 +59,7 @@ def plot_mesh_tally(
value : str
A string for the type of value to return - 'mean' (default),
'std_dev', 'rel_err', 'sum', or 'sum_sq' are accepted
outline : tuple
outline : True
If set then an outline will be added to the plot. The outline can be
by cell or by material.
outline_by : {'cell', 'material'}
Expand Down
9 changes: 7 additions & 2 deletions tests/test_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@ def test_plot_mesh_tally():
cell2.fill = mat1
geom = openmc.Geometry([cell1, cell2])

source = openmc.IndependentSource()
# work with older versions of openmc
try:
source = openmc.IndependentSource()
except:
source = openmc.Source()
source.angle = openmc.stats.Isotropic()
source.energy = openmc.stats.Discrete([14e6], [1])
# puts the source in the center of the RectangularParallelepiped
source.space = openmc.stats.Point(cell2.bounding_box.center)
source.space = openmc.stats.Point([-25.0, 25.0, 25.0])
# newer versions of openmc support cell2.bounding_box.center

sett = openmc.Settings()
sett.batches = 2
Expand Down