openmc icon indicating copy to clipboard operation
openmc copied to clipboard

Ignoring nuclides with no xs data when writing material xml files

Open nplinden opened this issue 2 years ago • 0 comments

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

  • [x] I have performed a self-review of my own code
  • [ ] I have run clang-format (version 15) on any C++ source files (if applicable)
  • [x] I have followed the style guidelines for Python source files (if applicable)
  • [x] 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 avatar Dec 11 '23 17:12 nplinden