Skip to content

Commit e647b9d

Browse files
ischoeglspeth
authored andcommitted
[Python] Fix unordered SolutionArray append
1 parent 10d7754 commit e647b9d

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

interfaces/cython/cantera/composite.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -815,14 +815,14 @@ def append(self, state=None, normalize=True, **kwargs):
815815
"the thermodynamic state".format(tuple(kwargs))
816816
) from None
817817
if normalize or attr.endswith("Q"):
818-
setattr(self._phase, attr, list(kwargs.values()))
818+
setattr(self._phase, attr, [kwargs[a] for a in attr])
819819
else:
820820
if attr.endswith("X"):
821821
self._phase.set_unnormalized_mole_fractions(kwargs.pop("X"))
822822
elif attr.endswith("Y"):
823823
self._phase.set_unnormalized_mass_fractions(kwargs.pop("Y"))
824824
attr = attr[:-1]
825-
setattr(self._phase, attr, list(kwargs.values()))
825+
setattr(self._phase, attr, [kwargs[a] for a in attr])
826826

827827
self._append(self._phase.state, extra_temp)
828828
self._indices.append(len(self._indices))

test/python/test_composite.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,16 @@ def test_append_no_norm_data(self):
475475
assert states[0].P == gas.P
476476
assert states[0].Y == approx(gas.Y)
477477

478+
def test_append_scrambled_input(self):
479+
gas = ct.Solution("h2o2.yaml")
480+
gas.TP = 300, ct.one_atm
481+
gas.set_unnormalized_mass_fractions(np.full(gas.n_species, 0.3))
482+
states = ct.SolutionArray(gas)
483+
states.append(Y=gas.Y, P=gas.P, normalize=False, T=gas.T)
484+
assert states[0].T == gas.T
485+
assert states[0].P == gas.P
486+
assert states[0].Y == approx(gas.Y)
487+
478488
@pytest.mark.skipif("native" not in ct.hdf_support(),
479489
reason="Cantera compiled without HDF support")
480490
def test_import_no_norm_data(self):

0 commit comments

Comments
 (0)