From e647b9de63210f974bd65730f37ff1f6cf79b2e6 Mon Sep 17 00:00:00 2001 From: Ingmar Schoegl Date: Tue, 21 Jan 2025 08:17:58 -0600 Subject: [PATCH] [Python] Fix unordered SolutionArray append --- interfaces/cython/cantera/composite.py | 4 ++-- test/python/test_composite.py | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/interfaces/cython/cantera/composite.py b/interfaces/cython/cantera/composite.py index cc0c7892f2..711cfc9b5c 100644 --- a/interfaces/cython/cantera/composite.py +++ b/interfaces/cython/cantera/composite.py @@ -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)) diff --git a/test/python/test_composite.py b/test/python/test_composite.py index d1562ded28..eed1faddb8 100644 --- a/test/python/test_composite.py +++ b/test/python/test_composite.py @@ -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):