How to indicate cross section data

Hello guys,

I’m a new user of OpenMC and also I have few experience with Ubuntu. I installed OpenMC via conda-forge.

I’m trying to run the first example “Modeling a Pin Cell”, however, although I read the Cross Section Configuration guide, I do not fully understand how to indicate in the input file where the cross section data can be found. So, I would like to know how to do that. I do not want to set an environment variable.

If useful, the OpenMC’s Python API is in ‘/home/anaconda3/bin/’. The nuclear data, downloaded from openmc.org, is in the directory ‘/home/Documens/OpenMC/NuclearData/’.

I also want to know if it is not a problem to use Spyder to create the input files.

Thanks in advance for your help.

2 Likes

Hi Javier,

If you don’t want to set the OPENMC_CROSS_SECTIONS environment variable, you can use Materials.cross_sections to achieve same thing. So it would look something like:

mats = openmc.Materials([mat1, mat2, …])
mats.cross_sections =
mats.export_to_xml()

One other note to make is that the version that is currently available on conda-forge (0.10) will not work with the data uploaded on openmc.org, which is intended for our next release. You can download an ENDF/B-VII.1 based library that will work with 0.10 here: https://anl.box.com/s/8uwvqh1fkpsys82n54ks39ou8ji222is

Best,
Paul

Sorry for digging up this old thread, but I am in need of some clarification…

I have tried to specify the cross sections via openmc.Materials like you said, but it never seemed to work, and the path will not end up in the materials.xml file.

OpenMC complains that the cross sections are not present.

Currently using 0.12

Thanks in advance,
Simon

Hi Simon,

When you specify the path to the cross sections, did you include the “cross_sections.xml”?. Something like this:

materials = openmc.Materials([mat1, mat2, …])
materials.cross_sections = ‘/path/to/nucleardata/cross_sections.xml’
materials.export_to_xml()

Hope this helps.
Javier

Yes, I included the complete path, but it still does not get exported

Thanks for the reminder,
Simon

Okay, could you share a picture of the script and/or the error shown?

The skript goes like this:

materials_file = openmc.Materials([fuel, heavy_water, cladding,
ss316, u_depleted, lead, cadmium,
polyethylene])
materials_file.cross_sections = ‘path/to/cross_sections.xml’
materials_file.export_to_xml()

The resulting XML file does not contain the path.

Accordingly, I get the following error from OpenMC:

ERROR: 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.

Humm, very weird. Well, another option is to include manually the path in the “materials.xml”. If you would like to share the part of your script where you specify the materials, I could check it!

Javier

@shimon Do you actually see the cross_sections.xml path inside of the generated materials.xml file?

No, the materials.xml does not contain any path.

Also, contrary to what I initially said, element expansion does NOT work without setting the OPENMC_CROSS_SECTIONS variable. How would you use element expansion without the environment variable?
(edit) ok, I think I figured element expansion out. I had set the path using “openmc.Materials.cross_sections = cross_sections_path”, but appearantly there was still an $OPENMC_CROSS_SECTIONS in the environment which took precedence. After unsetting OPENMC_CROSS_SECTIONS, element expansion works.

Thanks,
Simon

A curious addition: It seems to work if I put

my_materials._cross_sections = 'cross_sections_path'
my_materials.export_to_xml()

Then, materials.xml contains the path, and OpenMC runs. I found this out by checking the output of of my_materials.__dict__ which reads:

{'expected_type': openmc.material.Material,
'name': 'materials collection',
'_cross_sections': None}

What is happening here? The cross_sections attribute is private after instantiation? Is it just me not knowing enough about Python?

(edit)
For the sake of clarity, let me expand a bit.
If I put

my_materials.cross_sections = 'cross_sections_path'
my_materials.export_to_xml()

then my_materials.__dict__ says

{'expected_type': openmc.material.Material,
 'name': 'materials collection',
 '_cross_sections': None,
 'cross_sections': 'cross_sections_path'}

and materials.xml does not contain the path.

I have never had that issue, @shimon. No idea what to do.

Yeah, not sure what’s going with the last issue with the _cross_sections attribute. Setting my_materials.cross_sections is the right way to do this and should work (I wasn’t able to reproduce the behavior you’re seeing).

Regarding element expansion, generally you do need to rely on the OPENMC_CROSS_SECTIONS environment variable as opposed to materials.cross_sections. The reason is that at the time you call mat.add_element(...), the mat object doesn’t know anything about the cross_sections attribute you’ve set on another object. One potential way around this is the following:

zr = openmc.Element('Zr')
expanded = zr.expand(density, 'ao', cross_sections='cross_sections_path')

mat = openmc.Material()
for isotope, percent, percent_type in expanded:
    mat.add_element(isotope, percent, percent_type)

