Time

The Concept of Time in Simulations

In SIMION, there are a couple different concepts of time. First, there is the time (t) that occurs experimentally in the instrument you are designing, such as a one microsecond time for particles at a cathode to reach an anode. Second, there is the time (T) at which that system is simulated on the CPU. T may bear little resemblance to t in terms of their durations and chronology. For example, just because one ray may emit from a cathode before another ray does not necessarily mean we must calculate the trajectories of those rays in that order, and the time required to make that calculation could be orders of magnitude shorter of longer than the actual experiment. Third, there is the time in which the results of the simulation are visualized on the screen for the user, which in SIMION is often the same as T because calculation and visualization are normally done concurrently, but these could be different if you replayed the trajectories with the flying as Dots option or captured it as a movie and replayed it at a different speed. The visualization speed is typically intentionally much slower than t since microsecond timeframes are too fast for human perception.

Further breaking down simulation time: Since your CPU may be doing other tasks at the same time it is calculating your simulation (e.g. web browsing or waiting for disk and memory I/O) and you may even temporarily pause the simulation (Pause checkboxes on Particles tab), we may also consider just the portion of T in which the CPU is actively doing your calculation. The term wall-clock time is used to refer to the total time T (see Wikipedia:Wall_clock_time), and CPU time may refer to just the portion. There may also be multiple CPUs or cores involved.

Note

This page is abridged from the full SIMION 8.1.1 "Supplemental Documentation" (Help file). The following additional sections can be found in the full version of this page accessible via the "Help > Supplemental Documentation" menu in SIMION 8.1.1:
  • Relationship of T v.s. t
  • User Programming Cautions

Time of Birth (TOB)

Particles may need to start flying at different experimental times (t), such as if emitted from a cathode or ion source at different times. In order to simulate this in SIMION, each particle has a unique Time of Birth (TOB) value in microseconds, defined as the time the particle starts flying, measured relative to time t=0. TOB is defined for each particle in the particle definitions and is normally set to TOB=0 unless you select otherwise.

TOB often can be ignored and left at zero:

  • For static fields, TOB normally has no effect on the shape of particle trajectories. Two identical particles with different TOB values will traverse the same trajectory, just arrive at a time shifted by the TOB.

But TOB can be important in certain situations:

  • For time-dependent fields, the forces a particle will see in any point in space will depend on the time it reaches that point. So, TOB affects the shape of the trajectory.
  • But even for static fields, you still may want to set TOB in order to properly keep track of the arival times of particles.
  • For time-dependent fields that are also periodic, such as from an RF voltage, all that might matter is one period of the waveform. You may want to uniformly distribute the TOB over the RF period to accurately represent trajectories starting at all phases of the RF cycle. The SIMION Example: quad does this by setting the TOB in the particle definitions to a uniform distribution of 0.9 microseconds (the RF period).

TOB can be reported by Data Recording. TOB is also accessible from user programs via the ion_time_of_birth variable. It can also be changed in an initialize segment, which is just before a particle starts flying.

Time of Flight (TOF)

The Time of Flight (TOF) in SIMION is the current time of the particle being traced, measured from time t=0 (not t=TOB). It is accessible via Data Recording and the ion_time_of_flight variable in user programs. Technically the SIMION “time of flight” is not the “time the particle has actually been flying” since that is rather ion_time_of_flight - ion_time_of_birth unless (the typical case) of zero time of birth.

ion_time_of_flight is required for things like Time-Dependent Field because it’s the time inputted into the equation for the waveform used, like adj_elect01 = sin(ion_time_of_flight * w) .

Units

SIMION time units are usually microseconds (μsec). This includes Particles Define (time of birth: TOB), Data Recording (time of flight: TOF), and user programming reserved variables (e.g. ion_time_of_flight and ion_time_step). Other units can be in terms of microseconds–e.g. velocity is typically in mm per microsecond.

Lua

The os.time() function is a measure of the date or wall-clock time. On Windows, it returns the number of seconds since 1970 (the epoch date) and has a resolution of one second. The os.clock() function technically returns an approximation of the amount of CPU time used by the program; this meaning is OS dependent and not always wall-clock time, but on Windows it is the amount of wall-clock time since the start of the program and has a resolution on the order of a microsecond, so it can be more precise than os.time if you need to measure times less than a few seconds. These functions can be useful for benchmarking, as well as for record keeping:

local t1 = os.time()
do_some_calculation()
local dt = t1 - os.time()
print('dt=', dt, 'seconds', 'timestamp=', os.date())

The simion.sleep() function will wait for the given number of seconds (which may be a fraction), without freezing the program. simion.run_stop() will pause the program pending the user pressing a key.

See also Programming in Lua, 22.1 - Date and Time and lua-users.org DataAndTime.

Time-Dependent Fields

For information on time-dependent fields, including RF fields and varying electrode voltages, see Time-Dependent Field.