Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functionality to avoid redundant cross-section downloads if environment variable is set #46

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

davidepettinari
Copy link
Contributor

This pull request implements a feature to prevent the redundant download of nuclear data cross-sections for OpenMC if the required environment variable (OPENMC_CROSS_SECTIONS) is already defined on the system. This enhancement ensures efficient usage of resources and avoids unnecessary downloads, especially for systems where the cross-section libraries are already available.
These changes were developed collaboratively with @SteSeg .

Copy link
Collaborator

@RemDelaporteMathurin RemDelaporteMathurin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @davidepettinari @SteSeg for this!

I have one concern: what happens if one has OPENMC_CROSS_SECTIONS in the environment variables but the library is not ENDFB-8.0-NNDC?

Is there a way to ensure the correct library is used?

Comment on lines +58 to +59
if "OPENMC_CROSS_SECTIONS" not in os.environ:
import openmc_data_downloader as odd
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the import needs to be optional here

@SteSeg
Copy link
Contributor

SteSeg commented Jan 9, 2025

Thanks @davidepettinari @SteSeg for this!

I have one concern: what happens if one has OPENMC_CROSS_SECTIONS in the environment variables but the library is not ENDFB-8.0-NNDC?

Is there a way to ensure the correct library is used?

@RemDelaporteMathurin usually neutronics people want to test the model with their cross section library of choice. Also, for tritium production calculation the neutronics community tends to prefer FENDL over ENDF anyways.
If we want people to be able to reproduce exactly the results we have with exactly our nuclear data library we can add another flag for the user to decide to run the simulation with that specific library. Maybe we can add it as an option with the argparse module. Something like:

import argparse

def _parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument("-xs", "--use_original_library", type=Bool, default=True)
    args = parser.parse_args()

    return args

if not args.use_original_library:
    if "OPENMC_CROSS_SECTIONS" not in os.environ:
        import openmc_data_downloader as odd

@RemDelaporteMathurin
Copy link
Collaborator

neutronics people want to test the model with their cross section library of choice

I respect that, but it's also a matter of reproducibility of results here

for tritium production calculation the neutronics community tends to prefer FENDL over ENDF anyways

Do you remember why we went with ENDF then?

Maybe we can add it as an option with the argparse module

Argparse is useful when executing a script, but with libra-toolbox python modules are imported. Instead we could have a variable/attribute say libra_toolbox.neutronics.library that defaults to "ENDFB-8.0-NNDC" and this can be exposed to the users so that they can change it. Usage would be:

import libra_toolbox.neutronics

# change the cross sections library
libra_toolbox.neutronics.library = "another valid library"

baby_openmc_model = libra_toolbox.neutronics.model(......)

baby_openmc_model.run()

@SteSeg
Copy link
Contributor

SteSeg commented Jan 9, 2025

neutronics people want to test the model with their cross section library of choice

I respect that, but it's also a matter of reproducibility of results here

for tritium production calculation the neutronics community tends to prefer FENDL over ENDF anyways

Do you remember why we went with ENDF then?

Maybe FENDL was not downloadable? I don't know. Locally I always used FENDL by the way.

Maybe we can add it as an option with the argparse module

Argparse is useful when executing a script, but with libra-toolbox python modules are imported. Instead we could have a variable/attribute say libra_toolbox.neutronics.library that defaults to "ENDFB-8.0-NNDC" and this can be exposed to the users so that they can change it. Usage would be:

import libra_toolbox.neutronics

# change the cross sections library
libra_toolbox.neutronics.library = "another valid library"

baby_openmc_model = libra_toolbox.neutronics.model(......)

baby_openmc_model.run()

Sure, this will do as well. We will implement it on this PR.

@RemDelaporteMathurin
Copy link
Collaborator

@SteSeg @davidepettinari maybe it's better to add it as an argument of

def build_vault_model(
settings=None,
tallies=None,
added_cells=[],
added_materials=[],
overall_exclusion_region=None,
) -> "openmc.model.Model":

Something like:

def build_vault_model(
    settings=None,
    tallies=None,
    added_cells=[],
    added_materials=[],
    overall_exclusion_region=None,
    cross_section_library: str="ENDFB-8.0-NNDC"

Then:

    if cross_section_library != "local":
        if  "OPENMC_CROSS_SECTIONS" not in os.environ:
            materials.download_cross_section_data(
                libraries=[cross_section_library],
                set_OPENMC_CROSS_SECTIONS=True,
                particles=["neutron"],
            )

@RemDelaporteMathurin
Copy link
Collaborator

Maybe FENDL was not downloadable? I don't know. Locally I always used FENDL by the way.

@shimwell is FENDL downloadable in ODD?

@eepeterson what do you think would be the best option here? the thing that worries me is how to know which library was used in a certain model (python script) if we rely on "local" libraries

@RemDelaporteMathurin
Copy link
Collaborator

@SteSeg @davidepettinari it seems like FENDL-3.1d can be downloaded:

https://github.com/openmc-data-storage/openmc_data_downloader/blob/30ca58623336f6ede8592cb5be55f9984a4925a9/src/openmc_data_downloader/utils.py#L95-L100

@shimwell
Copy link

shimwell commented Jan 9, 2025

I there a way to ensure the correct library is used?

Unfortunately the h5 files made don't contain any identify info such as "FENDL 3.2c processed by". Although I like the idea and also would like this ability to add tags. See issue openmc-dev/data#54 let us try and see if this issue can be solved, otherwise we can add a custom hdf5 attribute to the data, but best to try an official way first

Looks like the newest FENDL is 3.2c, I have not tried to process that one yet but I can give it a go. I have processed the other releases and have all the scripts in this repo. I should mention the official processing scripts can be found here.

@RemDelaporteMathurin
Copy link
Collaborator

@shimwell I just tried running this analysis with FENDL 3.2c and things seem to work fine!

For reproducibility it's really a shame that there is no way of knowing the source of the cross sections that were used without asking the person who ran it directly.....

@shimwell
Copy link

For reproducibility it's really a shame that there is no way of knowing the source of the cross sections that were used without asking the person who ran it directly.....

I just put in this PR which can help by adding a string attribute to the h5 file, the string can contain things like "FENDL 3.2c"

@shimwell
Copy link

Just release an update to openmc-data so it includes the ability to make h5 files for FENDL 3.2c. pip install openmc_data then convert_fendl -r 3.2c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants