ContinuousTime.rst 2.7 KB

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