extracting timestep data via. callback functions.

54 views
Skip to first unread message

Marina Kovaleva

unread,
Feb 13, 2024, 2:39:30 AM2/13/24
to Cantera Users' Group
Hello,

I am having some trouble with callback functions for capturing info at each timestep for 1D simulations. The simulation runs successfully, but the timestep and steady-state callback functions are only activated once for the simulation, but the stats show multiple timesteps. I am wondering how to get datasets for many timesteps.

Code files attached:
- mech (UCSD)
- code file + run file -code is run from an instance of TimeStepCantera()


run.py
ucsd.yaml
timestep_test.py

Marina Kovaleva

unread,
Feb 13, 2024, 8:41:12 AM2/13/24
to Cantera Users' Group
Just to clarify my question - the callback function only activates once during the simulation. I would like to know how to activate it for every time the timestep advances? Thank you in advance for your help and support.

Marina

Ray Speth

unread,
Feb 13, 2024, 1:22:32 PM2/13/24
to Cantera Users' Group

Hi Marina,

You need to pass the callback function itself to the set_time_step_callback method. What you’re doing is calling the callback at a specific time, then passing the result of that (the None object) to set_time_step_callback, which is the way to specify that there is no callback function. Also, because of the way that it’s implemented, the callback function needs to return a number; this value is arbitrary, since it is not actually used.

For example, you want to write something like:

def timestep_callback(_): print("timstep callback") return 0.0

and then later for the setup:

self.f.set_time_step_callback(timestep_callback)

Hope this helps.

Regards,
Ray

Reply all
Reply to author
Forward
0 new messages