In [ ]:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import animation
from JSAnimation import IPython_display
In [ ]:
g = 9.8 # Gravidade
denw = 1025.0 # Densidade da água do mar.
sig = 7.3e-2 # Tensão superficial [N/m].
a = 1.0 # Amplitude da onda.
#L = float(raw_input('Entre o comprimento de onda em metros. '))
#H = float(raw_input(r'Entre a profundidade da coluna d'água (10--5000 m) ')
L, H = 100.0, 50.0
# Numero de onda.
k = 2 * np.pi / L
# Frequência angular.
omega = np.sqrt((g * k + (sig / denw) * (k**3)) * np.tanh(k * H))
# Período.
T = 2 * np.pi / omega
# Velocidade de fase.
c = np.sqrt((g / k + (sig / denw) * k) * np.tanh(k * H))
x, z = np.meshgrid(np.arange(0, 160, 10), np.arange(0, -80, -10),)
u, w = np.zeros_like(x), np.zeros_like(z)
def compute_vel(ph):
u = a * omega * (np.cosh(k * (z+H)) / np.sinh(k*H)) * np.cos(k * x - ph)
w = a * omega * (np.sinh(k * (z+H)) / np.sinh(k*H)) * np.sin(k * x - ph)
mask = -z > H
u[mask] = 0.0
w[mask] = 0.0
return u, w
In [ ]:
def basic_animation(frames=91, interval=30, dt=0.3):
fig = plt.figure(figsize=(8, 6))
ax = plt.axes(xlim=(0, 150), ylim=(-70, 10))
# Animated line:
quiver = ax.quiver(x, z, u, w, units='inches', scale=2)
ax.quiverkey(quiver, 120, -60, 1,
label=r'1 m s$^{-1}$',
coordinates='data')
line, = ax.plot([], [], 'b')
# Non animated lines:
ax.plot([0, 150], [0, 0], 'k:')
ax.set_ylabel('Profundidade [m]')
ax.set_xlabel(u'Distância [m]')
ax.set_title(u'Velocidade do fluido e deslocamento da superfície livre')
text = (r'$\lambda$ = %s m; h = %s m; kh = %2.3f; h/L = %s' %
(L, H, k * H, H/L))
ax.text(10, -65, text)
time_step = ax.text(10, -58, '')
line.set_data([], [])
def init():
return line, quiver, time_step
def animate(i):
time = i * dt
pht = omega * time
eta = a * np.cos(x[0] * k - pht) # Elevação da superfície.
u, w = compute_vel(pht)
quiver.set_UVC(u, w)
line.set_data(x[0], 5 * eta)
time_step.set_text('Tempo = %s s' % time)
return line, quiver, time_step
return animation.FuncAnimation(fig, animate, init_func=init,
frames=frames, interval=interval)
In [ ]:
dt = 0.3
basic_animation(dt=dt)