Skip to content

Commit

Permalink
[Thermo] update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ingmar Schoegl committed Nov 2, 2019
1 parent ce424c9 commit c86c704
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 29 deletions.
4 changes: 0 additions & 4 deletions interfaces/cython/cantera/_cantera.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,6 @@ cdef extern from "cantera/thermo/ThermoPhase.h" namespace "Cantera":
# miscellaneous
string type()
string report(cbool, double) except +translate_exception
string name()
void setName(string)
string id()
void setID(string)
vector[string] defaultState()
vector[string] fullStates()
vector[string] partialStates()
Expand Down
10 changes: 5 additions & 5 deletions interfaces/cython/cantera/composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ class Solution(ThermoPhase, Kinetics, Transport):
gas = ct.Solution('gri30.yaml')
If an input file defines multiple phases, the corresponding key in the
If an input file defines multiple phases, the corresponding key in the
*phases* map (in YAML), *name* (in CTI), or *id* (in XML) can be used
to specify the desired phase via the ``name`` keyword argument of
to specify the desired phase via the ``name`` keyword argument of
the constructor::
gas = ct.Solution('diamond.yaml', name='gas')
diamond = ct.Solution('diamond.yaml', name='diamond')
The name of the `Solution` object defaults to the *phase* identifier
specified in the input file. Upon initialization of a 'Solution' object,
The name of the `Solution` object defaults to the *phase* identifier
specified in the input file. Upon initialization of a 'Solution' object,
a custom name can assigned via::
gas.name = 'my_custom_name'
Expand Down Expand Up @@ -791,7 +791,7 @@ def collect_data(self, cols=None, threshold=0, species='Y'):
# Create default columns (including complete state information)
if cols is None:
cols = ('extra',) + self._phase._default_state

# Expand cols to include the individual items in 'extra'
expanded_cols = []
for c in cols:
Expand Down
32 changes: 32 additions & 0 deletions interfaces/cython/cantera/test/test_purefluid.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,38 @@ def test_TPX(self):
with self.assertRaisesRegex(ValueError, 'numeric value is required'):
self.water.TPX = T, P, 'spam'

def test_SolutionArray(self):

def check(a, b):
self.assertArrayNear(a.T, b.T)
self.assertArrayNear(a.P, b.P)
self.assertArrayNear(a.X, b.X)

# benchmark
a = ct.SolutionArray(self.water, 10)
a.TX = 373.15, np.linspace(0., 1., 10)

# complete data
cols = ('T', 'P', 'X')
data, labels = a.collect_data(cols=cols)
b = ct.SolutionArray(self.water)
b.restore_data(data, labels)
check(a, b)

# partial data
cols = ('T', 'X')
data, labels = a.collect_data(cols=cols)
b = ct.SolutionArray(self.water)
b.restore_data(data, labels)
check(a, b)

# default columns
data, labels = a.collect_data()
self.assertEqual(labels, ['T', 'density'])
b = ct.SolutionArray(self.water)
b.restore_data(data, labels)
check(a, b)


# To minimize errors when transcribing tabulated data, the input units here are:
# T: K, P: MPa, rho: kg/m3, v: m3/kg, (u,h): kJ/kg, s: kJ/kg-K
Expand Down
20 changes: 0 additions & 20 deletions interfaces/cython/cantera/test/test_thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -1885,23 +1885,3 @@ def check(a, b, atol=None):
b.restore_data(data, labels)
check(a, b)
self.assertTrue(len(b._extra) == 0)

# test PureFluid
w = ct.Water()
a = ct.SolutionArray(w, 10)
a.TX = 373.15, np.linspace(0., 1., 10)

# complete data
cols = ('T', 'P', 'X')
data, labels = a.collect_data(cols=cols)

b = ct.SolutionArray(w)
b.restore_data(data, labels)
check(a, b)

# partial data
cols = ('T', 'X')
data, labels = a.collect_data(cols=cols)
b = ct.SolutionArray(w)
b.restore_data(data, labels)
check(a, b)

0 comments on commit c86c704

Please sign in to comment.