Friedlander String

Del curso de CC. campus SJ.

Ondas 1D


In [7]:
from matplotlib import pyplot
import numpy
%matplotlib inline
from matplotlib import rcParams
rcParams['font.family'] = 'serif'
rcParams['font.size'] = 16

In [113]:
#Parámetros físicos
Lx = 10 #dimension x sistema
Ly = 5 #dimension y sistema
c = 340 #velocidad onda
R = 0.3 #coeficiente reflexion
f = 2000 #frecuencia fuente
w = 2*f*numpy.pi #vellocidad angular fuente
tiempo = 1 #cantidad de segundos


#Parámetros numéricos
dt = 1/10e3
nt =  int(numpy.floor(tiempo/dt))
s = 0.5 # s = (c*dt/dx)^2
dx = c*dt/s
dy = c*dt/s

#nodo de pulso
t0 = 0.1
n0 = numpy.floor(t0/dt)

nx = numpy.floor(Lx/dx)
ny = numpy.floor(Lx/dy)

#Ubicación de la fuente
xS = int(numpy.ceil(nx/2))
yS = int(numpy.ceil(ny/2))

In [108]:
# Función fuente

def source(n):
    return numpy.sin(w*dt*(n-n0))/(w*dt*(n-n0))

In [109]:
# Prueba de fuente

t = numpy.linspace(0,nt,1/dt)
pyplot.figure(figsize=(6,3))
pyplot.plot(t,source(t));



In [132]:
# Espacio 2D

x = numpy.linspace(0,Lx,nx)
y = numpy.linspace(0,Ly,ny)
    
pp = numpy.zeros(nx,ny)
pa = numpy.empty_like(pp)
pf = numpy.empty_like(pp)


/home/fmena/anaconda3/lib/python3.5/site-packages/ipykernel/__main__.py:6: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-132-60250ac17919> in <module>()
      8 pf = numpy.empty_like(pp)
      9 
---> 10 pp.size()

TypeError: 'int' object is not callable

In [119]:
def ondas_2D(x,y,pp,pa,pf):
    
    X, Y = numpy.meshgrid(x,y)
    
    pf = 2*pa[1:-1,1:-1] - pp[1:-1,1:-1] #+ (dt*c)**2*((pa[2:,1:-1]-2*pa[1:-1,1:-1]+pa[:-2,1:-1]) + (pa[1:-1,2:]-2*pa[1:-1,1:-1]+pa[1:-1,:-2]))
    
    pp = pa
    pa = pf
    pf = numpy.zeros_like(pp)

In [117]:
def plot_3D(x, y, p):
    '''Creates 3D plot with appropriate limits and viewing angle
    
    Parameters:
    ----------
    x: array of float
        nodal coordinates in x
    y: array of float
        nodal coordinates in y
    p: 2D array of float
        calculated potential field
    
    '''
    fig = pyplot.figure(figsize=(11,7), dpi=100)
    ax = fig.gca(projection='3d')
    X,Y = numpy.meshgrid(x,y)
    surf = ax.plot_surface(X,Y,p[:], rstride=1, cstride=1, cmap=cm.viridis,
            linewidth=0, antialiased=False)

    ax.set_xlim(0,1)
    ax.set_ylim(0,1)
    ax.set_xlabel('$x$')
    ax.set_ylabel('$y$')
    ax.set_zlabel('$z$')
    ax.view_init(30,45)

In [120]:
for n in range(1,nt):
    ondas_2D(x,y,pp,pa,pf)
    
    plot_3D(pa)


---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-120-cdf571e1d38c> in <module>()
      1 for n in range(1,nt):
----> 2     ondas_2D(x,y,pp,pa,pf)
      3 
      4     plot_3D(pa)

<ipython-input-119-44b52c6d5ea5> in ondas_2D(x, y, pp, pa, pf)
      3     X, Y = numpy.meshgrid(x,y)
      4 
----> 5     pf = 2*pa[1:-1,1:-1] - pp[1:-1,1:-1] #+ (dt*c)**2*((pa[2:,1:-1]-2*pa[1:-1,1:-1]+pa[:-2,1:-1]) + (pa[1:-1,2:]-2*pa[1:-1,1:-1]+pa[1:-1,:-2]))
      6 
      7     pp = pa

IndexError: too many indices for array

In [101]:
print(nt)
int(nt)


10000.0
Out[101]:
10000

In [ ]: