Skip to content

Radial pressure gradient name, lambda, breaks some SolutionArray functionality in Python. #1865

@TimothyEDawson

Description

@TimothyEDawson

Problem description

When adding "extra" columns to SolutionArray, they can be accessed as attributes of the object. However, presumably because lambda is reserved for lambda functions in Python, it breaks this feature.

Steps to reproduce

Because the radial pressure gradient is named lambda in the AxisymmetricFlow object, converting it to a SolutionArray demonstrates the issue:

>>> import cantera as ct
>>> gas = ct.Solution("gri30.yaml")
>>> flame = ct.CounterflowDiffusionFlame(gas, width=0.02)
>>> sol = flame.to_array()
>>> print(sol.extra)
['grid', 'velocity', 'spread_rate', 'lambda']
>>> print(sol.lambda)
  File "<python-input-1>", line 1
    print(sol.lambda)
              ^^^^^^
SyntaxError: invalid syntax

Though one workaround is to use getattr instead:

>>> print(getattr(sol, "lambda"))
[0. 0. 0. 0. 0. 0.]

Behavior

I would expect to be able to access the radial pressure gradient the same way I would any other extra parameter, e.g. velocity:

>>> print(sol.velocity))
[0. 0. 0. 0. 0. 0.]

I presume this may be why the radial pressure gradient is still called L in FlameBase, and perhaps there is a way to map sol.L to getattr(sol, "lambda") without breaking other functionality or user expectations. Also, apologies if this has already been discussed, I wasn't able to find anything about it when I searched the issues and pull requests for "lambda."

System information

  • Cantera version: 3.1.0
  • OS: RHEL 8.10
  • Python version: 3.13

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions