Comparing 1-D and N-D extrapolations with the 2nd-order acoustic wave equation
In this notebook, a ‘Mulder-style’ immersed boundary using a 1-D extrapolation per cartesian direction is compared with an immersed boundary approach using a single N-D extrapolation.
# Load the signed distance function for the boundary geometryimport pickleimport matplotlib.pyplot as pltdef read_sdf(surface, dims):"""Unpickle an sdf""" fname ='../tests/sdfs/'+ surface +'_'+str(dims) +'d.dat'withopen(fname, 'rb') as f: sdf = pickle.load(f)return sdf# Load the sinusoid 2D sdfsdf = read_sdf('hi_res_sinusoid', 2)plt.imshow(sdf.data.T, origin='lower')plt.title("Boundary geometry SDF")plt.colorbar()plt.show()
The same boundary geometry is used for both runs to compare the results of the two approaches.
from schism import BoundaryGeometrybg = BoundaryGeometry(sdf)grid = bg.grid # Gets the grid from the signed distance function
Operator `normals` ran in 0.01 s
The same TimeFunction can be used for both runs, the only requirement is that the data attribute is reset between.
import devito as dvs_o =4p = dv.TimeFunction(name='p', grid=grid, space_order=s_o, time_order=2)
As this notebook will use both 1-D and N-D extrapolations, separate boundary conditions are needed for each, with the former using appropriate approximations.
from schism import BoundaryConditions# N-dimensional boundary conditionsbc_list_nd = [dv.Eq(p, 0), # Zero pressure on free surface dv.Eq(p.dx2+p.dy2, 0), # Zero laplacian dv.Eq(p.dx4 +2*p.dx2dy2 + p.dy4, 0)] # Zero biharmonic# 1D boundary conditionsbc_list_1d = [dv.Eq(p, 0), # Zero pressure on free surface dv.Eq(p.dx2, 0), dv.Eq(p.dy2, 0), # Zero second derivative dv.Eq(p.dx4, 0), dv.Eq(p.dy4, 0)] # Zero fourth derivativebcs_nd = BoundaryConditions(bc_list_nd)bcs_1d = BoundaryConditions(bc_list_1d)
First running the implementation with 1D extrapolations.
Generating stencils for Derivative(p(t, x, y), (x, 2))
Generating stencils for Derivative(p(t, x, y), (y, 2))
Before running the models, a boundary mask to damp reflections at the edges of the domain is set up. As in previous examples, this will be a simple sponge mask.
import numpy as npdamp = dv.Function(name='damp', grid=grid)# Number of boundary layersnbl =10taper = np.linspace(0, 0.3, nbl)# Add the taper to the function's datadamp.data[:10] += taper[::-1, np.newaxis]damp.data[-10:] += taper[:, np.newaxis]damp.data[:, :10] += taper[np.newaxis, ::-1]damp.data[:, -10:] += taper[np.newaxis, :]plt.imshow(damp.data.T, origin='lower')plt.title("Damping mask")plt.colorbar()plt.show()
Setting up the source term, a Ricker source as before.
from examples.seismic import TimeAxis, RickerSourcec =1t0 =0.# Simulation starts a t=0tn =700.# Simulation last 0.7 seconds (700 ms)dt =0.5*grid.spacing[0]/c # Time step from grid spacingtime_range = TimeAxis(start=t0, stop=tn, step=dt)f0 =0.016# Source peak frequency is 16Hz (0.016 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] =600.
Snapshotting using a second TimeFunction and a ConditionalDimension will be used to sample the wavefield every 100ms.
A side-by-side comparison of a vacuum layer approach, an immersed boundary based on 1D extrapolations (Mulder’s approach), and an immersed boundary based on N-dimensional extrapolations is shown at 600ms.