From c6ccb80757b98058b2ee2cebe8d0a312059e1b82 Mon Sep 17 00:00:00 2001 From: Ingmar Schoegl Date: Sat, 31 Oct 2020 07:15:15 -0500 Subject: [PATCH] [1D] Fix FlameBase.restore_data bug --- interfaces/cython/cantera/onedim.pyx | 10 +++++++--- interfaces/cython/cantera/test/test_onedim.py | 12 ++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/interfaces/cython/cantera/onedim.pyx b/interfaces/cython/cantera/onedim.pyx index 97de224169..456028a734 100644 --- a/interfaces/cython/cantera/onedim.pyx +++ b/interfaces/cython/cantera/onedim.pyx @@ -950,7 +950,8 @@ cdef class Sim1D: def collect_data(self, domain, other): """ - Return data vector of domain *domain* as `SolutionArray` object + Return underlying data specifying a *domain*. Method is used as + a service function for export via `FlameBase.to_solution_array`. Derived classes set default values for *domain* and *other*, where defaults describe flow domain and essential non-thermodynamic solution @@ -1005,7 +1006,8 @@ cdef class Sim1D: def restore_data(self, domain, states, other_cols, meta): """ - Restore data vector of domain *domain* from `SolutionArray` *states*. + Restore a *domain* from underlying data. Method is used as + a service function for import via `FlameBase.from_solution_array`. Derived classes set default values for *domain* and *other*, where defaults describe flow domain and essential non-thermodynamic solution @@ -1016,6 +1018,8 @@ cdef class Sim1D: idom = self.domain_index(domain) dom = self.domains[idom] T, P, Y = states + if isinstance(P, np.ndarray) and P.size: + P = P[0] if isinstance(dom, _FlowBase): grid = other_cols['grid'] @@ -1036,7 +1040,7 @@ cdef class Sim1D: self.set_profile(spc, xi, Y[:, i]) # restore pressure - self.P = P[0] + self.P = P # restore settings dom.settings = meta diff --git a/interfaces/cython/cantera/test/test_onedim.py b/interfaces/cython/cantera/test/test_onedim.py index 1d39881c9a..ad9975b6d7 100644 --- a/interfaces/cython/cantera/test/test_onedim.py +++ b/interfaces/cython/cantera/test/test_onedim.py @@ -273,6 +273,18 @@ def run_mix(self, phi, T, width, p, refine): for rhou_j in self.sim.density * self.sim.velocity: self.assertNear(rhou_j, rhou, 1e-4) + def test_collect_restore(self): + self.run_mix(phi=1.0, T=300, width=2.0, p=1.0, refine=False) + + states, other, meta = self.sim.collect_data('flame', ['grid']) + self.assertArrayNear(self.sim.grid, other['grid']) + self.assertArrayNear(self.sim.T, states[0]) + + f2 = ct.FreeFlame(self.gas) + f2.restore_data('flame', states, other, meta) + self.assertArrayNear(self.sim.grid, f2.grid) + self.assertArrayNear(self.sim.T, f2.T) + def test_solution_array_output(self): self.run_mix(phi=1.0, T=300, width=2.0, p=1.0, refine=False)