Search code examples
pythonnumpysimulationphysicswave

Wave Simulation with Python


I want to simulate a propagating wave with absorption and reflection on some bodies in three dimensional space. I want to do it with python. Should I use numpy? Are there some special libraries I should use?

How can I simulate the wave? Can I use the wave equation? But what if I have a reflection? Is there a better method? Should I do it with vectors? But when the ray diverge the intensity gets lower. Difficult.

Thanks in advance.


Solution

  • If you do any computationally intensive numerical simulation in Python, you should definitely use NumPy.

    The most general algorithm to simulate an electromagnetic wave in arbitrarily-shaped materials is the finite-difference time domain method (FDTD). It solves the wave equation, one time-step at a time, on a 3-D lattice. It is quite complicated to program yourself, though, and you are probably better off using a dedicated package such as Meep.

    There are books on how to write your own FDTD simulations: here's one, here's a document with some code for 1-D FDTD and explanations on more than 1 dimension, and Googling "writing FDTD" will find you more of the same.

    You could also approach the problem by assuming all your waves are plane waves, then you could use vectors and the Fresnel equations. Or if you want to model Gaussian beams being transmitted and reflected from flat or curved surfaces, you could use the ABCD matrix formalism (also known as ray transfer matrices). This takes into account the divergence of beams.