Error while running a Pincell model

Good morning.
I ma new to OpenMC. I am trying to implement an example pincell model but i get the following error.
The following is my input. I am using a windows 10 OS

import os
import openmc

Set the OPENMC_CROSS_SECTIONS environment variable

os.environ[“OPENMC_CROSS_SECTIONS”] = r"C:\Jupyter_notebook\endfb-vii.1-hdf5\cross_sections.xml"

Verify the environment variable

print(f"OPENMC_CROSS_SECTIONS is set to: {os.environ[‘OPENMC_CROSS_SECTIONS’]}")

Define materials

fuel = openmc.Material(name=‘fuel’)
fuel.add_element(‘U’, 1.0, enrichment=4.25)
fuel.add_element(‘O’, 2.0)
fuel.set_density(‘g/cm3’, 10.5)

water = openmc.Material(name=‘water’)
water.add_element(‘H’, 2.0)
water.add_element(‘O’, 1.0)
water.set_density(‘g/cm3’, 1.0)
water.add_s_alpha_beta(‘c_H_in_H2O’)

materials = openmc.Materials([fuel, water])
materials.export_to_xml()

Define geometry

fuel_radius = openmc.ZCylinder(r=0.39)
fuel_region = -fuel_radius
water_region = +fuel_radius

fuel_cell = openmc.Cell(region=fuel_region, fill=fuel)
water_cell = openmc.Cell(region=water_region, fill=water)

root_universe = openmc.Universe(cells=[fuel_cell, water_cell])
geometry = openmc.Geometry(root_universe)
geometry.export_to_xml()

Define settings

settings = openmc.Settings()
settings.batches = 100
settings.inactive = 10
settings.particles = 1000
settings.export_to_xml()

Run OpenMC

openmc.run()

here is the error messsage


OSError Traceback (most recent call last)
Cell In[12], line 13
11 # Define materials
12 fuel = openmc.Material(name=‘fuel’)
—> 13 fuel.add_element(‘U’, 1.0, enrichment=4.25)
14 fuel.add_element(‘O’, 2.0)
15 fuel.set_density(‘g/cm3’, 10.5)

File /openmc_venv/lib/python3.11/site-packages/openmc/material.py:791, in Material.add_element(self, element, percent, percent_type, enrichment, enrichment_target, enrichment_type, cross_sections)
789 # Add naturally-occuring isotopes
790 element = openmc.Element(element)
→ 791 for nuclide in element.expand(percent,
792 percent_type,
793 enrichment,
794 enrichment_target,
795 enrichment_type,
796 cross_sections):
797 self.add_nuclide(*nuclide)

File /openmc_venv/lib/python3.11/site-packages/openmc/element.py:143, in Element.expand(self, percent, percent_type, enrichment, enrichment_target, enrichment_type, cross_sections)
141 if cross_sections is not None:
142 library_nuclides = set()
→ 143 tree = ET.parse(cross_sections)
144 root = tree.getroot()
145 for child in root.findall(‘library’):

File src/lxml/etree.pyx:3590, in lxml.etree.parse()

File src/lxml/parser.pxi:1952, in lxml.etree._parseDocument()

File src/lxml/parser.pxi:1978, in lxml.etree._parseDocumentFromURL()

File src/lxml/parser.pxi:1881, in lxml.etree._parseDocFromFile()

File src/lxml/parser.pxi:1200, in lxml.etree._BaseParser._parseDocFromFile()

File src/lxml/parser.pxi:633, in lxml.etree._ParserContext._handleParseResultDoc()

File src/lxml/parser.pxi:743, in lxml.etree._handleParseResult()

File src/lxml/parser.pxi:670, in lxml.etree._raiseParseError()

OSError: Error reading file ‘/root/nndc_hdf5/cross_sections.xml’: failed to load external entity “/root/nndc_hdf5/cross_sections.xml”

Please help me to resolve the isuue

Hi Asukua, welcome to the community.
From your error notification, I think you forgot to set your path to the cross_sections.xml on your environment variable or in your simulation.
By default, openmc uses the $OPENMC_CROSS_SECTIONS variable as a path to your nuclear data xsdir.
Try to check this variable from your linux terminal
echo $OPENMC_CROSS_SECTIONS
If there is none of it, then you will need to declare that variable as a default path to your nuclear data library.

