29
Jul
05

### Water Ripple Simulation

Here is a simple water ripple simulation showing single slit wave diffraction. The following Mathematica code solves the wave equation with damping using the finite difference method. You can read more about this algorithm on Hugo Elias’ website. (Note: technically this simulation should use Neumann boundary conditions but I decided it was simplier to demonstrate using Dirichlet boundary conditions).

`(* runtime: 18 seconds, c is the wave speed and b is a damping factor *) n = 64; c = 1; b = 5; dx = 1.0/(n - 1); Courant = Sqrt[2.0]/2;dt = Courant dx/c; z1 = z2 = Table[0.0, {n}, {n}]; Do[{z1, z2} = {z2, z1}; z1[[n/2, n/4]] = Sin[16Pi t]; Do[If[0.45 < i/n < 0.55 || ! (0.48 < j/n < 0.52), z2[[i, j]] = (2(1 - 2Courant^2)z1[[i, j]] + Courant^2(z1[[i - 1, j]] + z1[[i + 1, j]] + z1[[i, j - 1]] + z1[[i, j + 1]]))/(1 + b dt) - z2[[i, j]]], {i, 2, n - 1}, {j, 2, n - 1}]; ListPlot3D[z1, Mesh -> False, PlotRange -> {-1, 1}], {t, 0, 1, dt}];`

#### 2 Responses to “Water Ripple Simulation”

1. 1 S Lakshmi Narasimhan
April 15, 2010 at 8:12 pm

Frankly i did not understand the algorithm althogh i got the idea of how you transfer of data from one buffer frame to the next .
For example the arrays of integers ?Of what size?
And why do you have this sort of code….Buffer2(x, y) = (Buffer1(x-1,y)
Buffer1(x+1,y)
Buffer1(x,y+1)
Buffer1(x,y-1)) / 2 – Buffer2(x,y)
I did not understand what this exactly is ….although it looks like the coordinates of previous pts. are taken by the next array …
And similarly the spreading code …Smoothed(x,y) = (Buffer1(x-1, y) +
Buffer1(x+1, y) +
Buffer1(x, y-1) +
Buffer1(x, y+1)) / 4

2. 2 realflow100
July 26, 2010 at 12:22 am

AWESOME!

## Welcome !

You will find here some of my favorite hobbies and interests, especially science and art.

I hope you enjoy it!

Subscribe to the RSS feed to stay informed when I publish something new here.

I would love to hear from you! Please feel free to send me an email : bugman123-at-gmail-dot-com