diff --git a/interfaces/cython/cantera/solutionbase.pxd b/interfaces/cython/cantera/solutionbase.pxd index 46aff4621b..0e209feb4b 100644 --- a/interfaces/cython/cantera/solutionbase.pxd +++ b/interfaces/cython/cantera/solutionbase.pxd @@ -78,7 +78,7 @@ cdef extern from "cantera/base/SolutionArray.h" namespace "Cantera": vector[long int] apiShape() except +translate_exception void setApiShape(vector[long int]&) except +translate_exception size_t apiNdim() - string info(int, int) except +translate_exception + string info(vector[string]&, int, int) except +translate_exception CxxAnyMap meta() void setMeta(CxxAnyMap&) vector[string] componentNames() except +translate_exception diff --git a/interfaces/cython/cantera/solutionbase.pyx b/interfaces/cython/cantera/solutionbase.pyx index c8f250c890..054688d61c 100644 --- a/interfaces/cython/cantera/solutionbase.pyx +++ b/interfaces/cython/cantera/solutionbase.pyx @@ -3,8 +3,6 @@ cimport numpy as np import numpy as np -from collections import defaultdict as _defaultdict -from cython.operator cimport dereference as deref, preincrement as inc from pathlib import PurePath import warnings @@ -540,14 +538,29 @@ cdef class SolutionArrayBase: cxx_shape.push_back(dim) self.base.setApiShape(cxx_shape) - def info(self, rows=10, width=80): + def info(self, keys=None, rows=10, width=80): """ Print a concise summary of a `SolutionArray`. + :param keys: List of components to be displayed; if `None`, all components are + considered. :param rows: Maximum number of rendered rows. :param width: Maximum width of rendered output. """ - return pystr(self.base.info(rows, width)) + cdef vector[string] cxx_keys + if keys is not None: + for key in keys: + cxx_keys.push_back(stringify(key)) + elif self._phase.selected_species: + keep = self._phase.species_names + self._phase.selected_species = [] + names = set(self._phase.species_names) + self._phase.selected_species = keep + keep = set(keep) + for key in self.component_names: + if key not in names or key in keep: + cxx_keys.push_back(stringify(key)) + return pystr(self.base.info(cxx_keys, rows, width)) @property def meta(self): diff --git a/src/base/SolutionArray.cpp b/src/base/SolutionArray.cpp index 7c5f41d4d8..c51066351a 100644 --- a/src/base/SolutionArray.cpp +++ b/src/base/SolutionArray.cpp @@ -505,11 +505,8 @@ string SolutionArray::info(const vector& keys, int rows, int width) // add separator cols.push_back(vector(size + 1, " ...")); } - while (tail.size()) { - // copy trailing columns - cols.push_back(tail.back()); - tail.pop_back(); - } + // copy trailing columns + cols.insert(cols.end(), tail.rbegin(), tail.rend()); // assemble formatted output for (size_t row = 0; row < size; row++) {