Skip to content

Commit

Permalink
[Python] Fix unordered SolutionArray append
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl authored and speth committed Jan 22, 2025
1 parent 10d7754 commit e647b9d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions interfaces/cython/cantera/composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -815,14 +815,14 @@ def append(self, state=None, normalize=True, **kwargs):
"the thermodynamic state".format(tuple(kwargs))
) from None
if normalize or attr.endswith("Q"):
setattr(self._phase, attr, list(kwargs.values()))
setattr(self._phase, attr, [kwargs[a] for a in attr])
else:
if attr.endswith("X"):
self._phase.set_unnormalized_mole_fractions(kwargs.pop("X"))
elif attr.endswith("Y"):
self._phase.set_unnormalized_mass_fractions(kwargs.pop("Y"))
attr = attr[:-1]
setattr(self._phase, attr, list(kwargs.values()))
setattr(self._phase, attr, [kwargs[a] for a in attr])

self._append(self._phase.state, extra_temp)
self._indices.append(len(self._indices))
Expand Down
10 changes: 10 additions & 0 deletions test/python/test_composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,16 @@ def test_append_no_norm_data(self):
assert states[0].P == gas.P
assert states[0].Y == approx(gas.Y)

def test_append_scrambled_input(self):
gas = ct.Solution("h2o2.yaml")
gas.TP = 300, ct.one_atm
gas.set_unnormalized_mass_fractions(np.full(gas.n_species, 0.3))
states = ct.SolutionArray(gas)
states.append(Y=gas.Y, P=gas.P, normalize=False, T=gas.T)
assert states[0].T == gas.T
assert states[0].P == gas.P
assert states[0].Y == approx(gas.Y)

@pytest.mark.skipif("native" not in ct.hdf_support(),
reason="Cantera compiled without HDF support")
def test_import_no_norm_data(self):
Expand Down

0 comments on commit e647b9d

Please sign in to comment.