python restore solution saved from c++ error

51 views
Skip to first unread message

justin li

unread,
Aug 4, 2025, 11:49:32 AMAug 4
to Cantera Users' Group
Dear Users and Developers,

I am calculating surface reactions in a stagnation flow. After solving it in C++, I saved it through:         
flame.save("ConvecSurface11.yaml", "mix", "Solution with mixture transport", true);.

Then I attempted to restore it using the Python interface for post-processing; however, I was unable to successfully restore it.  The way I restore is like:
import cantera as ct
sim = ct.Sim1D.restore("ConvecSurface11.yaml","mix")

with errors:
CanteraError                              Traceback (most recent call last)
Cell In[1], line 2
      1 import cantera as ct
----> 2 sim = ct.Sim1D.restore("ConvecSurface11.yaml","mix")
File build/python/cantera/_onedim.pyx:1665, in cantera._onedim.Sim1D.restore()
CanteraError:
CanteraError thrown by Sim1D::restore:
Unknown file extension ''; supported extensions include 'h5'/'hdf'/'hdf5' and 'yml'/'yaml'.

If I restore it after defining an object through:
gas = ct.Solution('BurkeH2.yaml')
width = 0.00384
surf_phase = ct.Interface("ptcombust2.yaml", "Pt_surf")
gas = surf_phase.adjacent["gas"]
sim = ct.ImpingingJet(gas=gas, width=width, surface=surf_phase)
sim.restore(filename="ConvecSurface11.yml",name="mix")


I got the following errors:
CanteraError                              Traceback (most recent call last)
Cell In[3], line 6
      4 gas = surf_phase.adjacent["gas"]
      5 sim = ct.ImpingingJet(gas=gas, width=width, surface=surf_phase)
----> 6 sim.restore(filename="ConvecSurface11.yml",name="mix")
File build/python/cantera/_onedim.pyx:1665, in cantera._onedim.Sim1D.restore()
CanteraError:
CanteraError thrown by Sim1D::restore:
Encountered exception when reading entry 'mix' from 'ConvecSurface11.yml':
No field or solution with name '/mix/flame'.

The versions for both C++ and Python interfaces are 3.0.1.(The system of the workstation is Ubuntu 18, which does not support the newest cantera version )

Please help me out! Thanks in advance!

Justin


justin li

unread,
Aug 4, 2025, 9:47:44 PMAug 4
to Cantera Users' Group
Thanks. I have solved the issue.

Like the error raised, "No field or solution with name '/mix/flame'.",  the python ct.ImpingingJet restoration has a default subdomain entry, which appears to be unable to be provided in Python. Therefore, I changed the definition of each part in the impinging jet when calculating in C++ with the "default name", i.e., "inlet", "flame", "surface". Then, using the same restoration method by defining the object first, all the parts of the solution have been successfully restored.

cheers

justin li

unread,
Aug 6, 2025, 2:29:10 AMAug 6
to Cantera Users' Group
Well, after restoring the solution to post-process, another issue appears. 

gas = ct.Solution('BurkeH2.yaml')
H2Index = gas.species_names.index("H2")

width = 0.00384
surf_phase = ct.Interface("ptcombust2.yaml", "Pt_surf")
gas = surf_phase.adjacent["gas"]
sim = ct.ImpingingJet(gas=gas, width=width, surface=surf_phase)

fileName = "ConvecSurface"+str(int(vel))+"Unity.yaml"
sim.restore(fileName,"unity")

surfHrr1 = np.sum(surf_phase.net_rates_of_progress*surf_phase.delta_enthalpy)
print("surfHrr1=",surfHrr1/q_ref)
#print(sim.cp_mass[-1])
#print(sim.partial_molar_enthalpies[0:,-1])
surfHrr2 = np.sum(surf_phase.net_rates_of_progress*surf_phase.delta_enthalpy)
print("surfHrr2=",surfHrr2/q_ref)


The surfaceHrr1 and surfaceHrr2 above have different values, which have been further found to be related to the first call of any "high-ordered" quantities by the sim object, e.g., heat capacity and production rate. Once the "high-ordered" quantities are called, the variables are updated as the correct ones at the given basic state. (The two commented print lines have the same effects for correctly retrieving variables.)
在2025年8月4日星期一 UTC+8 23:49:32<justin li> 写道:

Ray Speth

unread,
Aug 15, 2025, 3:16:29 PMAug 15
to Cantera Users' Group

Hi Justin,

You’ve got quite a few things going on here; I’ll try to address as much as I can.

While there are no Ubuntu packages of Cantera 3.1 for Ubuntu 18.04, you should still be able to use the latest version if you install using Conda or Pip.

The first attempt at restoring, sim = ct.Sim1D.restore("ConvecSurface11.yaml","mix") is expected to fail. Here, you’re calling an instance method of the Sim1D class (restore), without first creating an instance of the class. The second approach, where you first instantiate a Solution object and use that to create a ImpingingJet object before calling restore is correct.

You’re right that the domain names need to match in order for the restoration to work correctly. While there isn’t a way to specify these names to the restore function, you can change the names on the ImpingingJet object before calling restore. For example:

sim = ct.ImpingingJet(gas=gas, width=width, surface=surf_phase) sim.inlet.name = 'inlet' sim.flame.name = 'flow' sim.surface.name = 'surf' sim.restore(fileName, "unity")

where those three names correspond to the names used in the original C++ simulation.

In the last issue, you’re getting hit by the fact that the reaction rates on the surface are dependent not only on the state of the surf_phase but also the gas phase object gas. Because the gas object is also being used by the Sim1D object for property calculations, its state may change after calculating any of these properties. The correct way to handle this is by setting the state of the gas to match the final grid point by calling sim.set_gas_state(sim.flame.n_points - 1) before accessing any properties of the surface phase that depend on the gas state. This can perhaps be viewed as a relative of the problem described in Enhancement #201.

Regards,
Ray

justin li

unread,
Sep 1, 2025, 8:56:26 AMSep 1
to Cantera Users' Group
Hi Ray,

Thanks for your patient answer!

It is all clear to me now.

Regards,
Justin

Reply all
Reply to author
Forward
0 new messages