Benchmark the Finite Differences solver for the elastic wave propagation


In [1]:
%pylab inline
from fatiando import gridder, vis
from fatiando.seismic import wavefd


Welcome to pylab, a matplotlib-based Python environment [backend: module://IPython.zmq.pylab.backend_inline].
For more information, type 'help(pylab)'.

SH waves


In [2]:
# Make a wave source from a mexican hat wavelet
sources = [wavefd.MexHatSource(25, 25, 100, 0.5, delay=1.5)]
# Set the parameters of the finite difference grid
shape = (200, 200)
spacing = (250, 250)
area = (0, spacing[1]*shape[1], 0, spacing[0]*shape[0])
# Make a density and S wave velocity model
dens = 2700*ones(shape)
svel = 3000*ones(shape)
dt = 0.05
maxit = 400

In [3]:
%timeit -n 5 [u for u in wavefd.elastic_sh(spacing, shape, svel, dens, dt, maxit, sources, padding=0.5)]


5 loops, best of 3: 1.31 s per loop

In [4]:
def run():
    for u in wavefd.elastic_sh(spacing, shape, svel, dens, dt, maxit, sources, padding=0.5):
        continue
%prun -T seismic_wavefd.elastic_sh.profile run()
!cat seismic_wavefd.elastic_sh.profile


 
*** Profile printout saved to text file u'seismic_wavefd.elastic_sh.profile'. 
         2409 function calls in 1.317 seconds

   Ordered by: internal time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
      399    0.776    0.002    0.776    0.002 {fatiando.seismic._cwavefd._apply_damping}
      399    0.516    0.001    0.516    0.001 {fatiando.seismic._cwavefd._step_elastic_sh}
      402    0.011    0.000    1.316    0.003 wavefd.py:382(elastic_sh)
      400    0.008    0.000    0.008    0.000 wavefd.py:229(__call__)
      399    0.002    0.000    0.002    0.000 {fatiando.seismic._cwavefd._boundary_conditions}
        1    0.002    0.002    0.002    0.002 wavefd.py:331(_add_pad)
        2    0.001    0.001    0.001    0.001 {numpy.core.multiarray.zeros}
        1    0.000    0.000    1.317    1.317 <ipython-input-4-1bad3f344c47>:1(run)
      400    0.000    0.000    0.000    0.000 wavefd.py:237(coords)
        1    0.000    0.000    1.317    1.317 <string>:1(<module>)
        3    0.000    0.000    0.000    0.000 wavefd.py:421(<genexpr>)
        1    0.000    0.000    0.000    0.000 {max}
        1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}

P and SV waves


In [11]:
# Make a wave source from a mexican hat wavelet
sources = [wavefd.MexHatSource(25, 25, 100, 0.5, delay=1.5)]
# Set the parameters of the finite difference grid
shape = (100, 100)
spacing = (500, 500)
area = (0, spacing[1]*shape[1], 0, spacing[0]*shape[0])
# Make a density and S wave velocity model
dens = 2700*ones(shape)
svel = 3000*ones(shape)
pvel = 4000*ones(shape)
dt = 0.05
maxit = 300

In [12]:
%timeit -n 5 [u for u in wavefd.elastic_psv(spacing, shape, pvel, svel, dens, dt, maxit, sources, sources, padding=0.5)]


5 loops, best of 3: 963 ms per loop

In [13]:
def run():
    for u in wavefd.elastic_psv(spacing, shape, pvel, svel, dens, dt, maxit, sources, sources, padding=0.5):
        continue
%prun -T seismic_wavefd.elastic_psv.profile run()
!cat seismic_wavefd.elastic_psv.profile


 
*** Profile printout saved to text file u'seismic_wavefd.elastic_psv.profile'. 
         3309 function calls in 0.965 seconds

   Ordered by: internal time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
      299    0.325    0.001    0.325    0.001 {fatiando.seismic._cwavefd._step_elastic_psv_x}
      299    0.316    0.001    0.316    0.001 {fatiando.seismic._cwavefd._step_elastic_psv_z}
      598    0.301    0.001    0.301    0.001 {fatiando.seismic._cwavefd._apply_damping}
      302    0.011    0.000    0.965    0.003 wavefd.py:502(elastic_psv)
      600    0.009    0.000    0.009    0.000 wavefd.py:229(__call__)
      598    0.001    0.000    0.001    0.000 {fatiando.seismic._cwavefd._boundary_conditions}
        2    0.001    0.001    0.001    0.001 wavefd.py:331(_add_pad)
        1    0.000    0.000    0.965    0.965 <ipython-input-13-887484d2d225>:1(run)
      600    0.000    0.000    0.000    0.000 wavefd.py:237(coords)
        4    0.000    0.000    0.000    0.000 {numpy.core.multiarray.zeros}
        3    0.000    0.000    0.000    0.000 wavefd.py:545(<genexpr>)
        1    0.000    0.000    0.965    0.965 <string>:1(<module>)
        1    0.000    0.000    0.000    0.000 {max}
        1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}

In [ ]: