| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 
 | #!/usr/bin/env python
#
# This example display wave.
#
# import
import matplotlib.pyplot as plot
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import pylab
import time
 
class Wave:
    """
    wave class
    A maximum amplitude (m)
    nu frequency in (Hz)
    wavelength in (m)
    phi0 initial phase (rad) 
    
    Amplitude harmonic plane wave
    u(r,t)=Acos(k.r-wt + phi0) 
    """
 
    def __init__ (self):
        print "Wave Instance"
        self.A = 1.0
        self.nu = 1.0
        self.lambdaWave = 1.0
        self.phi0 = 0.0
        # angular frequency rad.s-1
        self.w = 2*np.pi*self.nu
        # magnitude of wave vector m-1
        self.k = 2*np.pi/self.lambdaWave 
 
    def setWaveParameters(self,A,nu,lambdaWave,phi0):
        self.A = A
        self.nu = nu
        self.lambdaWave = lambdaWave
        self.phi0 = phi0
        # angular frequency rad.s-1
        self.w = 2*np.pi*self.nu
        # magnitude of wave vector m-1
        self.k = 2*np.pi/self.lambdaWave
 
    def printWave(self):
        # Display wave information
        print "Wave information"
        print "amplitude %s m" % self.A
        print "frequency %s Hz" % self.nu
        print "wavelength %s m" % self.lambdaWave
        print "initial phase %s rad" % self.phi0
        print "Dependent proprieties"
        print "angular frequency %s rad.s-1" % self.w
        print "magnitude of wave number %s m-1" % self.k
 
    def getAmplitudeHarmonicPlaneWave(self,x,t):
        r = x
        return np.float(self.A.np.cos(self.k*self.r-self.w*t+self.phi0))
 
    def getAmplitudeHarmonicCentralWave(self,x,y,t):
        r = x*x+y*y
        return np.float(self.A.np.cos(self.k*self.r-self.w*t+self.phi0))
 
wave1 = Wave()
wave1.printWave()
 
wave1.setWaveParameters(4.0, 3.0, 2.0, 0.0)
 
wave1.printWave()
 
plot.ion()
fig = plot.figure()
ax = Axes3D(fig)
 
xs = np.linspace(0,10,100)
ys = np.linspace(0,10,100)
X,Y = np.meshgrid(xs,ys)
 
Z = wave1.getAmplitudeHarmonicPlaneWave(X,0)
 
wframe = None
tstart =time.time()
for t in np.linspace(0,2*np.pi,100):
    oldcol=wframe
    Z = wave1.getAmplitudeHarmonicPlaneWave(X,t)
    wframe = ax.plot_surface(X, Y, Z, rstride=5, cstride=5, color='r')
 
    # Remove old line collection before drawing
    if oldcol is not None:
        ax.collections.remove(oldcol)
 
    plot.draw()
 
    print 'FPS: %f' % (100 / (time.time() - tstart)) |