openmc icon indicating copy to clipboard operation
openmc copied to clipboard

Bugfix: Can't convert multiple ACE files containing thermal scattering data to HDF5

Open yardasol opened this issue 3 years ago • 0 comments

When using the openmc-ace-to-hdf5 script to convert a single thermal scattering ACE file, it works just fine:

python ../../openmc/scripts/openmc-ace-to-hdf5 acedata/Gra-800.ACE -d ../jeff312_h5
/home/ooblack/projects/openmc/openmc/data/thermal.py:136: UserWarning: Thermal scattering material "gr05" is not recognized. Assigning a name of c_Graphite.
  warn('Thermal scattering material "{}" is not recognized. '
ACE name: gr05
Name: c_Graphite
Converting gr05.32t (ACE) to c_Graphite (HDF5)

however, when I try to convert more than one thermal scattering ACE file, I get the following output:

python ../../openmc/scripts/openmc-ace-to-hdf5 acedata/Gra-1000.ACE acedata/Gra-800.ACE -d ../jeff312_h5
/home/ooblack/projects/openmc/openmc/data/thermal.py:136: UserWarning: Thermal scattering material "gr06" is not recognized. Assigning a name of c_Graphite.
  warn('Thermal scattering material "{}" is not recognized. '
ACE name: gr06
Name: c_Graphite
Converting gr06.32t (ACE) to c_Graphite (HDF5)
/home/ooblack/projects/openmc/openmc/data/thermal.py:136: UserWarning: Thermal scattering material "gr05" is not recognized. Assigning a name of c_Graphite.
  warn('Thermal scattering material "{}" is not recognized. '
Converting gr05.32t (ACE) to c_Graphite (HDF5)
ACE name: gr05
Name: nndc
Self name: {self.name}
Failed to convert gr05.32t: Data provided for an incorrect material.

Notice the error at the end of the output.

What could be causing this? Well, at line 512 in thermal.py, we have the following code block:

         # Check that name matches
         if data.name != self.name:
             raise ValueError('Data provided for an incorrect material.')

So there must be an incompatibility between data.name and self.name.

I added lines to openmc/data/thermal.py beneath lines 512 (Self name), 616 (ACE name), and 621 (Name) to print the appropriate names at each. In the above code block, we can see for all files after the first one, name is now nndc. This will conflict with the previous name set by the first file of c_Graphite.

The root of this error is at line 95 in openmc-ace-to-hdf5:

             else:
                 # Read existing HDF5 file
                 data = cls.from_hdf5(converted[name])
 
                 # Add data for new temperature
                 try:
                     print(f"Converting {table.name} (ACE) to {data.name}        (HDF5)")
                     data.add_temperature_from_ace(table, metastable)
                 except Exception as e:
                     print(f"Failed to convert {table.name}: {e}")
                     continue
 
                 # Re-export
                 data.export_to_hdf5(converted[name], "w", libver=libver)

Where the metastable variable is passed as name to add_temperature_from_ace. By deleting this variable from the function signature, we can fix the error.

yardasol avatar Sep 24 '22 22:09 yardasol