Package: openmc-source-plotter
A Python package for plotting the positions, directions or energy distributions of OpenMC sources.InstallationYou will need to have OpenMC version 0.14.0 or newer installed first.pipinstallopenmc_source_plotterFeaturesThe package simply extends the defaultopenmc.IndependentSourceBaseandopenmc.Modelto provides additional functions that:extract the positions, directions and energy of particlesvisualise a source with respect to:directionenergypositionOr just provide the initial particles withsample_initial_particlesExample plotsBelow are some basic examples, for more examples see theexamples folderfor example usage scripts.Plot of energy distribution of the sourceimportopenmcimportopenmc_source_plotter# extends openmc.IndependentSource with plotting functions# initialises a new source objectmy_source=openmc.IndependentSource()# sets the energy distribution to a muir distribution neutrons for DT fusion neutronsmy_source.energy=openmc.stats.muir(e0=14080000.0,m_rat=5.0,kt=20000.0)# plots the particle energy distributionplot=my_source.plot_source_energy(n_samples=2000)plot.show()Plot of energy distribution of two sourcesimportopenmcimportopenmc_source_plotter# extends openmc.IndependentSource with plotting functions# initialises a new source objectmy_dt_source=openmc.IndependentSource()# sets the energy distribution to a muir distribution DT neutronsmy_dt_source.energy=openmc.stats.muir(e0=14080000.0,m_rat=5.0,kt=20000.0)# initialises a new source objectmy_dd_source=openmc.IndependentSource()# sets the energy distribution to a muir distribution DD neutronsmy_dd_source.energy=openmc.stats.muir(e0=2080000.0,m_rat=2.0,kt=20000.0)# plots the particle energy distribution by building on the first plotfigure1=my_dd_source.plot_source_energy(n_samples=10000)figure2=my_dt_source.plot_source_energy(figure=figure1,n_samples=10000)figure2.show()Plot direction of particlesimportopenmcimportopenmc_source_plotter# extends openmc.IndependentSource with plotting functions# initializes a new source objectmy_source=openmc.IndependentSource()# sets the direction to isotropicmy_source.angle=openmc.stats.Isotropic()# plots the particle energy distributionplot=my_source.plot_source_direction(n_samples=200)plot.show()Plot position of particlesimportopenmcimportopenmc_source_plotter# extends openmc.IndependentSource with plotting functions# initialises a new source objectmy_source=openmc.IndependentSource()# the distribution of radius is just a single valueradius=openmc.stats.Discrete([10],[1])# the distribution of source z values is just a single valuez_values=openmc.stats.Discrete([0],[1])# the distribution of source azimuthal angles# values is a uniform distribution between 0 and 2 Piangle=openmc.stats.Uniform(a=0.0,b=2*3.14159265359)# this makes the ring source using the three distributions and a radiusmy_source.space=openmc.stats.CylindricalIndependent(r=radius,phi=angle,z=z_values,origin=(0.0,0.0,0.0))# plots the particle energy distributionplot=my_source.plot_source_position()plot.show()Extract particle objectsA list ofopenmc.Particleobjects can be obtained usingmodel.sample_initial_particles()oropenmc.SourceBase.sample_initial_particles()importopenmcimportopenmc_source_plotter# extents openmc.Model with sample_initial_particles methodsettings=openmc.Settings()settings.particles=1settings.batches=1my_source=openmc.IndependentSource()my_source.energy=openmc.stats.muir(e0=14080000.0,m_rat=5.0,kt=20000.0)settings.source=my_sourcematerials=openmc.Materials()sph=openmc.Sphere(r=100,boundary_type="vacuum")cell=openmc.Cell(region=-sph)geometry=openmc.Geometry([cell])model=openmc.Model(geometry,materials,settings)particles=model.sample_initial_particles(n_samples=10)print(particles)>>>[<SourceParticle:neutronatE=1.440285e+07eV>,<SourceParticle:neutronatE=1.397691e+07eV>,<SourceParticle:neutronatE=1.393681e+07eV>,<SourceParticle:neutronatE=1.470896e+07eV>,<SourceParticle:neutronatE=1.460563e+07eV>,<SourceParticle:neutronatE=1.420684e+07eV>,<SourceParticle:neutronatE=1.413932e+07eV>,<SourceParticle:neutronatE=1.412428e+07eV>,<SourceParticle:neutronatE=1.464779e+07eV>,<SourceParticle:neutronatE=1.391648e+07eV>]print(particles[0].E)>>>1.440285e+07Related packagesTokamak sources can also be plotted using theopenmc-plasma-sourcepackage