Skip to content
Jacob Czech edited this page Jun 8, 2015 · 2 revisions

Warning: Some of the following details might not be entirely correct. However, this is my current understanding of how the scheduler works.

Overview

MCell uses a discretized multi-scale scheduler. The scheduler prepares certain events to be handled at predetermined simulation times. By default the schedulers change scale every factor of 100. As such, events within the next 100 iterations go into one scheduler, events within the next 10,000 iterations go into the next scheduler, and so on. Events from coarser time scales will be moved into the more granular time scale as we approach the scaling boundary.

What Gets Scheduled

The following items are handled by the scheduler: volume/surface molecules (timer), volume output (volume_output_scheduler), reaction output (count_scheduler), molecule releases (releaser), and dynamic geometries (dynamic_geometry_scheduler). Dynamic geometries are currently only handled in an experimental branch and won't be mentioned again. Unlike reaction data, visualization data is not handled by the scheduler.

The scheduling of volume and surface molecules is unique from other scheduled items, because there is a scheduler for each local storage. Storages are not the same as subvolumes and the number of subvolumes is likely different than the number of storages. Molecules can also be scheduled at sub-timestep intervals unlike the other items mentioned.

Having said that, it seems like release sites act sensibly if molecules are released at sub-timestep values. They are technically released before they should be, but they don't get picked off the timer scheduler until the proper time. For example if you are simulating with a timestep of 1e-6 and you release a molecule at 5e-7 seconds into the simulation, then the molecule will be released at 0 seconds, but won't diffuse (or react) until 5e-7.

Creating a Scheduler and Scheduling Events

Before doing anything else, a scheduler must be created using create_scheduler. Then the scheduler must then be populated using schedule_add/schedule_insert which takes a scheduler and the thing to be scheduled (e.g. a "timer" and a molecule). Some of these events are scheduled before the simulation even starts (molecule releases, reaction/volume output) and others are scheduled during the simulation (molecules). Each thing to be scheduled is stored as an abstract_element.

Retrieving Scheduled Events

Once events have been scheduled, we need to pull them out of the scheduler when they come up during a simulation. During mcell_run_iteration, we check for events (process_molecule_releases, process_reaction_output, process_volume_output) in the schedulers using schedule_next. If we are out of items for the current timestep, then we advance the scheduler in question (schedule_advance). This may require moving stuff from a coarser time scale to the current time scale.

For molecules, we run the timestep (run_timestep) for each local storage and then advance each timer scheduler (using schedule_advance called from schedule_next). We also use schedule_next near the beginning of run_timestep, but for a different purpose. It is used here to actually pull stuff off the scheduler, not to advance it. Most of the interesting stuff for run_timestep happens in one large while loop. We keep looping over the scheduler until there's nothing left in it.

For non-diffusing molecules, we advance the scheduling time of molecules up until the point when they should react. If they can't react, then we just bump it up by some large "arbitrary" value. We advance the schedule time for diffusing molecules by some variable amount. This can operate at values that are smaller or larger than the timestep and doesn't need to be an integer value. The logic for determining this amount is currently a little convoluted.

At the end of the main while loop in the timestep function, molecules which still exist will need to be rescheduled for a later timestep. Some molecules might need to be added to a different scheduler if they moved to a subvolume which uses a different storage. All of this is done using schedule_add. It's even possible for the same molecule to come up multiple times during the same timestep if its lifetime falls between the current timestep and the next timestep. This might happen for a unimolecular reaction or if a time-varying rate constant forces the lifetime to be recalculated.

Clone this wiki locally