how to set the temperature of a reactor

88 views
Skip to first unread message

Gianfranco Dell'Agli

unread,
Jan 4, 2026, 7:35:01 PMJan 4
to Cantera Users' Group
Dear all, I’m facing an issue with Cantera (version 3.2) that I haven’t been able to solve. I want to build a model of a combustion flue‑gas heat exchanger to analyze the chemical transformations occurring during cooling. I have assumed a temperature profile and I know the residence time of the flue gases inside the exchanger.

Following the Lagrangian approach suggested in the examples on the website, I would like to integrate in time using an IdealGasReactor, but with the temperature profile imposed by me rather than determined by the energy equation. Unfortunately, I haven’t found any way to set directly the reactor temperature: even calling syncState() after assigning the new temperature to the gas phase doesn’t work.

The only workaround I’ve found is to add a wall connected to a reservoir at the desired temperature and assign a very large heat‑transfer coefficient to the wall. Unfortunately, this approach is numerically unstable (on my old PC) and computationally expensive.

Does anyone have any suggestions or know of an alternative method? Thanks in advance,
Gianfranco

Andrea Locaspi

unread,
May 22, 2026, 9:36:00 AM (11 days ago) May 22
to Cantera Users' Group
Hi Gianfranco,

it might be a late reply, but I tried to do something similar. In my case I wanted to impose the derivative of the temperature, and I used the extensible reactor class, overwriting the temperature equation with after_eval. 

In my case, I wanted to impose a linear temperature increase with a heating rate (HR) in K/min. The python code looks like:

gas = ct.Solution("gas.yaml")
gas_reactor = _RampGasReactor(gas, energy="on", volume=V_gas0, HR=HR)

class _RampGasReactor(ct.ExtensibleIdealGasMoleReactor):
    """IdealGasMoleReactor with energy equation replaced by dT/dt = HR/60."""

    def __init__(self, *args, HR=10.0, **kwargs):
        super().__init__(*args, **kwargs)
        self._dTdt = HR / 60.0  # K/s
        self._iT = None

    def after_eval(self, t, LHS, RHS):
        if self._iT is None:
            self._iT = self.component_index("temperature")
        LHS[self._iT] = 1.0
        RHS[self._iT] = self._dTdt

You have to be careful however with the ideal reactor you are using, for instance the ConstPressure reactor uses the enthalpy as equation rather than the temperature one. I am using cantera 4.0 built from github source code, I think this should work also with your version as it has documentation on the current stable version on the website. 

A much simpler approach if your reactive system is not too complex, could be to update manually after each time step the temperature of the phases, but I am not sure if this results in weird behaviours if the manually set time-steps are not sufficiently small. 

Hope this helps,
Andrea

Reply all
Reply to author
Forward
0 new messages