Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Python] Fix unordered SolutionArray append #1840

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading