Skip to content

Warn user if XML attribute/subelement exceeds maximum size #3838

@lewisgross1296

Description

@lewisgross1296

Bug Description

In #3774, we moved the distrib fill/temp/dens options from attribute to sub-element, as we were hitting the max attribute size for our model. It turns out there's a (larger) limit for sub-elements too. When trying to store temperatures, I encountered the limit.

If your sub-element exceeds 2GB, then lxml silently writes a blank sub-element. The number of entries depends on how much data (including a space) per item you are trying to write. E.g. there can be more entries in the sub-elements if the temperature stored is 8 vs 873.15. We should warn the user in the case that we've attempted to create a sub-element that is too large.

Steps to Reproduce

Here's an MWE to test that behavior.

import openmc

highest_working_num_instances = 306_500_000  # 306_800_000 fails, 306_500_000 works
num_instances = 306_800_000  # need string of temps to be <=2GB

mat = openmc.Material(name="U")
mat.add_element("U", 1.0, enrichment=5)

cell = openmc.Cell(fill=mat)
cell.temperature = [873.15] * num_instances  # can fit more entries with less temp digits (e.g. 8)

g = openmc.Geometry([cell])
model = openmc.Model()
model.geometry = g
model.export_to_model_xml()

which produces this model.xml

<?xml version='1.0' encoding='utf-8'?>
<model>
  <materials>
    <material id="1" name="U" depletable="true">
      <density units="sum"/>
      <nuclide name="U234" ao="0.0004523305496957069"/>
      <nuclide name="U235" ao="0.05060678291113409"/>
      <nuclide name="U238" ao="0.9487090831661896"/>
      <nuclide name="U236" ao="0.00023180337298067612"/>
    </material>
  </materials>
  <geometry>
    <cell id="1" material="1" universe="1">
      <temperature></temperature>
    </cell>
  </geometry>
  <settings>
    <run_mode>eigenvalue</run_mode>
  </settings>
  </model>

Note there should be num_instances temperatures but we see none.

Environment

OpenMC 0.15.3 on Ubuntu 24.04.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions