This example is interactive. Click the play button on any cell to execute it, or run all cells in sequence.

Van der Pol

Simulation of the Van der Pol oscillator, a classic example of a stiff dynamical system.

You can also find this example as a single file in the GitHub repository.

The Van der Pol oscillator is described by the following 2nd order ODE

MATHDISPLAY0ENDMATH

where the parameter :math:`\mu` controles the stiffness of the system. Stiffness in dynamical systems typically arises when the (local) internal time constants (eigenvalues of the Jacobian) are on different scales, or when very steep gradients are encountered.

ODE solvers for stiff systems require large stability regions and therefore are usually implicit. PathSim has a huge range of implicit solvers (i.e. ESDIRK32, ESDIRK43, GEAR52A, ...), that can be used to solve stiff systems, such as the Van der Pol system with very large :math:`\mu`, reliably. Lets see how this works.

PathSim supplies a specific block to define differential equations, the ODE block. To accept the Van der Pol system, we have to convert the 2nd order ODE into a system of 1st order ODEs:

MATHDISPLAY0ENDMATH

As a block diagram it would look like this:

block diagram of ODE block and Scope

And translated to PathSim like this:

Python
Loading...
12:44:12 - INFO - LOGGING (log: True)
12:44:12 - INFO - BLOCKS (total: 2, dynamic: 1, static: 1, eventful: 0)
12:44:12 - INFO - GRAPH (nodes: 2, edges: 1, alg. depth: 1, loop depth: 0, runtime: 0.028ms)

Here we define the paramter :math:`\mu = 1000` (btw. :math:`\mu = 10000` also works), which means severe stiffness! This is pretty much a torture test for stiff ODE solvers.

Lets run the simulation and look at the results:

Python
Loading...
12:44:12 - INFO - STARTING -> TRANSIENT (Duration: 4000.00s)
12:44:12 - INFO - --------------------   2% | 0.0s<0.1s | 1211.2 it/s
12:44:13 - INFO - ####----------------  20% | 0.1s<6.1s | 1211.9 it/s
12:44:13 - INFO - ########------------  40% | 0.3s<1.9s | 1015.2 it/s
12:44:13 - INFO - ############--------  60% | 0.5s<0.4s | 928.9 it/s
12:44:13 - INFO - ################----  80% | 0.7s<0.1s | 1013.7 it/s
12:44:13 - INFO - #################### 100% | 0.9s<--:-- | 959.6 it/s
12:44:13 - INFO - FINISHED -> TRANSIENT (total steps: 817, successful: 567, runtime: 900.71 ms)
Output