Hello everyone, I get this error when I try to run and I tried the fixes in this post here but they didn’t work for me, what can I do? Thanks a lot for your help.
I tried the fix you suggested and I get thie error, could you help, please? @pshriwise
Hi @Dalia. Thanks for reaching out about this.
We typically see the error
ERROR: Failed to open HDF5 file with mode ‘w’: summary.h5
because an openmc.StatePoint
object is already open in the Python interpreter. We’re working on a way to avoid this issue, but for now I’ll refer you to this thread on the topic:
Along with an explanation of a couple ways to manage this issue:
As for the missing statepoint file you mentioned in your last post, I’m not really sure why that would occur without seeing the rest of your notebook. If you’re still running into problems after trying the solutions in the thread above, if you can share the notebook that would make it easier to diagnose that problem.
Hope this helps!
– Patrick
Thank you so much for your help, I tried these solutions but some didn’t work and the others produced errors, so I’m starting with the fix you suggested, here’s my whole script:
import openmc
%matplotlib inline
from IPython.display import Image
import numpy as np
import matplotlib.pyplot as plt
settings = openmc.Settings()
settings.run_mode = ‘fixed source’
settings.particles = 1
settings.batches = 1
settings.inactive = 0
with openmc.StatePoint(‘statepoint.10.h5’) as sp:
k_eff = sp.keff
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.0, 0.0))
source.angle = openmc.stats.Isotropic()
source.energy = openmc.stats.Discrete([14.5e6], [1.0])
settings.source = source
settings.source = source
settings.output = {
‘tallies’: False,
‘path’: ‘results’
}
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])
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()
openmc.run()
I also got cmake running the line: install cmake, I’m not sure how to use it to solve the problem.
Hi @Dalia.
I should’ve read the error message more carefully. Based on the lines of code you provided above there are a couple issues to address:
-
The directory
results
needs to be created before the OpenMC simulation is run, otherwise OpenMC will not be able to create the HDF5 results files for the simulation. You can do this prior to running your Python script, or you can use the Pythonos
module to check for the directory and create it if it doesn’t exist. -
The script attempts to open an OpenMC statepoint file before the simulation is run. The lines
with openmc.StatePoint("statepoint.10.h5") as sp:
k_eff = sp.keff
need to be moved to the end of your code. Also, the statepoint file name is going to be based on the number of batches run in the simulation, so that filename should really be "statepoint.1.h5"
. I’d recommend running more than one batch, even in fixed source mode, so that tally statistics are computed correctly. This is a holdover from OpenMC originally being intended for eigenvalue problems.
- Finally, you will want to run more than one particle per batch. Right now I’m getting an error related to source site rejection.
Let me know if you have any additional questions as you move forward with your work.
-Patrick
Thank you so much for your help! I put the lines at the end of the code and the statepoint error disappeared but I got the same error:
I’m not sure I understand what I need to do here.
To start, make sure a directory results
exists in the same directory as your notebook. Or remove these lines from the notebook:
settings.output = {
‘tallies’: False,
‘path’: ‘results’
}
The 'path': 'results'
line indicates that OpenMC should place generated files in a directory called “results”. If that directory does not exist, you’ll get the error you’re seeing. here’s the relevant section in the documentation.
Thanks a lot for your help! I finally got a different error, I tried changing the number of particles, and removing the line specifing a fixed source, but it didn’t work, the spatial definition of the external source is the origin, what should I fix here?
Thank you a lot I fixed it using this post:
Thank you really for your help!
You’ll want to make sure your geometry contains the source. Right now it contains a single spherical shell that doesn’t contain the source at (0, 0, 0), so OpenMC is trying to source particles outside the model and failing.
I’m specifying the source at the origin, and the shell is centered at the origin, how can I make sure that’s inside the shell?
You need to either add another cell to the problem that occupies the inside of that sphere or change the current cell’s region.
I added this empty cell for the inside of the shell:
empty_cell = openmc.Cell(region=-sph_2), is that correct?
This line: empty_cell = openmc.Cell(region=-sph_2)
fixed the issue in my case.