Skip to content

Commit

Permalink
[Python] Support select_species in SolutionArray
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl authored and speth committed Apr 11, 2023
1 parent ec454fc commit 756f595
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion interfaces/cython/cantera/solutionbase.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 17 additions & 4 deletions interfaces/cython/cantera/solutionbase.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down
7 changes: 2 additions & 5 deletions src/base/SolutionArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,11 +505,8 @@ string SolutionArray::info(const vector<string>& keys, int rows, int width)
// add separator
cols.push_back(vector<string>(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++) {
Expand Down

0 comments on commit 756f595

Please sign in to comment.