Skip to content

openmc.stats.Tabular documents support for 'log-log' interpolation, but C++ backend rejects it as unsupported #3722

@Submerging

Description

@Submerging

Bug Description

According to the Python API documentation for openmc.stats.Tabular, the interpolation argument officially supports in https://docs.openmc.org/en/stable/pythonapi/generated/openmc.stats.Tabular.html#openmc.stats.Tabular:

  • {'histogram', 'linear-linear', 'linear-log', 'log-linear', 'log-log'}

However, when using interpolation='log-log' in a source energy distribution, OpenMC fails at runtime during XML model loading with:

  • ERROR: Unsupported interpolation type for distribution: log-log

This indicates a mismatch between the Python API documentation and the actual C++ implementation.

In distribution.cpp, it's:
//==============================================================================
// Tabular implementation
//==============================================================================

Tabular::Tabular(pugi::xml_node node)
{
  if (check_for_node(node, "interpolation")) {
    std::string temp = get_node_value(node, "interpolation");
    if (temp == "histogram") {
      interp_ = Interpolation::histogram;
    } else if (temp == "linear-linear") {
      interp_ = Interpolation::lin_lin;
    } else {
      openmc::fatal_error(
        "Unsupported interpolation type for distribution: " + temp);
    }
  } else {
    interp_ = Interpolation::histogram;
  }

  // Read and initialize tabular distribution. If number of parameters is odd,
  // add an extra zero for the 'p' array.
  auto params = get_node_array<double>(node, "parameters");
  if (params.size() % 2 != 0) {
    params.push_back(0.0);
  }
  std::size_t n = params.size() / 2;
  const double* x = params.data();
  const double* p = x + n;
  init(x, p, n);
}

Steps to Reproduce

import openmc

# --- Minimal geometry ---
mat = openmc.Material()
mat.add_element('H', 1)
mat.set_density('g/cm3', 1.0)

materials = openmc.Materials([mat])

sphere = openmc.Sphere(r=10.0, boundary_type='vacuum')
cell = openmc.Cell(fill=mat, region=-sphere)
universe = openmc.Universe(cells=[cell])
geometry = openmc.Geometry(universe)

# --- Settings with Tabular(log-log) ---
energy = [1e-5, 0.0253, 0.5, 1.0e6]
flux   = [1.2e12, 5.5e13, 2.1e13, 8.4e11]

energy_dist = openmc.stats.Tabular(
    energy, flux, interpolation='log-log'
)

source = openmc.IndependentSource(energy=energy_dist)

settings = openmc.Settings()
settings.source = [source]
settings.batches = 1
settings.particles = 10

# --- Build model ---
model = openmc.Model(geometry, materials, settings)

# --- Run ---
model.run()

Environment

openmc 0.15.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions