Can't see the result after running the code

Hello everyone,

I’m trying to get the tritium production and the code runs sucessfully but I can’t read the result, I try to print it using this line: print('The tritium breeding by lithium 6 is ', tally.scores), it gives a result of zero.

But it doesn’t give me the value. Here’s my script and a screenshot of the result:

import openmc
%matplotlib inline
from IPython.display import Image
import numpy as np
import matplotlib.pyplot as plt
!rm summary.h5
!rm statepoint..h5
settings = openmc.Settings()
settings.particles = 500
settings.batches = 10
settings.inactive = 0
energy_dist = openmc.stats.Discrete([14.5e6], [1.0]) # energies, probabilities
source = openmc.Source(energy=energy_dist)
source = openmc.Source()
source.space = openmc.stats.Point((0, 0, 0))
source.angle = openmc.stats.Isotropic()
source.energy = openmc.stats.Discrete([14.5e6], [1.0])
settings.source = source
settings.source = source
settings.run_mode = ‘fixed source’
settings.export_to_xml()
lithium = openmc.Material(1, “lithium”)
lithium.add_element(‘Li’, 6.0)
lithium.set_density(‘g/cm3’, 0.534)
mats = openmc.Materials([lithium])
mats.export_to_xml()
sph = openmc.Sphere(r=16, boundary_type=‘reflective’)
inside_sph = -sph
outside_sph = +sph
sph_2 = openmc.Sphere(r=15, boundary_type=‘reflective’)
inside_sph_2 = -sph_2
outside_sph_2 = +sph_2
spherical_shell = -sph & +sph_2
cell = openmc.Cell(region=spherical_shell)
cell.fill = lithium
outside_sph = openmc.Sphere(r=17, boundary_type=‘vacuum’)
universe = openmc.Universe(cells=[cell, empty_cell])
empty_cell = openmc.Cell(region=-sph_2)
universe.plot(width = (40.0, 40.0), colors={cell: ‘green’})
geometry = openmc.Geometry(universe)
geometry.export_to_xml()
cell_filter = openmc.CellFilter([cell])
energy_filter = openmc.EnergyFilter([14.5e6])
tally = openmc.Tally(name=‘breeding’)
tally.filters = [cell_filter, energy_filter]
tallies_file = openmc.Tallies()
tallies_file.append(tally)
tally.scores = [‘H3-production’]
tallies_file.export_to_xml()
model = openmc.model.Model(geometry, mats, settings, tallies_file)
!rm summary.h5
!rm statepoint.
.h5
sp_filename = model.run()
print('The tritium breeding by lithium 6 is ', tally.scores)
with openmc.StatePoint(“statepoint.10.h5”) as sp:
k_eff = sp.keff

Thank you so much for your help!

1 Like

Thanks for posting

I would be tempted to remove the reflective surface on the spheres.

sph_2 = openmc.Sphere(r=15, boundary_type=‘reflective’)

Could be changed to

sph_2 = openmc.Sphere(r=15)

1 Like

I think you have not extracted tally results from statepoint file before printing it out.
This line "print('The tritium breeding by lithium 6 is ', tally.scores) " will never tell the value but the string “H3-production” itself.

A brief example could be like:

sp = openmc.StatePoint(sp_filename)
tbr_tally = sp.get_tally(name=‘breeding’)
df = tbr_tally.get_pandas_dataframe()
tbr_tally_result = (df[‘mean’].sum())
print('The tritium breeding by lithium 6 is ', tbr_tally_result)

1 Like

Thank you a lot for pointing this out, I actually only put it because I get this error, is there another way to fix it?

Thank you so much for your help! I used the lines you suggested and I got this error:

The outermost surface could be assigned a vacuum boundary to fix the no boundary conditions found error

sph = openmc.Sphere(r=16, boundary_type=‘vacuum’)

I tried it and it gave me this error, I tied refreshing the kernal but it kept showing this error:

I guess there is something wrong in the modeling. Here is the script that I can run for your reference.

import openmc
#%matplotlib inline
#from IPython.display import Image
import numpy as np
import matplotlib.pyplot as plt
#!rm summary.h5
#!rm statepoint..h5
settings = openmc.Settings()
settings.particles = 1000
settings.batches = 15
settings.inactive = 5
energy_dist = openmc.stats.Discrete([14.5e6], [1.0]) # energies, probabilities
source = openmc.Source(energy=energy_dist)
source = openmc.Source()
source.space = openmc.stats.Point((0, 0, 0))
source.angle = openmc.stats.Isotropic()
source.energy = openmc.stats.Discrete([14.5e6], [1.0])
settings.source = source
settings.run_mode = 'fixed source'
settings.export_to_xml()
#
lithium = openmc.Material(1, "lithium")
lithium.add_element("Li", 6.0)
lithium.set_density("g/cm3", 0.534)
mats = openmc.Materials([lithium])
mats.export_to_xml()
#
sph = openmc.Sphere(r=16, boundary_type="reflective")
cell = openmc.Cell()
cell.region=-sph
cell.fill = lithium
universe = openmc.Universe(cells=[cell])
#universe.plot(width = (40.0, 40.0), colors={cell: "green"})
geometry = openmc.Geometry(universe)
geometry.export_to_xml()
cell_filter = openmc.CellFilter([cell])
energy_filter = openmc.EnergyFilter([14.5e6])
tally = openmc.Tally(name="breeding")
tally.filters = [cell_filter]
tallies_file = openmc.Tallies()
tallies_file.append(tally)
tally.scores = ["H3-production"]
tallies_file.export_to_xml()
#
model = openmc.model.Model(geometry, mats, settings, tallies_file)
#!rm summary.h5
#!rm statepoint..h5
sp_filename = model.run()
#
sp = openmc.StatePoint(sp_filename)
#
# access the tally using pandas dataframes
tbr_tally = sp.get_tally(name='breeding')
df = tbr_tally.get_pandas_dataframe()

tbr_tally_result = (df['mean'].sum())
tbr_tally_std_dev = df['std. dev.'].sum()/df['mean'].sum()
    
print('The tritium breeding by lithium 6 is ', tbr_tally_result)
1 Like

Thank you so much for your help! It did work for me and I got the tritum ratio, I’m trying to create a spherical shell and I added a smaller sphere and an empty cell to represent the vacuum and I get this error, here’s the script, too:

import openmc
#%matplotlib inline
#from IPython.display import Image
import numpy as np
import matplotlib.pyplot as plt
#!rm summary.h5
#!rm statepoint…h5
settings = openmc.Settings()
settings.particles = 1000
settings.batches = 15
settings.inactive = 5
energy_dist = openmc.stats.Discrete([14.5e6], [1.0]) # energies, probabilities
source = openmc.Source(energy=energy_dist)
source = openmc.Source()
source.space = openmc.stats.Point((0, 0, 0))
source.angle = openmc.stats.Isotropic()
source.energy = openmc.stats.Discrete([14.5e6], [1.0])
settings.source = source
settings.run_mode = ‘fixed source’
settings.export_to_xml()

lithium = openmc.Material(1, “lithium”)
lithium.add_element(“Li”, 6.0)
lithium.set_density(“g/cm3”, 0.534)
mats = openmc.Materials([lithium])
mats.export_to_xml()

sph = openmc.Sphere(r=16, boundary_type=“reflective”)
sph_2 = openmc.Sphere(r=15, boundary_type=“reflective”)
space = openmc.Sphere(r=17, boundary_type=“vacuum”)

cell.region=-sph & +sph_2
cell.fill = lithium
universe = openmc.Universe(cells=[cell])
#universe.plot(width = (40.0, 40.0), colors={cell: “green”})
geometry = openmc.Geometry(universe)
geometry.export_to_xml()
cell_filter = openmc.CellFilter([cell])
energy_filter = openmc.EnergyFilter([14.5e6])
tally = openmc.Tally(name=“breeding”)
tally.filters = [cell_filter]
tallies_file = openmc.Tallies()
tallies_file.append(tally)
tally.scores = [“H3-production”]
tallies_file.export_to_xml()

model = openmc.model.Model(geometry, mats, settings, tallies_file)
#!rm summary.h5
#!rm statepoint…h5
sp_filename = model.run()