As you see, when you directly expand an element, you can pass it a path to a cross sections file. Perhaps we ought to allow a similar specification in Material.add_element.

Thanks for the helpful comments!

I think I will give up trying to do this without an environment variable.

Setting an environment variable programatically works, e.g. in Jupyter I can just use
%env OPENMC_CROSS_SECTIONS $cross_sections_path

All, I am having the same issue. I want to specify the path to my cross section library, but it never ends up in the materials.xml file. I can edit the materials.xml file by hand (or write a script to do that) and insert the cross section line, but that sort of defeats the purpose of the python api.

I have tried every which way I can think of to specify the path to the cross sections I want to use. I prefer to not do this with an environment variable so that I could more explicitly run a sensitivity study on different cross section sets.

I am playing with the assembly example file and have the source codes of interest available (being a new user I cannot upload). I have been compiling with the command:

python3 assembly.py --generate

Here is the assembly source code of interest:

Define materials

fuel = openmc.Material(name=‘Fuel’)
fuel.set_density(‘g/cm3’, 10.29769)
fuel.add_nuclide(‘U234’, 4.4843e-6)
fuel.add_nuclide(‘U235’, 5.5815e-4)
fuel.add_nuclide(‘U238’, 2.2408e-2)
fuel.add_nuclide(‘O16’, 4.5829e-2)

clad = openmc.Material(name=‘Cladding’)
clad.set_density(‘g/cm3’, 6.55)
clad.add_nuclide(‘Zr90’, 2.1827e-2)
clad.add_nuclide(‘Zr91’, 4.7600e-3)
clad.add_nuclide(‘Zr92’, 7.2758e-3)
clad.add_nuclide(‘Zr94’, 7.3734e-3)
clad.add_nuclide(‘Zr96’, 1.1879e-3)

hot_water = openmc.Material(name=‘Hot borated water’)
hot_water.set_density(‘g/cm3’, 0.740582)
hot_water.add_nuclide(‘H1’, 4.9457e-2)
hot_water.add_nuclide(‘O16’, 2.4672e-2)
hot_water.add_nuclide(‘B10’, 8.0042e-6)
hot_water.add_nuclide(‘B11’, 3.2218e-5)
hot_water.add_s_alpha_beta(‘c_H_in_H2O’)

openmc.Materials.cross_sections = ‘/home/neonnuke/openmc/xsecs/endfb80_hdf5/cross_sections.xml’

And here is the materials.xml file without the line needed:

<?xml version='1.0' encoding='utf-8'?>

… etcetera

And I can get it to run with openmc by inserting the line:

<cross_sections>/home/neonnuke/openmc/xsecs/endfb80_hdf5/cross_sections.xml</cross_sections>

right after the materials tag.

Hi,

Doing the following is not working?

materials = openmc.Materials([mat1, mat2, …])
materials.cross_sections = ‘/path/to/nucleardata/cross_sections.xml’
materials.export_to_xml()

I gave it a try with the following lines:

materials = openmc.Materials([fuel, clad, hot_water])
#openmc.Materials.cross_sections = ‘/home/neonnuke/openmc/xsecs/endfb80_hdf5/cross_sections.xml’
materials.cross_sections = ‘/home/neonnuke/openmc/xsecs/endfb80_hdf5/cross_sections.xml’
materials.export_to_xml()

And no cross section path. Now, should I still be using the same python command? The /examples/assembly directory has no export_to_xml for the materials list.

If you are new with OpenMC, I recommend taking a look at the Examples. There it is very well explained every step to create your input.

If you are using this Python API, I guess the way of defining the path to the cross sections should be similar

Thanks for the input Javier. I will continue playing with it and referencing the different example files available.

Ah-Ha!!! I have localized the source of the problem - I still do not have an idea about what is going on, but here is what I have found.

When I insert the lines Javier recommended:

materials = openmc.Materials([fuel, clad, hot_water])
#openmc.Materials.cross_sections = ‘/home/neonnuke/openmc/xsecs/endfb80_hdf5/cross_sections.xml’
materials.cross_sections = ‘/home/neonnuke/openmc/xsecs/endfb80_hdf5/cross_sections.xml’
materials.export_to_xml()

And I use the compile without --generate or --run flags, I get a materials.xml file that includes my cross section path. “python3 input_file”

Now, if I change absolutely nothing about the input, but use either the --generate or --run flags, the cross_section path is not included in the materials.xml file. “python3 input_file --generate”

So it is something with the generate or run interaction. Or maybe with the looping that occurs if you do not specify export_to_xml for the materials explicitly.

Here is the lame work-around, you have to add the materials.export statement and then compile twice then execute openmc standalone:

python3 assembly.py --generate;python3 assembly.py;openmc