advance_to_steady_state() in C++ cantera

101 views
Skip to first unread message

Cristopher Morales

unread,
Apr 9, 2025, 2:39:08 AM4/9/25
to Cantera Users' Group
Hi All,

I hope you are doing well,

I would like to ask you about if this function is available in Cantera C++,
I have seen examples using it in Python but I have not been able to find it in the C++ files.
Could you please guide me about how this one can be created using the advance(double delta_time) function available? I read that in the python version, internally the unsteady solution is computed until there is no change in composition. I would really appreciate any help about it. 
Thank you so much in advance!!!

Best regards,

Cristopher Morales Ubal 

Cristopher Morales

unread,
Apr 29, 2025, 7:49:25 AM4/29/25
to Cantera Users' Group
Hi, 

I hope you are doing well, could someone guide about how to understand the integration is done for a batch reactor? where exactly in the code does this integration occur? I want to debug that part because for some reason when I used advance(time) in cantera C++, even at a low temperature 300K and a very small time step (10^-15), the species mass fractions change which I think should not occur.

Thank you so much in advance!!!!

Cristopher Morales Ubal

Ray Speth

unread,
May 28, 2025, 11:01:42 PM5/28/25
to Cantera Users' Group

Hi Christopher,

The Cantera documentation contains a page providing some details on how time integration works.

For your mixture, I’d suggest looking at the initial net production rates of the species and the net rates of progress for the reactions. At least some of them should be non-zero, although they will be quite small. Using the GRI 3.0 mechanism for an initial methane/air mixture at 300 K, the largest net production rates are around 1e-35 kmol/m^3/s, and after one time step of 1e-15 seconds, the largest changes to the mass fractions are around 1e-48, which seems consistent with those production rates. All of these values are effectively zero within the absolute tolerances of the integrator.

Regards,
Ray

Cristopher Morales

unread,
Jun 12, 2025, 12:19:17 PM6/12/25
to Cantera Users' Group
Hi Ray,

Thank you so much for your answer,

I am trying to compute the reaction rate as it is proposed in the paper Direct Numerical Simulation of Chemically Reacting Flows with the Public Domain Code OpenFOAM | SpringerLink

reaction_rate_openfoam.JPG

where C_k is the molar concentration and Mk is the molecular weight of the species k.
I can compute correctly the reaction rate for H2, but for other species such as H2O , O2, these reactions rates are order of magnitude different when I compare them with the reaction rates obtained using the GetNetProductionRates * MolecularWeight. 
I have read the page that you suggested me, and I would like to ask you if you could guide me about where the mass fractions are updated within Cantera C++. I checked LHS and RHS terms in Cantera and I can see how the equations are solved but I would like to further understand how the species mass fractions are updated in order to try to compute the reaction rates as it is proposed in the aforementioned paper. 
LHS_RHS_CANTERA.JPG
Many thanks in advance,
Looking forward to your answer,

Best regards,

Cristopher Morales Ubal 

Ray Speth

unread,
Jun 13, 2025, 3:31:33 PM6/13/25
to Cantera Users' Group

Hi Christopher,

Are you trying to re-implement the calculation of the reaction rates from the rate parameterizations and the stoichiometric coefficients? What’s shown in that diagram is that they use Cantera not only to compute the reaction rates and species production rates, but also to do the time integration of the local reaction term. But the equations written are only a subset of what’s actually being solved — this is missing the calculation of the backwards rate constant from the equilibrium constant for each reaction, the various reactions that are not parameterized as just modified Arrhenius rates, and the reactions that have third-body effects that need to be accounted for. If you’re just doing this for your own edification, you might have better luck comparing some of the intermediate quantities that Cantera can provide, such as the rates of progress for each reaction (getFwdRatesOfProgress and getRevRatesOfProgress) or even just the rate constants (getFwdRateConstants). It will be easier to see where your calculation is going wrong by looking at individual reactions, rather than looking at the net production rate for a species, where this result is the combination of all reactions involving that species.

In the ReactorNet::eval method, as described on the page I linked to, the state of the ThermoPhase is updated within the Reactor::updateState method.

Regards,
Ray

Reply all
Reply to author
Forward
0 new messages