From your script, I think the nuclear data exists on the Windows side, while you need to declare it in the wsl. So, you will need to make sure that you use the correct path to your nuclear data. To access the C directory on the Windows side, you will need to use /mnt/c/path to your lib cross_sections.xml. But for the calculation efficiency, I recommend you to move the nuclear data to the wsl side (to the linux side), i.e. to your $HOME directory, since openmc can access those nuclear data files faster if it is on your linux side.

Since you have downloaded the openmc official data library from Official Data Libraries | OpenMC . I think you have download the ENDF VII.1, You can update or add the OPENMC_CROSS_SECTIONS variable from your .profile file at your $HOME directory so it becomes your environment variable to your Ubuntu profile as the default path for openmc

export OPENMC_CROSS_SECTIONS=/home/name/path/to/your/endfb-vii.1-hdf5/cross_sections.xml

you could also set openmc to use this library by adding the cross_sections.xml file path to openmc.Materials.cross_sections

materials = openmc.Materials([any material you made, so on])
materials.cross_sections = '/home/name/path/to/your/endfb-vii.1-hdf5/cross_sections.xml'
materials.export_to_xml()

Also, you could ask this kind of question from the user support category, since I think it will catch more eyes from there

Thank you very much for your response. I take your corrections to use the user support platform for this kind of question. I tried the first two options but it didnt work, When i tried the last option

Define materials

fuel = openmc.Material(name=‘fuel’)
fuel.add_element(‘U’, 1.0, enrichment=4.25)
fuel.add_element(‘O’, 2.0)
fuel.set_density(‘g/cm3’, 10.5)

water = openmc.Material(name=‘water’)
water.add_element(‘H’, 2.0)
water.add_element(‘O’, 1.0)
water.set_density(‘g/cm3’, 1.0)
water.add_s_alpha_beta(‘c_H_in_H2O’)

materials = openmc.Materials([fuel, water])
materials.cross_sections = ‘C:\Jupyter_notebook\OpenmcInput\endfb-vii.1-hdf5’
materials.export_to_xml()

the code started running then aborted with an error message

RuntimeError: Cross sections XML file ‘C:\Jupyter_notebook\OpenmcInput\endfb-vii.1-hdf5’ does not exist. Abort(-1) on node 0 (rank 0 in comm 0): application called MPI_Abort(MPI_COMM_WORLD, -1) - process 0

I have confirmed that i downloaded the data library correctly. And i also extracted it to the path i specified in the materials cell. .I will appreciate your help. Thank you.

Hi Asukua,
I think the problem came from the fact that Linux can’t directly access the Windows C: directory.

If you use wsl (windows subsystem Linux), the Windows C directory can be accessed from the /mnt/ folder, so instead of
materials.cross_sections = ‘C:\ …\endfb-vii.1-hdf5’
Try

materials.cross_sections = ‘/mnt/c/...... /endfb-vii.1-hdf5/cross_sections.xml’

Openmc was run on the Linux side of your PC, but you have the nuclear data on the Windows directory C: So you will need to properly set the path to access the Windows directory from your Linux side. That’s why I changed it to /mnt/c because the C: windows directory could be accessed from the /mnt/c on the wsl side. You might want to check it by opening the C folder from the Linux terminal, maybe using
bash
from the address bar, and then typing
pwd
to know what is the address for your current working directory being opened in your Linux terminal. You can do that on your Linux terminal by doing cd and cd … manually if you want to explore your wsl directory
Note: openmc needs the path to the cross_sections.xml file, not the path to the nuclear data folder/directory.

Also, I recommend you extract or move the nuclear data library to the Linux home directory before because it will shorten the time to read nuclear data for openmc which works on the Linux side of your PC.
You could do this from the Windows side by using Windows Explorer and clicking on the Linux icon at the bottom, which will bring you to the //wsl.localhost/ as your Linux root directory.

Wahidlutfi,

thank you so much.

Issue resolved.!

I mounted the cross section library on the openmc Docker container via powershell terminal. Then i specified the cross section library path as

#specifying the library path as in my openmc Docker containet
openmc.config.cross_sections = ‘/openmc/cross-sections/cross_sections.xml’

This works perfectly.

1 Like