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

restore_data refers to P[0] instead of P #942

Closed
kahilah opened this issue Oct 30, 2020 · 1 comment · Fixed by #943
Closed

restore_data refers to P[0] instead of P #942

kahilah opened this issue Oct 30, 2020 · 1 comment · Fixed by #943

Comments

@kahilah
Copy link

kahilah commented Oct 30, 2020

In function restore_data() in onedim.pyx the pressure is restored simply setting
self.P = P[0]

However, prior to that call, P is defined as T, P, Y = states where states is the function argument. If user has created the states by using f.collect_data() function, P is not an array but a float, hence evoking an error TypeError: 'float' object is not subscriptable

Steps to reproduce

import cantera as ct
import numpy as np

# Simulation parameters
p = ct.one_atm  # pressure [Pa]
Tin = 300.0  # unburned gas temperature [K]
reactants = 'H2:1.1, O2:1, AR:5'  # premixed gas composition
width = 0.03  # m
loglevel = 1  # amount of diagnostic output (0 to 8)

# IdealGasMix object used to compute mixture properties, set to the state of the
# upstream fuel-air mixture
gas = ct.Solution('h2o2.xml')
gas.TPX = Tin, p, reactants

# Set up flame object
f = ct.FreeFlame(gas, width=width)
f.set_refine_criteria(ratio=3, slope=0.06, curve=0.12)
f.show_solution()

# Solve with mixture-averaged transport model
f.transport_model = 'Mix'
f.solve(loglevel=loglevel, auto=True)

fdata_tmp = f.collect_data('flame', ['grid'])

f.restore_data('flame', fdata_tmp[0], fdata_tmp[1], fdata_tmp[2])

System information

  • Cantera version: development version installed by conda
  • OS: Centos 7
  • Python 3.8
@ischoegl
Copy link
Member

Thanks for this bug report on this recently introduced feature - the main issue is that docstrings are incorrect, i.e. these functions work with tuple arguments, not SolutionArrays; it's certainly true that the observed behavior needs to be fixed also. Overall, these functions are mainly meant as service functions for flame.to_solution_array and flame.from_solution_array. As a work-around, I'd recommend simply using those, i.e.

arr = f.to_solution_array('flame')
f.from_solution_array(arr, 'flame')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants