Skip to content

Commit

Permalink
[skip ci] Apply formatting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
shimwell authored and actions-user committed Nov 25, 2021
1 parent f69b498 commit b363756
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 59 deletions.
3 changes: 1 addition & 2 deletions examples/example_get_particle_data.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import openmc_source_plotter as osp
import openmc

Expand All @@ -18,7 +17,7 @@
initial_source_filename = osp.create_initial_particles(
source=my_source,
number_of_particles=10,
openmc_exec='/home/jshim/miniconda3/envs/openmc_0_11_0/bin/openmc'
openmc_exec="/home/jshim/miniconda3/envs/openmc_0_11_0/bin/openmc",
)

# gets the particle corrdiantes, energy and direction
Expand Down
3 changes: 1 addition & 2 deletions examples/example_plot_direction_from_initial_source.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import openmc_source_plotter as osp
import openmc
import numpy as np
Expand All @@ -13,7 +12,7 @@
initial_source_filename = osp.create_initial_particles(
source=my_source,
number_of_particles=100,
openmc_exec='/home/jshim/miniconda3/envs/openmc_0_11_0/bin/openmc'
openmc_exec="/home/jshim/miniconda3/envs/openmc_0_11_0/bin/openmc",
)

# plots the particle energy distribution
Expand Down
7 changes: 3 additions & 4 deletions examples/example_plot_energy_from_initial_source.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import openmc_source_plotter as osp
import openmc
import numpy as np
Expand All @@ -19,12 +18,12 @@
initial_source_filename = osp.create_initial_particles(
source=my_source,
number_of_particles=10,
openmc_exec='/home/jshim/miniconda3/envs/openmc_0_11_0/bin/openmc'
openmc_exec="/home/jshim/miniconda3/envs/openmc_0_11_0/bin/openmc",
)

# plots the particle energy distribution
plot = osp.plot_energy_from_initial_source(
energy_bins=np.linspace(0, 20e6, 50),
input_filename=initial_source_filename)
energy_bins=np.linspace(0, 20e6, 50), input_filename=initial_source_filename
)

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

import openmc_source_plotter as osp
import openmc
import numpy as np
Expand All @@ -13,17 +12,19 @@
z_values = openmc.stats.Discrete([0], [1])

# the distribution of source azimuthal angles values is a uniform distribution between 0 and 2 Pi
angle = openmc.stats.Uniform(a=0., b=2* 3.14159265359)
angle = openmc.stats.Uniform(a=0.0, b=2 * 3.14159265359)

# this makes the ring source using the three distributions and a radius
my_source.space = openmc.stats.CylindricalIndependent(r=radius, phi=angle, z=z_values, origin=(0.0, 0.0, 0.0))
my_source.space = openmc.stats.CylindricalIndependent(
r=radius, phi=angle, z=z_values, origin=(0.0, 0.0, 0.0)
)


# makes an initial_source.h5 file with details of the particles
initial_source_filename = osp.create_initial_particles(
source=my_source,
number_of_particles=10,
openmc_exec='/home/jshim/miniconda3/envs/openmc_0_11_0/bin/openmc'
openmc_exec="/home/jshim/miniconda3/envs/openmc_0_11_0/bin/openmc",
)

# plots the particle energy distribution
Expand Down
62 changes: 30 additions & 32 deletions openmc_source_plotter/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@


def create_initial_particles(
source: openmc.source,
number_of_particles: int=2000,
openmc_exec='openmc'
)-> str:
source: openmc.source, number_of_particles: int = 2000, openmc_exec="openmc"
) -> str:
"""Accepts an openmc source and creates an initial_source.h5 file that can
be used to find propties of the source particles such as initial x,y,z
coordinates, direction and energy.
Expand All @@ -31,7 +29,7 @@ def create_initial_particles(
number_of_particles: the number of particles to sample
openmc_exec: the path of openmc executable or executable name if it
appears in your system $PATH. Defaults to 'openmc' which will use
the default openmc in your system $PATH environmental variable.
the default openmc in your system $PATH environmental variable.
Returns:
The filename of the initial source file created (initial_source.h5)
"""
Expand All @@ -47,7 +45,7 @@ def create_initial_particles(

# Instantiate a Settings object
settings = openmc.Settings()
settings.run_mode = ("fixed source")
settings.run_mode = "fixed source"
settings.particles = number_of_particles
settings.batches = 1
settings.inactive = 0
Expand All @@ -62,9 +60,8 @@ def create_initial_particles(

return "initial_source.h5"

def get_particle_data(
input_filename: str
):

def get_particle_data(input_filename: str):

f = h5py.File(input_filename, "r")
dset = f["source_bank"]
Expand All @@ -83,28 +80,29 @@ def get_particle_data(
z_values.append(particle[0][2])
x_dir.append(particle[1][0])
y_dir.append(particle[1][1])
z_dir.append(particle[1][2])
z_dir.append(particle[1][2])
e_values.append(particle[2])

return {
'x_values': x_values,
'y_values': y_values,
'z_values': z_values,
'x_dir': x_dir,
'y_dir': y_dir,
'z_dir': z_dir,
'e_values': e_values
"x_values": x_values,
"y_values": y_values,
"z_values": z_values,
"x_dir": x_dir,
"y_dir": y_dir,
"z_dir": z_dir,
"e_values": e_values,
}


def plot_energy_from_initial_source(
energy_bins: np.array=np.linspace(0, 20e6, 50),
input_filename: str = "initial_source.h5"
energy_bins: np.array = np.linspace(0, 20e6, 50),
input_filename: str = "initial_source.h5",
):
"""makes a plot of the energy distribution of the source"""

data = get_particle_data(input_filename)

e_values = data['e_values']
e_values = data["e_values"]

# Calculate pdf for source energies
probability, bin_edges = np.histogram(e_values, energy_bins, density=True)
Expand Down Expand Up @@ -135,21 +133,21 @@ def plot_position_from_initial_source(input_filename="initial_source.h5"):

data = get_particle_data(input_filename)

text = ["Energy = " + str(i) + " eV" for i in data['e_values']]
text = ["Energy = " + str(i) + " eV" for i in data["e_values"]]

fig = go.Figure()

fig.add_trace(
go.Scatter3d(
x=data['x_values'],
y=data['y_values'],
z=data['z_values'],
x=data["x_values"],
y=data["y_values"],
z=data["z_values"],
hovertext=text,
text=text,
mode="markers",
marker={
"size": 2,
"color": data['e_values'],
"color": data["e_values"],
},
)
)
Expand All @@ -170,12 +168,12 @@ def plot_direction_from_initial_source(input_filename="initial_source.h5"):
{
"type": "cone",
"cauto": False,
"x": data['x_values'],
"y": data['y_values'],
"z": data['z_values'],
"u": data['x_dir'],
"v": data['y_dir'],
"w": data['z_dir'],
"x": data["x_values"],
"y": data["y_values"],
"z": data["z_values"],
"u": data["x_dir"],
"v": data["y_dir"],
"w": data["z_dir"],
"cmin": 0,
"cmax": 1,
"anchor": "tail",
Expand Down
27 changes: 12 additions & 15 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,16 @@
url="https://github.com/fusion-energy/openmc_source_plotter",
packages=setuptools.find_packages(),
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',
"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",
],
python_requires='>=3.6',
install_requires=[
"plotly>=5.1.0",
"numpy>=1.21.1",
"h5py"
])
python_requires=">=3.6",
install_requires=["plotly>=5.1.0", "numpy>=1.21.1", "h5py"],
)

0 comments on commit b363756

Please sign in to comment.