Skip to main content

2nd-order elastic horizontal free-surface

This notebook explores a less-commonly used formulation of the elastic wave equation, the second-order system of equations, given by Kelly et al. 1976.

# Load the signed distance function for the boundary geometry
import pickle
import matplotlib.pyplot as plt
import numpy as np

def read_sdf(surface):
    """Unpickle an sdf"""
    fname = 'sdfs/' + surface + '.dat'
    with open(fname, 'rb') as f:
        sdf = pickle.load(f)
    return sdf

# Load the horizontal 2D sdf
sdf = read_sdf('flat_surface_2d')


plt.imshow(sdf.data.T, origin='lower')
plt.title("Boundary geometry SDF")
plt.colorbar()
plt.show()

from schism import BoundaryGeometry
bg = BoundaryGeometry(sdf)
grid = bg.grid  # Gets the grid from the signed distance function
Operator `normals` ran in 0.01 s
import devito as dv
import numpy as np
import matplotlib.pyplot as plt

s_o = 4

ux = dv.TimeFunction(name='ux', grid=grid, space_order=s_o, time_order=2)
uy = dv.TimeFunction(name='uy', grid=grid, space_order=s_o, time_order=2)

# Material parameters
rho = 1.
mu = 0.25
lam = 0.5

# Shorthand
b = 1./rho
from schism import BoundaryConditions

nx = bg.n[0]
ny = bg.n[1]

# With fourth-order boundary conditions
bc_list = [dv.Eq(nx*(lam+2*mu)*ux.dx + nx*lam*uy.dy
                 + ny*mu*ux.dy + ny*mu*uy.dx, 0),
           dv.Eq(nx*mu*ux.dy + nx*mu*uy.dx
                 + ny*(lam+2*mu)*uy.dy + ny*lam*ux.dx, 0),
           dv.Eq(lam*mu*nx*uy.dy3 + mu**2*ny*ux.dy3
                 + ux.dx2dy*ny*(lam**2 + 2*lam*mu + 2*mu**2)
                 + ux.dx3*nx*(lam**2 + 4*lam*mu + 4*mu**2)
                 + ux.dxdy2*nx*(2*lam*mu + 3*mu**2)
                 + uy.dx2dy*nx*(lam**2 + 3*lam*mu + mu**2)
                 + uy.dx3*ny*(lam*mu + 2*mu**2)
                 + uy.dxdy2*ny*(lam**2 + 3*lam*mu + 3*mu**2), 0),
           dv.Eq(lam*mu*ny*ux.dx3 + mu**2*nx*uy.dx3
                 + ux.dx2dy*nx*(lam**2 + 3*lam*mu + 3*mu**2)
                 + ux.dxdy2*ny*(lam**2 + 3*lam*mu + mu**2)
                 + ux.dy3*nx*(lam*mu + 2*mu**2)
                 + uy.dx2dy*ny*(2*lam*mu + 3*mu**2)
                 + uy.dxdy2*nx*(lam**2 + 2*lam*mu + 2*mu**2)
                 + uy.dy3*ny*(lam**2 + 4*lam*mu + 4*mu**2), 0)]

bcs = BoundaryConditions(bc_list)
from schism import Boundary

boundary = Boundary(bcs, bg)

derivs = (ux.dx2, ux.dy2, ux.dxdy, uy.dx2, uy.dy2, uy.dxdy)

subs = boundary.substitutions(derivs)
Generating stencils for Derivative(ux(t, x, y), (x, 2))
Generating stencils for Derivative(ux(t, x, y), (y, 2))
Operator `eval_coeffs` ran in 0.01 s
Operator `eval_coeffs` ran in 0.01 s
Operator `eval_coeffs` ran in 0.01 s
Operator `eval_coeffs` ran in 0.01 s
Generating stencils for Derivative(ux(t, x, y), x, y)
Operator `eval_coeffs` ran in 0.01 s
Operator `eval_coeffs` ran in 0.01 s
Operator `eval_coeffs` ran in 0.01 s
Operator `eval_coeffs` ran in 0.01 s
Generating stencils for Derivative(uy(t, x, y), (x, 2))
Generating stencils for Derivative(uy(t, x, y), (y, 2))
Operator `eval_coeffs` ran in 0.01 s
Operator `eval_coeffs` ran in 0.01 s
Operator `eval_coeffs` ran in 0.01 s
Operator `eval_coeffs` ran in 0.01 s
Generating stencils for Derivative(uy(t, x, y), x, y)
Operator `eval_coeffs` ran in 0.01 s
Operator `eval_coeffs` ran in 0.01 s
Operator `eval_coeffs` ran in 0.01 s
Operator `eval_coeffs` ran in 0.01 s
from examples.seismic import TimeAxis, RickerSource

c = np.sqrt(b*(lam+2*mu))

t0 = 0.  # Simulation starts a t=0
tn = 550.  # Simulation last 0.5 seconds (500 ms)
dt = 0.5*grid.spacing[0]/c  # Time step from grid spacing

time_range = TimeAxis(start=t0, stop=tn, step=dt)

f0 = 0.007  # Source peak frequency is 7Hz (0.007 kHz)
src = RickerSource(name='src', grid=grid, f0=f0,
                   npoint=1, time_range=time_range)

src.coordinates.data[0, 0] = 500.
src.coordinates.data[0, 1] = 400.
# Stability check
alpha = np.sqrt((lam+2*mu)/rho)
beta = np.sqrt(mu/rho)
dx = np.amin(grid.spacing)


print(dt)
print("Must be smaller than")
print(dx/np.sqrt(alpha**2 + beta**2))
5.0
Must be smaller than
8.94427190999916
rhs_ux = b*(lam+2*mu)*ux.dx2 + b*mu*ux.dy2 + b*(lam+mu)*uy.dxdy
rhs_uy = b*(lam+2*mu)*uy.dy2 + b*mu*uy.dx2 + b*(lam+mu)*ux.dxdy

eq_ux = dv.Eq(ux.forward,
              2*ux - ux.backward
              + dt**2*rhs_ux.subs(subs))

eq_uy = dv.Eq(uy.forward,
              2*uy - uy.backward
              + dt**2*rhs_uy.subs(subs))
src_ux = src.inject(field=ux.forward, expr=src*dt**2)
src_uy = src.inject(field=uy.forward, expr=-src*dt**2)
op = dv.Operator([eq_ux, eq_uy] + src_ux)
op(time=time_range.num-1, dt=dt)
Operator `Kernel` ran in 0.31 s
PerformanceSummary([(PerfKey(name='section0', rank=None),
                     PerfEntry(time=0.3013329999999999, gflopss=0.0, gpointss=0.0, oi=0.0, ops=0, itershapes=[])),
                    (PerfKey(name='section1', rank=None),
                     PerfEntry(time=6.599999999999992e-05, gflopss=0.0, gpointss=0.0, oi=0.0, ops=0, itershapes=[]))])
plt.imshow(ux.data[1].T, origin='lower', cmap='seismic')
plt.colorbar()
plt.show()

plt.imshow(uy.data[1].T, origin='lower', cmap='seismic')
plt.colorbar()
plt.show()

assert np.isclose(np.linalg.norm(ux.data), 368.79498)
assert np.isclose(np.linalg.norm(uy.data), 233.19011)
Back to top