mirror of
https://github.com/Cantera/cantera.git
synced 2025-02-25 18:55:29 -06:00
[SolutionArray] Add array size methods
This commit is contained in:
committed by
Ingmar Schoegl
parent
3947980eb2
commit
532e60c92d
@@ -654,6 +654,33 @@ class SolutionArray:
|
||||
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.
|
||||
|
||||
:return: `int`
|
||||
"""
|
||||
return len(self.shape)
|
||||
|
||||
@property
|
||||
def shape(self) -> tuple[int, ...]:
|
||||
"""The shape of the SolutionArray.
|
||||
|
||||
: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.
|
||||
|
||||
:return: `int`
|
||||
"""
|
||||
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
|
||||
|
||||
@@ -240,6 +240,10 @@ class TestSolutionArrayIO(utilities.CanteraTest):
|
||||
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")
|
||||
|
||||
Reference in New Issue
Block a user