sp = openmc.StatePoint(sp_filename)

access the tally using pandas dataframes

tbr_tally = sp.get_tally(name=‘breeding’)
df = tbr_tally.get_pandas_dataframe()

tbr_tally_result = (df[‘mean’].sum())
tbr_tally_std_dev = df[‘std. dev.’].sum()/df[‘mean’].sum()

print('The tritium breeding by lithium 6 is ', tbr_tally_result)
with openmc.StatePoint(‘statepoint.15.h5’) as sp:
k_eff = sp.keff

Thank you so much for your help!

It does not make any sense to create a geometry like this:
a sphere with reflective boundary condition and surrounded by another sphere with reflective boundary condition and then surrounded by vacuum sphere. A neutron will never across the surface with reflective boundary condition.

How can I define the vacuum outside of the shell? I edited the geometry to this but still you mean I should define the vacuum differently?

sph = openmc.Sphere(r=16)
sph_2 = openmc.Sphere(r=15)
space = openmc.Sphere(r=17, boundary_type=“vacuum”)

shell =-sph & +sph
shell = openmc.Cell(region=shell)
shell.fill = lithium
universe = openmc.Universe(cells=[shell])

This is the error I get when I don’t define the reflective boundary condition:

I edited to this and I get this error:
sph = openmc.Sphere(r=16,boundary_type=“vacuum”)
sph_2 = openmc.Sphere(r=15)

shell =-sph & +sph_2
outside_shell = +shell & -sph_2
shell = openmc.Cell(region=shell)
shell.fill = lithium
universe = openmc.Universe(cells=[shell])
empty_cell = openmc.Cell(region=outside_shell)
#universe.plot(width = (40.0, 40.0), colors={cell: “green”})
geometry = openmc.Geometry(universe)
geometry.export_to_xml()

OpenMC does not need to define the vacuum outer space. So if I understood correctly, you just need to model a spherical shell without inner or outer space like this:

sph_1 = openmc.Sphere(r=15, boundary_type="reflective")
sph_2 = openmc.Sphere(r=16, boundary_type="reflective")
shell = openmc.Cell(region=+sph_1  & -sph_2 )
shell.fill = lithium
universe = openmc.Universe(cells=[shell])

Thank you so much for your help! I tried but when I don’t define a vacuum I get this error, I saw a fix that I should define an empty cell and editted to these lines but I still get the same error:

sph_1 = openmc.Sphere(r=15, boundary_type=“reflective”)
sph_2 = openmc.Sphere(r=16, boundary_type=“reflective”)
shell = openmc.Cell(region=+sph_1 & -sph_2 )
shell.fill = lithium
empty_cell = openmc.Sphere(r=17)
empty_cell=openmc.Cell(region=+sph_2)
universe = openmc.Universe(cells=[shell, empty_cell])
#universe.plot(width = (40.0, 40.0), colors={cell: “green”})
geometry = openmc.Geometry(universe)
geometry.export_to_xml()
cell_filter = openmc.CellFilter([shell, empty_cell])

The source you defined is located at (0,0,0), where there is no defined geometry in this modeling. You should modify the source according to the geometry.

I edited the empty_cell to include the inside of the shell but the model got me a zero, how can I include the source in the geometry?

empty_cell = openmc.Sphere(r=15)
empty_cell=openmc.Cell(region=-sph_1)
universe = openmc.Universe(cells=[shell, empty_cell])

I finally got it after editing the lines to these:

sph_1 = openmc.Sphere(r=15)
sph_2 = openmc.Sphere(r=16, boundary_type=“vacuum”)
shell = openmc.Cell(region=+sph_1 & -sph_2 )
shell.fill = lithium
empty_cell = openmc.Sphere(r=15)
empty_cell=openmc.Cell(region=-sph_1)
universe = openmc.Universe(cells=[shell, empty_cell])

Thank you so much for your help!

sph_1 is empty_cell?
I think there should be no problem. The very high leakage is caused by the vacuum boundary condition of sph_2.

The empty cell is the empty space from the origin to sph_1, I added it to be a geometry to the empty space inside. And the vacuum condition for sph_2 is to avoid the no boundary error, I will make some trails to avoid this error some other way.