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

Ignoring nuclides with no xs data when writing material xml files #2800

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

nplinden
Copy link
Contributor

Description

Adding an ignore_phantom_nuclides argument to Materials.export_to_xml, Model.export_to_xml and Model.export_to_model_xml (and Model.run). This allows a user to automatically ignore nuclides that have no cross-sections when writing xml files. A typical usecase is running an eigenvalue calculation on a depleted material. This new argument is set to False by default.

A first implementation of this was available when using OpenMCOperator to start depletion from existing depleted materials, this PR refactors it to allow static calculations as well. In particular the _get_nuclides_with_data function was moved from the OpenMCOperator subclasses to the material.py file.

A warning message was also added to inform the user about the percentage of mass density lost when ignoring these nuclides, a high number would be problematic for the calculation's accuracy but this should not be the case for most practical uses.

This feature was discussed with @pshriwise during the last OpenMC community call. This is my first non trivial PR, so any feedback is of course much appreciated.

Example script

Here is a minimal working script showcasing the feature:

import openmc
import openmc.deplete
from openmc import Geometry, Material, Materials, Settings, Universe, Cell, Sphere

mat = Material()
mat.add_nuclide("U235", 0.06, "ao")
mat.add_nuclide("U238", 0.94, "ao")
mat.add_nuclide("C14", 1, "ao")
mat.set_density("g/cm3", 10)
mat.temperature = 700
mat.volume = 1000
materials = Materials(materials=[mat])

sphere = -Sphere(r=10, boundary_type="vacuum")
cell = Cell(fill=mat, region=sphere)
geometry = Geometry(root=Universe(cells=[cell]))

settings = Settings()
settings.particles = 1000
settings.batches = 100
settings.inactive = 10
settings.temperature = {"method": "interpolation"}
settings.source = openmc.IndependentSource(space=openmc.stats.Point())

# Using individual exports:
materials.export_to_xml(ignore_phantom_nuclides=True)
geometry.export_to_xml()
settings.export_to_xml()
openmc.run()

# Using model export_to_xml:
# model = openmc.Model(geometry=geometry, settings=settings, materials=materials)
# model.export_to_xml(ignore_phantom_nuclides=True)
# openmc.run()

# Using model export_to_model_xml:
# model = openmc.Model(geometry=geometry, settings=settings, materials=materials)
# model.export_to_model_xml(ignore_phantom_nuclides=True)
# openmc.run()

# Using model.run() directly
# model = openmc.Model(geometry=geometry, settings=settings, materials=materials)
# model.run(export_model_xml=True, ignore_phantom_nuclides=True)

# Restarting a depletion calculation:
# model = openmc.Model(geometry=geometry, settings=settings, materials=materials)
# operator = openmc.deplete.CoupledOperator(model)
# integrator = openmc.deplete.PredictorIntegrator(operator, [10, 10, 10], [80, 80, 80], timestep_units='d')
# integrator.integrate()

Checklist

  • I have performed a self-review of my own code
  • I have run clang-format (version 15) on any C++ source files (if applicable)
  • I have followed the style guidelines for Python source files (if applicable)
  • I have made corresponding changes to the documentation (if applicable)
  • I have added tests that prove my fix is effective or that my feature works (if applicable)

@nplinden nplinden marked this pull request as ready for review December 12, 2023 12:56
from openmc.mgxs import GROUP_STRUCTURES
from openmc.data import REACTION_MT
import openmc
from .abc import change_directory
from .chain import Chain, REACTIONS
from .coupled_operator import _find_cross_sections
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
from .coupled_operator import _find_cross_sections

@@ -91,7 +91,7 @@ def get_microxs_and_flux(
reactions = chain.reactions
if not nuclides:
cross_sections = _find_cross_sections(model)
nuclides_with_data = _get_nuclides_with_data(cross_sections)
nuclides_with_data = get_nuclides_with_data(cross_sections)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
nuclides_with_data = get_nuclides_with_data(cross_sections)
nuclides_with_data = _get_nuclides_with_data(cross_sections)

@@ -15,6 +15,7 @@
from openmc.checkvalue import check_value
from openmc.exceptions import DataError
from openmc.mpi import comm
from openmc import get_nuclides_with_data
Copy link
Member

@shimwell shimwell Jan 2, 2024

Choose a reason for hiding this comment

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

I think get_nuclides_with_data is now called _get_nuclides_with_data. Also perhaps this does not need importing as I see an abstract method in the openmc_operator file

@@ -148,16 +149,12 @@ def __init__(
# for which there is an entry in the micro_xs parameter
openmc.reset_auto_ids()

self.nuclides_with_data = self._get_nuclides_with_data(
self.cross_sections)
self.nuclides_with_data = get_nuclides_with_data(self.cross_sections)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
self.nuclides_with_data = get_nuclides_with_data(self.cross_sections)
self.nuclides_with_data = _get_nuclides_with_data(self.cross_sections)

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.

2 participants