Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1D] Fix FlameBase.restore_data bug #943

Merged
merged 1 commit into from
Nov 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions interfaces/cython/cantera/onedim.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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']
Expand All @@ -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
Expand Down
12 changes: 12 additions & 0 deletions interfaces/cython/cantera/test/test_onedim.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down