Extensible reactor

118 views
Skip to first unread message

LGS

unread,
Jan 4, 2024, 5:01:40 PM1/4/24
to Cantera Users' Group
Hi all,

Cantera version: 3.0
Language: Python

I am using the extensible reactor framework to set up a mixing (multi-phase) system. I use the after_get_state to set the initial condition used by the ODE solver and would like to use _update_state to set the state of the Reactor (reactor.thermo) based on the new values for the state vector (y) but unable to do so. 

Say, i would like to modify the mass-fraction of a particular species i of the reactor to a value (y[i]*p) but the method reactor.Y is not writeable. And the same seems to be the case with mass, density or energy of the reactor. 

How should I go about achieving this?

Thank you for your help.

Best,
LGS

Ray Speth

unread,
Jan 5, 2024, 12:07:41 PM1/5/24
to Cantera Users' Group

Hi LGS,

There is a bit of a catch here for cases where you want to override the update_state behavior, caused by the normally clever behavior where accessing the reactor.thermo property automatically syncs the thermo object with the reactor’s state. In this case, I think what you want to do is use a different member variable to also reference the same Solution object but without triggering these automatic updates, for example naming this MyReactor.gas.

If you are replacing the update_state method, you should be sure to call MyReactor.update_connected so the new state is saved internally.

Also, note that there is no meaningful way to set a single mass fraction — you need to set the full mass fraction vector for the Solution object. The Reactor.Y property is just a shorthand accessor for Reactor.thermo.Y (which will trigger the same automatic updates).

Regards,
Ray

LGS

unread,
Jan 8, 2024, 10:55:49 AM1/8/24
to Cantera Users' Group
Hi Ray,

Thank you so much for the response. I am still a little confused and would appreciate your help in understanding it.

For before_ or after_update_state methods, are you suggesting that I use a new member variable (solution variable) to store the modified output of the ode solver at the end of each time step? 

Am I right in understanding, update_connected is required even when a reactor is used alone as in, when it is not connected any other reactors or reservoirs as a part of a network if I were to use replace_update_state?

I have one follow-up question about this. I am iterating a network of reactors through time,  while update_state and update_connected would update the reactor state based on the ODE integration and user modification, is there a way to modify the input to the ode solver (eval) within the extensible class function definitions? I believe get_state is accessed at t=0 (initialization), so any modified input to the ode integrator has to come from outside the class definition and cannot be included within any delegatable methods in extensible reactor.

Thank you once again.

Best,
LGS

Ray Speth

unread,
Jan 8, 2024, 6:15:01 PM1/8/24
to Cantera Users' Group

Hi,

Sorry, I misspoke. There is no way to call the update_connected method from Python, so I don’t think it’s currently possible to modify the state that’s internally held by the reactor and used to set the state of the ThermoPhase object at the start of the default version of eval. If you’re implementing a replace_eval method, this doesn’t matter, since you can set the gas state however you like, but it does limit the ability to use overrides of update_state effectively.

I have been planning on some updates to simplify the evaluation logic for Reactor governing equations. If you could share the code that you were expecting should work, or at least an outline of the modifications to the governing equations that you were interested in making, it would be useful to me to make sure that such changes are possible in the future.

Regards,
Ray

Reply all
Reply to author
Forward
0 new messages