diff --git a/interfaces/cython/cantera/composite.py b/interfaces/cython/cantera/composite.py index c633d16b48..5971c19dd2 100644 --- a/interfaces/cython/cantera/composite.py +++ b/interfaces/cython/cantera/composite.py @@ -1,5 +1,6 @@ # This file is part of Cantera. See License.txt in the top-level directory or # at https://cantera.org/license.txt for license and copyright information. +from __future__ import annotations from ._cantera import * import numpy as np @@ -654,6 +655,35 @@ def __call__(self, *species): return SolutionArray(self._phase[species], states=self._states, extra=self._extra) + def __len__(self) -> int: + return self._shape[0] + + @property + def ndim(self) -> int: + """The number of dimensions in the SolutionArray. + + .. versionadded:: 3.0 + """ + return len(self.shape) + + @property + def shape(self) -> tuple[int, ...]: + """The shape of the SolutionArray. + + .. versionadded: 3.0 + + :return: A tuple of integers with the number of elements in each dimension. + """ + return self._shape + + @property + def size(self) -> int: + """The number of elements in the SolutionArray. + + .. versionadded: 3.0 + """ + return np.prod(self.shape) + def append(self, state=None, normalize=True, **kwargs): """ Append an element to the array with the specified state. Elements can diff --git a/interfaces/cython/cantera/test/test_composite.py b/interfaces/cython/cantera/test/test_composite.py index fc0822bb23..eeaba69959 100644 --- a/interfaces/cython/cantera/test/test_composite.py +++ b/interfaces/cython/cantera/test/test_composite.py @@ -240,6 +240,10 @@ def test_append_state(self): self.assertEqual(states[0].T, gas.T) self.assertEqual(states[0].P, gas.P) self.assertArrayNear(states[0].X, gas.X) + self.assertEqual(len(states), 1) + self.assertEqual(states.shape, (1,)) + self.assertEqual(states.ndim, 1) + self.assertEqual(states.size, 1) def test_append_no_norm_data(self): gas = ct.Solution("h2o2.yaml")