Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 235
kame Avatar asked Feb 10 '11 11:02

kame


People also ask

Can Python be used for simulation?

In this tutorial, you'll learn how to use Python's simpy framework to create virtual simulations that will help you solve problems like these. In this tutorial, you'll learn how to: Use a simulation to model a real-world process. Create a step-by-step algorithm to approximate a complex system.

How do you solve a wave equation in Python?

assume packet never reaches boundary c=1.0 #speed of sound rsq=(c*dt/dx)**2 #appears in finite diff sol nx = int((xmax-xmin)/dx) + 1 #number of points on x grid nt = int((tmax-tmin)/dt) + 2 #number of points on t grid u = np. zeros((nt,nx)) #solution to WE #set initial pulse shape def init_fn(x): val = np.

What is wave simulation?

The Simple Wave Simulator Interactive provides the learner with a virtual wave machine for exploring the nature of a wave, quantitative relationships between wavelength, frequency and speed, and comparisons between transverse waves such as those traveling through a rope and longitudinal waves such as sound.


2 Answers

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.

like image 166
ptomato Avatar answered Sep 23 '22 01:09

ptomato


If you are solving 3D custom PDEs, I would recommend at least a look at FiPy. It'll save you the trouble of building a lot of your matrix conditioners and solvers from scratch. It uses numpy and/or trilinos. Here are some examples.

like image 21
Paul Avatar answered Sep 23 '22 01:09

Paul