diff --git a/README.md b/README.md index 7b04a1a..0c50e2c 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -A Python package for plotting the locations, directions or energy distributions of OpenMC source particles +A Python package for plotting the locations, directions or energy distributions of OpenMC sources. # Installation @@ -7,31 +7,19 @@ A Python package for plotting the locations, directions or energy distributions pip install openmc_source_plotter ``` -temporary fix -For position and direction plotting with fixed source sources it is currently -necessary to use openmc version 0.11 and also to point the ```openmc_exec``` -path to the openmc executable. - -This can be installed with: -```bash -conda install -c conda-forge openmc=0.11 -``` - - # Features The package provides functions to: -- create the initial_source.h5 for a given openmc.source - extract the locations, directions and energy of particles -- visualise an openmc.source with respect to: +- visualise an ```openmc.Source``` with respect to: - direction - energy - location # Example plots -Plot of energy distribution of the source +## Plot of energy distribution of the source ```python import openmc_source_plotter as osp @@ -47,8 +35,7 @@ my_source.energy = openmc.stats.Muir(e0=14080000.0, m_rat=5.0, kt=20000.0) # plots the particle energy distribution plot = osp.plot_source_energy( source=my_source, - number_of_particles=2000, - energy_bins=np.linspace(0, 20e6, 100), + n_samples=2000, ) plot.show() @@ -56,7 +43,7 @@ plot.show() ![openmc particle source energy plot](https://user-images.githubusercontent.com/8583900/143615694-a3578115-f8a2-4971-bf26-458177b4f113.png) -Plot of energy distribution of two sources +## Plot of energy distribution of two sources ```python import openmc_source_plotter as osp @@ -77,8 +64,7 @@ my_dd_source.energy = openmc.stats.Muir(e0=2080000.0, m_rat=2.0, kt=20000.0) # plots the particle energy distribution plot = osp.plot_source_energy( source=[my_dt_source, my_dd_source], - number_of_particles=10000, - energy_bins=np.linspace(0, 20e6, 100), + n_samples=10000, ) plot.show() @@ -86,6 +72,8 @@ plot.show() ![openmc particle source energy plot](https://user-images.githubusercontent.com/8583900/151376414-fb1555eb-61d1-4c82-bc4d-a05f62819c5d.png) +## Plot direction of particles + ```python import openmc_source_plotter as osp import openmc @@ -99,14 +87,47 @@ my_source.angle = openmc.stats.Isotropic() # plots the particle energy distribution plot = osp.plot_source_direction( source=my_source, - number_of_particles=100, - openmc_exec="/home/jshim/miniconda3/envs/openmc_0_11_0/bin/openmc", + n_samples=100, ) plot.show() ``` ![openmc particle source direction plot](https://user-images.githubusercontent.com/8583900/143615706-3b3a8467-0233-42d6-a66c-d536c80a01d8.png) + +## Plot position of particles + +```python + +import openmc_source_plotter as osp +import openmc + +# initialises a new source object +my_source = openmc.Source() + +# the distribution of radius is just a single value +radius = openmc.stats.Discrete([10], [1]) + +# the distribution of source z values is just a single value +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.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) +) + +# plots the particle energy distribution +plot = osp.plot_source_position(source=my_source) + +plot.show() + +``` + +![openmc particle source position plot](https://user-images.githubusercontent.com/8583900/179424915-bee56a87-6214-46ef-8625-92b8f4cbd1b3.png) + # Usage See the [examples folder](https://github.com/fusion-energy/openmc_source_plotter/tree/main/examples) for example usage scripts. diff --git a/openmc_source_plotter/core.py b/openmc_source_plotter/core.py index fce31d7..ecc766b 100644 --- a/openmc_source_plotter/core.py +++ b/openmc_source_plotter/core.py @@ -16,19 +16,21 @@ def sample_initial_particles(source: openmc.source, n_samples=1000, prn_seed=Non settings = openmc.Settings() settings.particles = 1 settings.batches = 1 + settings.source = source settings.export_to_xml() materials = openmc.Materials() materials.export_to_xml() - sph = openmc.Sphere(r=1, boundary_type="vacuum") + sph = openmc.Sphere(r=9999999999, boundary_type="vacuum") cell = openmc.Cell(region=-sph) geometry = openmc.Geometry([cell]) geometry.export_to_xml() - # model.geometry = openmc.Geometry([cell]) - # model = openmc.Model() + # # model = openmc.Model() + # model.geometry = geometry + # model.materials = geometry openmc.lib.init() particles = openmc.lib.sample_external_source( @@ -58,7 +60,7 @@ def plot_source_energy( for single_source in source: - e_values = single_source.energy.sample(n_samples=n_samples) + e_values = single_source.energy.sample(n_samples=n_samples, prn_seed=prn_seed) # Calculate pdf for source energies probability, bin_edges = np.histogram(e_values, bins="auto", density=True) @@ -104,6 +106,7 @@ def plot_source_position( for single_source in source: data = sample_initial_particles(single_source, n_samples, prn_seed) + print([p.r for p in data]) text = ["Energy = " + str(particle.E) + " eV" for particle in data]