Creating a simulator for Malkus waterwheels with Java

Over the weekend I used Java to create a simulator to demonstrate Malkus waterwheels, which is something I found out about while reading about chaos theory on Wikipedia.

The Malkus waterwheel is a special type of waterwheel that exhibits chaotic behaviour. This means that a small change in initial conditions can lead to very different motion in the wheel over time.

The waterwheel has several buckets that each have holes at the bottom for water to flow back out. The bucket at the top is filled by a tap.

I decided to use Java because I am learning it as my Duke of Edinburgh skills section and wanted to do a project to get some practice. The window is created by the Swing package but the AWT package is used to update the graphics every frame within a Swing JPanel.

Before I could do the project I had to research angular acceleration and polar coordinates. It is easier to represent the positions of the buckets using polar coordinates than Cartesian coordinates because the velocity and acceleration are calculated in radians/second. I convert the positions to Cartesian coordinates when I draw the buckets to the screen.

I came up with the following process for simulating the motion of the wheel:

  1. For each bucket, find the component of its weight acting perpendicular to the radius of the wheel. The parallel component can be ignored because it is balanced by the centripetal force.
  2. Add up all of the forces (weight components) acting perpendicular to the radius. Add a drag force acting in the opposite direction to the wheel’s angular velocity (proportional to the magnitude of the velocity) to find the resultant force causing the wheel to rotate.
  3. Calculate the angular acceleration \alpha of the wheel in radians/second using
    \alpha = \frac{F}{mr}
    where m is the mass of the wheel and the buckets with the water and r is the radius of the wheel.
  4. Each frame increase the wheel’s velocity by the acceleration divided by the frame rate (because the acceleration is the change in velocity every second, not every frame).

I placed two wheels side by side and gave them starting angles of 1.0° and 1.2° away from horizontal. Although the wheels start off about the same, they quickly diverge and start moving differently, even though the initial difference was only a fifth of a degree.

Here is a video of the program in action:

As you can see I added in graphs to show the centres of mass of the two wheels underneath. I also put in graphs of the velocity against the x an y coordinates of the centre of mass of the left wheel. These plot the distinctive shape of a Lorenz attractor (although the bottom one is upside down because the top of the y axis is 0 here when it’s usually the other way round). This proves that the waterwheel does follow the Lorenz equations, even though it is being modelled using Physics here instead.

Every frame the program writes the angular velocity and centre of mass data to a CSV file, which means I can plot graphs using Excel:

Leave a comment

Design a site like this with WordPress.com
Get started