Skip to content

Commit

Permalink
Merge pull request #9 from cnerg/anu1217-py
Browse files Browse the repository at this point in the history
Added Spherical Shell Python script and associated files
  • Loading branch information
gonuke authored May 14, 2024
2 parents 0024a1d + d0efcb2 commit 4ebd379
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 0 deletions.
Binary file added SphericalShell/Neutron_flux_vs_energy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions SphericalShell/SS_h5_Reader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import matplotlib.pyplot as plt
import openmc


# Get results from statepoint
with openmc.StatePoint('statepoint.10.h5') as sp:
t = sp.get_tally(name="Flux spectrum")
k = sp.get_tally(name="Neutron tally")

# Get the energies from the energy filter
energy_filter = t.filters[0]
energies = energy_filter.bins[:, 0]

# Get the flux values
mean = t.get_values(value='mean').ravel()

#Flux/elastic/absorption tallies:
tal = k.get_values(value='mean').ravel()
print(tal)

# Plot flux spectrum
fix, ax = plt.subplots()
ax.loglog(energies, mean, drawstyle='steps-post')
ax.set_xlabel('Energy [eV]')
ax.set_ylabel('Flux [neutron-cm/source]')
ax.grid(True, which='both')
plt.savefig('Neutron_flux_vs_energy.png')
plt.show()
70 changes: 70 additions & 0 deletions SphericalShell/SphericalShell.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# -*- coding: utf-8 -*-
"""
Created on Thu Feb 8 08:16:12 2024
@author: Anupama Rajendra
"""
import openmc
import numpy as np
#import tkinter as tk

# Create materials & export to XML:
#Simulating tungsten shell:
W = openmc.Material(name='W_Shell')
W.set_density('g/cm3', 19.28)
W.add_element('W', 1.0)
materials = openmc.Materials([W])
materials.export_to_xml()

# Create geometry
#Spherical shell:
R_1= openmc.Sphere(r=1000) #sphere of radius 1000cm
inside_sphere_1 = -R_1
outside_sphere_1 = +R_1
R_2 = openmc.Sphere(r=1005, boundary_type='vacuum')
inside_sphere_2 = -R_2
outside_sphere_2 = +R_2
R_3 = outside_sphere_1 & inside_sphere_2 #filled with tungsten

# Mapping materials to geometry:
Void = openmc.Cell(fill=None, region = inside_sphere_1)
Shell = openmc.Cell(fill=W, region=R_3)
geometry = openmc.Geometry([Void, Shell])
geometry.export_to_xml()


# # Source distribution:
PointSource = openmc.stats.Point(xyz=(0.0, 0.0, 0.0))
Prob = openmc.stats.Discrete(14E+06, 1.0)

# Assign simulation settings
settings = openmc.Settings()
settings.batches = 10
settings.inactive = 1
settings.particles = 100000
settings.source = openmc.Source(space=PointSource, energy=Prob, strength = 1.0, particle = 'neutron')
settings.run_mode = 'fixed source'
settings.export_to_xml()

# Define tallies
neutron_tally = openmc.Tally(name="Neutron tally")
neutron_tally.scores = ['flux', 'elastic', 'absorption']
# Implementing filter for neutron tally through W shell
cell_filter = openmc.CellFilter([Shell])
neutron_tally.filters = [cell_filter]

# Creating a tally to get the flux energy spectrum.
# An energy filter is created to assign to the flux tally.
e_min, e_max = 5e2, 14.001e6
groups = 500
energies = np.logspace(np.log10(e_min), np.log10(e_max), groups + 1)
energy_filter = openmc.EnergyFilter(energies)

spectrum_tally = openmc.Tally(name="Flux spectrum")
# Implementing energy and cell filters for flux spectrum tally
spectrum_tally.filters = [energy_filter, cell_filter]
spectrum_tally.scores = ['flux']

# Collecting and exporting tallies to .xml
tallies = openmc.Tallies([neutron_tally, spectrum_tally])
tallies.export_to_xml()
Binary file added SphericalShell/statepoint.10.h5
Binary file not shown.

0 comments on commit 4ebd379

Please sign in to comment.