| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- Continuous Time Simulation
- ==========================
- Given that continuous time simulation will always have to be discretized when
- executed, it is important to ask *how* this discretization happens. In the
- :doc:`SinGen` example, this was done by reducing the delta inbetween multiple
- steps. However, this may compute too often for what is required in a given
- simulation. Assume we have the following data (from a sine wave):
- .. figure:: ../_figures/stepsize/sine.png
- :width: 600
- Fixed Step Size
- ---------------
- With the previously discussed technique, the data could be plot using a fixed
- step size, where the new data is being computed every :code:`dt` time. The
- smaller this :code:`dt` value is, the more precise the plot. Below, the same
- function has been plot twice, for :code:`dt = 0.5` and :code:`dt = 0.1`, where
- the marked points on the plot highlight *when* the data has been recomputed. It
- is clear from these plots that a smaller step size identifies more accurate
- results.
- .. figure:: ../_figures/stepsize/sine-5.png
- :width: 600
- .. figure:: ../_figures/stepsize/sine-1.png
- :width: 600
- This behaviour is the default in the simulator. To explicitly set it, make use of
- the :class:`CBD.stepsize.Fixed` class as follows (assuming :code:`sim` is the
- simulator object):
- .. code-block:: python
- sim.setStepSize(Fixed(0.5))
- # OR, EQUIVALENTLY
- sim.setStepSize(0.5)
- Yet, when the step size logic has been untouched since the creation of the
- simulator instance, the normal :func:`CBD.simulator.Simulator.setDeltaT` can be
- used as well.
- This was done for academic reasons, as it is much easier to explain CBDs with a
- fixed step size, as compared to varying step sizes.
- Euler 2-Step
- ------------
- Variable step size algorithms continuously increases or decreases the :code:`dt`
- to allow for less steps to be taken. Whenever the simulation fluctuates a lot,
- :code:`dt` will be small. However, if there are only small changes, it will be
- large.
- The `Euler 2-Step` does this by (approximately) halving/doubling the current
- :code:`dt`, trying to get the best match for the given data. More information on
- the actual algorithm can be found in the documentation for
- :class:`CBD.stepsize.Euler2` and `professor Joel Feldman's notes on variable step
- size algorithms <http://www.math.ubc.ca/~feldman/math/vble.pdf>`_.
- It can be set on the simulator object as follows:
- .. code-block:: python
- sim.setStepSize(Euler2(0.1, 0.005))
- For the sine wave example, with any starting delta and an acceptance error epsilon
- of :code:`0.005`, the following plot is obtained. Note that a decrease of the
- epsilon will make the plot more precise.
- .. figure:: ../_figures/stepsize/sine-euler2.png
- :width: 600
|