openmc-dev / openmc

OpenMC Monte Carlo Code
https://docs.openmc.org
Other
699 stars 444 forks source link

Final step in depletion being written to depletion_results.h5 regardless of filename given to integrator #2968

Closed gridley closed 1 week ago

gridley commented 2 weeks ago

Bug Description

The last step always tries to write to an h5 file called depletion_results.h5, even if a user gave something like my_decay.h5 to Integrator.integrate. This is because the kwarg for the file name is written at all steps but the last in the integrator base class.

It throws an exception as a result that looks like:

bigrig% python decay_mwe.py 
/usr/lib/python3/dist-packages/scipy/__init__.py:146: UserWarning: A NumPy version >=1.17.3 and <1.25.0 is required for this version of SciPy (detected version 1.26.2
  warnings.warn(f"A NumPy version >={np_minversion} and <{np_maxversion}"
[openmc.deplete] t=0.0 s, dt=50.0 s, source=0.0
[openmc.deplete] t=50.0 s, dt=50.0 s, source=0.0
[openmc.deplete] t=100.0 s, dt=50.0 s, source=0.0
[openmc.deplete] t=150.0 s, dt=50.0 s, source=0.0
[openmc.deplete] t=200.0 s, dt=50.0 s, source=0.0
[openmc.deplete] t=250.0 s, dt=50.0 s, source=0.0
[openmc.deplete] t=300.0 s, dt=50.0 s, source=0.0
[openmc.deplete] t=350.0 s, dt=50.0 s, source=0.0
[openmc.deplete] t=400.0 s, dt=50.0 s, source=0.0
[openmc.deplete] t=450.0 s, dt=50.0 s, source=0.0
[openmc.deplete] t=500.0 (final operator evaluation)
Traceback (most recent call last):
  File "/home/gavin/Scratch/decay_mwe.py", line 28, in <module>
    integ.integrate(path='decaystep.h5')
  File "/home/gavin/Code/openmc/openmc/deplete/abc.py", line 850, in integrate
    StepResult.save(self.operator, [n], res_list, [t, t],
  File "/home/gavin/Code/openmc/openmc/deplete/stepresult.py", line 570, in save
    results.export_to_hdf5(path, step_ind)
  File "/home/gavin/Code/openmc/openmc/deplete/stepresult.py", line 271, in export_to_hdf5
    res._to_hdf5(handle, step, parallel=False)
  File "/home/gavin/Code/openmc/openmc/deplete/stepresult.py", line 426, in _to_hdf5
    number_dset[index, i, low:high+1] = self.data[i]
  File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
  File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
  File "/home/gavin/.local/lib/python3.10/site-packages/h5py/_hl/dataset.py", line 997, in __setitem__
    mspace = h5s.create_simple(selection.expand_shape(mshape))
  File "/home/gavin/.local/lib/python3.10/site-packages/h5py/_hl/selections.py", line 264, in expand_shape
    raise TypeError("Can't broadcast %s -> %s" % (source_shape, self.array_shape))  # array shape
TypeError: Can't broadcast (1, 3820) -> (1, 3819)

Steps to Reproduce

See the MWE in #2966 and set the path as follows:

integ.integrate(path='decaystep.h5')

results = openmc.deplete.Results('decaystep.h5')

Environment

Does not matter.