Skip to content

Commit

Permalink
[Test] include append with state in test_composite
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidAkinpelu committed Jun 16, 2021
1 parent 9eff408 commit 773b045
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
12 changes: 11 additions & 1 deletion interfaces/cython/cantera/composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,17 @@ def append(self, state=None, normalize=True, **kwargs):
extra_temp[name] = kwargs.pop(name)

if state is not None:
self._phase.state = state
mode = "".join(self._phase._native_state)
if normalize or mode[-1] == "Q":
if len(mode) == 3:
state_data = (state[0], state[1], state[2:])
elif len(mode) == 2:
state_data = (state[0], state[1:])
else:
state_data = state
setattr(self._phase, mode, state_data)
else:
self._phase.state = state

# Non normalize form must be set using the mass fractions as the
# mole fractions are not in the native_state setter.
Expand Down
19 changes: 19 additions & 0 deletions interfaces/cython/cantera/test/test_composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,25 @@ def test_append_no_norm_data(self):
self.assertEqual(states[0].P, gas.P)
self.assertArrayNear(states[0].Y, gas.Y)

def test_append_no_norm_state(self):
gas = ct.Solution("h2o2.yaml")
gas.TP = 300, ct.one_atm
gas.set_unnormalized_mass_fractions(np.full(gas.n_species, 0.3))
states = ct.SolutionArray(gas)
states.append(gas.state, normalize=False)
self.assertEqual(states[0].T, gas.T)
self.assertEqual(states[0].P, gas.P)
self.assertArrayNear(states[0].Y, gas.Y)

def test_append_norm_state(self):
gas = ct.Solution("h2o2.yaml")
gas.TPX = 300, ct.one_atm, 'H2:0.5, O2:0.4'
states = ct.SolutionArray(gas)
states.append(gas.state)
self.assertEqual(states[0].T, gas.T)
self.assertEqual(states[0].P, gas.P)
self.assertArrayNear(states[0].X, gas.X)

def test_import_no_norm_data(self):
outfile = pjoin(self.test_work_dir, "solutionarray.h5")
if os.path.exists(outfile):
Expand Down

0 comments on commit 773b045

Please sign in to comment.