[0.13.3-dev][cross_sections.xml] Problem/Bug in "cross_sections.xml" path specification

Dear all,

I ran into the following problem/bug when trying to plot a simple universe (using an instance of the class openmc.Universe() and its .plot() method).

Specifications: Ubuntu 22.04.2 LTS on Windows 11 WSL2, using Visual Studio Code, OpenMC version 0.13.3-dev.

When using the .plot() method (I’m using Jupyter-like .ipynb notebooks), the code asks for the cross_sections.xml path specification, even though the file is in the same directory as the .ipynb file.

  • Doubt #1: not sure if that should be actually needed for just ploting the universe
  • Doubt #2: shouldn’t be the .xml file by default taken from this same directory?

Any of the following works fine for specifying the “cross_sections.xml” path:

openmc.config["cross_sections"]="/home/juan/cross_sections.xml"
openmc.Materials.cross_sections ="/home/juan/cross_sections.xml"
%env OPENMC_CROSS_SECTIONS = /home/juan/cross_sections.xml

But when trying the following ( “4)” ):

mats = openmc.Materials([...])
mats.cross_sections = "/home/juan/cross_sections.xml"
mats.export_to_xml()

doesn’t work.

Either using method “2)” or “4)” the “materials.xlm” file is created, and the lines:

<?xml version='1.0' encoding='utf-8'?>
<materials>
  <cross_sections>/home/juan/Tutorial/cross_sections.xml</cross_sections>

appear correctly, but in case “2)” works and in case “4)” it doesn’t, as if the file was not seen.

  • Doubt #3: shouldn’t the line (and the method) “mats.cross_sections = …” work as well?

Best regards,
Juan

3 Likes

Hello @Juan_GaliciaA,

I ran into the same problem some time ago and gave up using the universe.plot() method and resorted to the openmc.plot_geometry(). It’s nice to know that those three options work since it’s very handy to plot the geometry as we are building it. However, i don’t understand why setting the mats.cross_sections does not work since the error message states:

RuntimeError: No cross_sections.xml file was specified in materials.xml or in the OPENMC_CROSS_SECTIONS environment variable. OpenMC needs such a file to identify where to find data libraries. Please consult the user's guide at https://docs.openmc.org/ for information on how to set up data libraries.

And, as you showed, the cross_section.xml path was correctly exported to the materials.xml file.

We may need some help here.

My best regards,
Artur Souza

1 Like

We have been tinkering with the universe plot function recently. There were a few pull requests that improved the plotting merged in to the develop as recently as this week.

I would be keen to try and reproduce this error.

Wondering if you can share the XML files.

But perhaps the best solution would be to make the plotting not need to load cross sections at all.

Many thanks

Hello @Shimwell,

Here are the materials.xml and geometry.xml files together with the Jupyter notebook i used to generate them.

Fuel Rod.ipynb (14.1 KB)
geometry.xml (1.2 KB)
materials.xml (2.4 KB)

To explain what’s happening here, when you call universe.plot(), under the hood, OpenMC will create a temporary directory, spit out a geometry.xml file containing only that universe, spit out a materials.xml file that contains only the materials that are found within that universe, and then run openmc.plot_geometry on this temporary set of inputs. Fundamentally, the Universe object has no knowledge of the Materials object, which is why setting mats.cross_sections doesn’t affect universe.plot.

At this point, I would recommend using openmc.config as the preferred way of indicating where cross sections are, and it should work across all functions in the Python API.

1 Like