.. index:: clock

Clocks
------

.. currentmodule:: brian

.. index::
   single: clock; default clock
   single: default clock

Many Brian objects store a clock object (always passed in the 
initialiser with the keyword ``clock=``...). If no clock is specified,
the program uses the global default clock. When Brian is initially
imported, this is the object :data:`defaultclock`, and it has a default
time step of 0.1ms. In a simple script, you can override this by
writing (for example)::

	defaultclock.dt = 1*ms

However, there are other ways to access or redefine the default
clock (see functions below).

.. index::
   single: clock; multiple clocks
   single: multiple clocks

You may wish to use multiple clocks in your program. In this case,
for each object which requires one, you have to pass a copy of its
:class:`Clock` object. The network run function automatically handles objects
with different clocks, updating them all at the appropriate time
according to their time steps (value of :attr:`~Clock.dt`).

Multiple clocks can be useful, for example, for defining a simulation
that runs with a very small ``dt``, but with some computationally
expensive operation running at a lower frequency. 

The :class:`Clock` class
~~~~~~~~~~~~~~~~~~~~~~~~

.. autoclass:: Clock
.. autoclass:: EventClock
.. autoclass:: FloatClock
.. autoclass:: NaiveClock
.. autoclass:: RegularClock

.. index::
   single: clock; default clock
   single: default clock

The default clock
~~~~~~~~~~~~~~~~~

.. data:: defaultclock

    The default clock object
    
    Note that this is only the default clock object if you haven't
    redefined it with the :func:`define_default_clock` function or the
    ``makedefaultclock=True`` option of a :class:`Clock` object. A safe way to
    get hold of the default clock is to use the functions:
    
    * :func:`get_default_clock`
    * :func:`reinit_default_clock`
    
    However, it is suitable for short scripts, e.g.::
    
        defaultclock.dt = 1*ms
        ...

.. autofunction:: define_default_clock
.. autofunction:: reinit_default_clock
.. autofunction:: get_default_clock
