fusion-energy / openmc_source_plotter Goto Github PK
View Code? Open in Web Editor NEWA Python package for extracting and plotting the locations, directions, energy distributions of OpenMC source particles
License: MIT License
A Python package for extracting and plotting the locations, directions, energy distributions of OpenMC source particles
License: MIT License
would be good to get an image of for plotly
source locations for a plasma (not currently possible due to version conflict)
source location for ring source (not currently possible due to version conflict)
source energy of muir spectrum
source direction of a point source
openmc version 0.11.0 is used as it writes the initial_source.h5 but it doesn't include the cylindrical source.
Invalid spatial distribution for external source: cylindrical
plt.stem plots lokk quite nice compared to the line plot
because of the size difference in the axis it can often appear as if ring sources are sending particles straight up and down
For example a ring source with a radius of 10 will not show the particles traveling left and right very well
To get the CI working this package needs a Dockerfile
Other dockerfiles I've built might not be working well with mpich and this is why I can't make initial_source.h5 using openmc version 0.12
https://openmc.discourse.group/t/obtaining-initial-source-for-fix-source-mode/1463/2
So the options are to
Perhaps input_filename
could accept a list of h5 files
Then multiple plots could be made on a single axis, this would be useful for the energy plotting function
plot_energy_from_initial_source(
input_filename: List
)
To make the name space the same as OpenMC we can use a monkey patch. Here is the code examples
package code
import openmc
class Source(openmc.Source):
def plot_source_energy(self, n_samples: int = 1000, prn_seed: int = None):
...
openmc.Source = Source # overwrites the openmc class with this extended class
user code
import openmc
import openmc_source_plotter
my_source = openmc.Source()
my_source.plot_source_energy()
MWE:
import openmc_source_plotter as osp
import openmc_plasma_source as ops
import numpy as np
import math
my_source = ops.FusionRingSource(
fuel="DT",
radius=1,
z_placement=1,
angles=(math.radians(-1), math.radians(1)),
)
plot = osp.plot_source_energy(
source=my_source,
number_of_particles=2000,
energy_bins=np.linspace(0, 20e6, 100)
)
Produces:
(base) root@9cd1860b80ad:/home/fusion-neutronics-workflow# python plot_source.py
%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%
############### %%%%%%%%%%%%%%%%%%%%%%%%
################## %%%%%%%%%%%%%%%%%%%%%%%
################### %%%%%%%%%%%%%%%%%%%%%%%
#################### %%%%%%%%%%%%%%%%%%%%%%
##################### %%%%%%%%%%%%%%%%%%%%%
###################### %%%%%%%%%%%%%%%%%%%%
####################### %%%%%%%%%%%%%%%%%%
####################### %%%%%%%%%%%%%%%%%
###################### %%%%%%%%%%%%%%%%%
#################### %%%%%%%%%%%%%%%%%
################# %%%%%%%%%%%%%%%%%
############### %%%%%%%%%%%%%%%%
############ %%%%%%%%%%%%%%%
######## %%%%%%%%%%%%%%
%%%%%%%%%%%
| The OpenMC Monte Carlo Code
Copyright | 2011-2022 MIT, UChicago Argonne LLC, and contributors
License | https://docs.openmc.org/en/latest/license.html
Version | 0.13.0
Git SHA1 | cff247e35785e7236d67ccf64a3401f0fc50a469
Date/Time | 2022-07-08 08:43:41
MPI Processes | 1
OpenMP Threads | 4
Reading settings XML file...
Reading cross sections XML file...
Reading materials XML file...
Reading geometry XML file...
Minimum neutron data temperature: 1.7976931348623157e+308 K
Maximum neutron data temperature: 0 K
Preparing distributed cell instances...
Reading plot XML file...
Writing summary.h5 file...
===============> FIXED SOURCE TRANSPORT SIMULATION <===============
Simulating batch 1
Creating state point statepoint.1.h5...
=======================> TIMING STATISTICS <=======================
Total time for initialization = 1.2467e-01 seconds
Reading cross sections = 7.5700e-05 seconds
Total time in simulation = 2.7996e-02 seconds
Time in transport only = 3.4304e-03 seconds
Time in active batches = 2.7996e-02 seconds
Time accumulating tallies = 1.3000e-06 seconds
Time writing statepoints = 2.4537e-02 seconds
Total time for finalization = 4.5000e-06 seconds
Total time elapsed = 1.5276e-01 seconds
Calculation Rate (active) = 71439 particles/second
============================> RESULTS <============================
WARNING: Could not compute uncertainties -- only one active batch simulated!
Leakage Fraction = 1.00000
Traceback (most recent call last):
File "/opt/conda/lib/python3.9/shutil.py", line 806, in move
os.rename(src, real_dst)
OSError: [Errno 18] Invalid cross-device link: 'initial_source.h5' -> '/tmp/openmc_source_y85xaz55.h5'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/fusion-neutronics-workflow/plot_source.py", line 19, in <module>
plot = osp.plot_source_energy(
File "/opt/conda/lib/python3.9/site-packages/openmc_source_plotter/core.py", line 38, in plot_source_energy
create_initial_particles(
File "/opt/conda/lib/python3.9/site-packages/openmc_source_plotter/utils.py", line 100, in create_initial_particles
shutil.move("initial_source.h5", output_source_filename)
File "/opt/conda/lib/python3.9/shutil.py", line 826, in move
copy_function(src, real_dst)
File "/opt/conda/lib/python3.9/shutil.py", line 435, in copy2
copyfile(src, dst, follow_symlinks=follow_symlinks)
File "/opt/conda/lib/python3.9/shutil.py", line 264, in copyfile
with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst:
FileNotFoundError: [Errno 2] No such file or directory: 'initial_source.h5'
openmc_source_plotter version: current
openmc version 0.13.0
Should I use openmc 0.11 to have this work?
Not sure if intended to be compatible with openmc=0.13.3
. I upgraded to 0.14.0
and error went away.
import openmc
import openmc_source_plotter
--> 230 openmc.SourceBase.sample_initial_particles = sample_initial_particles
231 openmc.model.Model.sample_initial_particles = sample_initial_particles
232 openmc.Model.sample_initial_particles = sample_initial_particles
AttributeError: module 'openmc' has no attribute 'SourceBase'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.