This website uses cookies to improve your experience. If you continue without changing your settings, you consent to our use of cookies in accordance with our cookie policy. You can disable cookies at any time.


Full-waveform inversion, Part 1: Forward modeling



Since its reintroduction by Pratt (1999), full-waveform inversion (FWI) has gained a lot of attention in geophysical exploration because of its ability to build high-resolution velocity models more or less automatically in areas of complex geology. While there is an extensive and growing literature on the topic, publications focus mostly on technical aspects, making this topic inaccessible for a broader audience due to the lack of simple introductory resources for newcomers to computational geophysics. We will accomplish this by providing a hands-on walkthrough of FWI using Devito (Lange et al., 2016), a system based on domain-specific languages that automatically generates code for time-domain finite differences.

As usual, this tutorial is accompanied by all the code you need to reproduce the figures. Go to and follow the links. In the Notebook, we describe how to simulate synthetic data for a specified source and receiver setup and how to save the corresponding wavefields and shot records. In Part 2 of this series, we will address how to calculate model updates — i.e., gradients of the FWI objective function — via adjoint modeling. Finally, in Part 3 we will demonstrate how to use this gradient as part of an optimization framework for inverting an unknown velocity model.

What is FWI?

FWI tries to iteratively minimize the difference between data that were acquired in a seismic survey and synthetic data that are generated from a wave simulator with an estimated (velocity) model of the subsurface. As such, an FWI framework essentially consists of a wave simulator for forward modeling the predicted data and an adjoint simulator for calculating a model update from the data misfit. This first part of the tutorial is dedicated to the forward modeling part and demonstrates how to discretize and implement the acoustic wave equation using Devito (


Devito provides a concise, straightforward computational framework for discretizing wave equations, which underlie most FWI frameworks. We will show that it generates verifiable executable code at run time for wave propagators associated with forward and (in Part 2) adjoint wave equations. Devito frees the user from the recurrent and time-consuming development of performant time-stepping codes and allows the user to concentrate on the geophysics of the problem rather than on low-level implementation details of wave-equation simulators. This tutorial covers the conventional adjoint-state formulation of full-waveform tomography (Tarantola, 1984) that underlies most of the current methods referred to as FWI (Virieux and Operto, 2009). While other formulations have been developed to improve the performance of FWI for poor starting models, in these tutorials we will concentrate on the standard formulation that relies on the combination of a forward/adjoint pair of propagators and a correlation-based gradient. We discuss how to set up wave simulations for inversion, including how to express the wave equation in Devito symbolically and how to deal with the acquisition geometry.

Wave simulations for inversion

The acoustic wave equation with the squared slowness m, defined as m(x, y) = c–2(x, y) with c(x, y) being the unknown spatially varying wavespeed, is given by: ((1)) where Δ is the Laplace operator, q(t, x, y; xs, ys) is the seismic source located at (xs, ys), and η(x, y) is a space-dependent dampening parameter for the absorbing boundary layer (Cerjan et al., 1985). As shown in Figure 1, the physical model is extended in every direction by nbpml grid points to mimic an infinite domain. The dampening term η du/dt attenuates the waves in the dampening layer and prevents waves from reflecting at the model boundaries. In Devito, the discrete representations of m and η are contained in a model object that contains a grid object with all relevant information such as the origin of the coordinate system, grid spacing, size of the model, and dimensions time, x, y:

Figure 1.

Figure 1. (a) Diagram showing the model domain, with the perfectly matched layer (PML) as an absorbing layer to attenuate the wavefield at the model boundary. (b) The example model used in this tutorial, with the source and receivers indicated. The grid lines show the cell boundaries.

In the Model instantiation, vp is the velocity in km/s, origin is the origin of the physical model in meters, spacing is the discrete grid spacing in meters, shape is the number of grid points in each dimension, and nbpml is the number of grid points in the absorbing boundary layer. It is important to note that shape is the size of the physical domain only, while the total number of grid points, including the absorbing boundary layer, will be automatically derived from shape and nbpml.

Symbolic definition of the wave propagator

To model seismic data by solving the acoustic wave equation, the first necessary step is to discretize this partial differential equation (PDE), which includes discrete representations of the velocity model and wavefields, as well as approximations of the spatial and temporal derivatives, using finite differences. Unfortunately, implementing these finite-difference schemes in low-level code by hand is error prone, especially when we want performant and reliable code.

The primary design objective of Devito is to allow users to define complex matrix-free finite-difference approximations from high-level symbolic definitions, while employing automated code generation to create highly optimized low-level C code. Using the symbolic algebra package SymPy (Meurer et al. 2017) to facilitate the automatic creation of derivative expressions, Devito generates computationally efficient wave propagators.

At the core of Devito's symbolic application program interface are symbolic types that behave like SymPy function objects, while also managing data:

  • Function objects represent a spatially varying function discretized on a regular Cartesian grid. For example, a function symbol f = Function(name=“f”, grid=model.grid, space_order=2) is denoted symbolically as f(x, y). The objects provide auto-generated symbolic expressions for finite-difference derivatives through shorthand expressions like f.dx and f.dx2 for the first and second derivative in x.

  • TimeFunction objects represent a time-dependent function that has time as the leading dimension, for example g(time, x, y). In addition to spatial derivatives, TimeFunction symbols also provide time derivatives g.dt and g.dt2.

  • SparseFunction objects represent sparse components, such as sources and receivers, which are usually distributed sparsely and often located off the computational grid. These objects also therefore handle interpolation onto the model grid.

To demonstrate Devito's symbolic capabilities, let us consider a time-dependent function u(time, x, y) representing the discrete forward wavefield: where the grid object provided by the model defines the size of the allocated memory region, and time_order and space_order define the default discretization order of the derived derivative expressions.

We can now use this symbolic representation of our wavefield to generate simple discretized expressions for finite-difference derivative approximations using shorthand expressions, such as u.dt and u.dt2 to denote du/dt and d2u/dt2, and respectively:

Using the automatic derivation of derivative expressions, we can now implement a discretized expression for equation 1 without the source term q(x, y, t; xs, ys). The model object, which we created earlier, already contains the squared discrete slowness model.m and damping term model.damp as Function objects:

If we write out the second-order time derivative u.dt2 as shown earlier and ignore the damping term for the moment, our pde expression translates to the following discrete wave equation: ((2)) with time being the current time step and dt being the time-stepping interval. To propagate the wavefield, we rearrange to obtain an expression for the wavefield u(time + dt) at the next time step. Ignoring the damping term once again, this yields: ((3))

We can rearrange our pde expression automatically using the SymPy utility function solve, then create an expression which defines the update of the wavefield for the new time step u(time + dt), with the command u.forward: stencil represents the finite-difference approximation derived from equation 3, including the finite-difference approximation of the Laplacian and the damping term. Although it defines the update for a single time step only, Devito knows that we will be solving a time-dependent problem over a number of time steps because the wavefield u is a TimeFunction object.

Setting up the acquisition geometry

The expression for time stepping we derived in the previous section does not contain a seismic source function yet, so the update for the wavefield at a new time step is solely defined by the two previous wavefields. However as indicated in equation 1, wavefields for seismic experiments are often excited by an active (impulsive) source q(x, y, t; xs), which is a function of space and time (just like the wavefield u). To include such a source term in our modeling scheme, we simply add the source wavefield as an additional term to equation 3:


Because the source appears on the right-hand side in the original equation (equation 1), the term also needs to be multiplied with dt2/m (this follows from rearranging equation 2, with the source on the right-hand side in place of 0). Unlike the discrete wavefield u however, the source q is typically localized in space and only a function of time, which means the time-dependent source wavelet is injected into the propagating wavefield at a specified source location. The same applies when we sample the wavefield at receiver locations to simulate a shot record — i.e., the simulated wavefield needs to be sampled at specified receiver locations only. Source and receiver both do not necessarily coincide with the modeling grid.

Here, RickerSource acts as a wrapper around SparseFunction and models a Ricker wavelet with a peak frequency f0 and source coordinates src_coords: The src.inject function now injects the current time sample of the Ricker wavelet (weighted with dt2/m as shown in equation 4) into the updated wavefield u.forward at the specified coordinates: To extract the wavefield at a predetermined set of receiver locations, there is a corresponding wrapper function for receivers as well, which creates a SparseFunction object for a given number npoint of receivers, number nt of time samples, and specified receiver coordinates rec_coords: Rather than injecting a function into the model as we did for the source, we now simply save the wavefield at the grid points that correspond to receiver positions and interpolate the data to their exact position of the computational grid location:

Forward simulation

We can now define our forward propagator by adding the source and receiver terms to our stencil object:

The symbolic expressions used to create Operator contain sufficient meta-information for Devito to create a fully functional computational kernel. The dimension symbols contained in the symbolic function object (time, x, y) define the loop structure of the created code while allowing Devito to automatically optimize the underlying loop structure to increase execution speed.

The size of the loops and spacing between grid points is inferred from the symbolic Function objects and associated model.grid object at run time. As a result, we can invoke the generated kernel through a simple Python function call by supplying the number of time steps time and the time-step size dt. The user data associated with each Function is updated in-place during operator execution, allowing us to extract the final wavefield and shot record directly from the symbolic function objects without unwanted memory duplication:

When this has finished running, the resulting wavefield is stored in and the shot record is in We can easily plot this 2D array as an image, as shown in Figure 2.

Figure 2.

Figure 2. The shot record generated by Devito for the example velocity model.

As demonstrated in the notebook, a movie of snapshots of the forward wavefield can also be generated by capturing the wavefield at discrete time steps. Figure 3 shows three time steps from the movie.

Figure 3.

Figure 3. Three snapshots from the wavefield simulation that resulted in the shot record in Figure 2. You can generate an animated version in the Notebook at


In this first part of the tutorial, we have demonstrated how to set up the discretized forward acoustic wave equations and associated wave propagator with run-time code generation. While we limited our discussion to the constant density acoustic wave equation, Devito is capable of handling more general wave equations, but this is a topic beyond this tutorial on simulating waves for inversion. In Part 2 of our tutorial, we will show how to calculate a valid gradient of the FWI objective using the adjoint-state method. In Part 3, we will demonstrate how to set up a complete matrix-free and scalable optimization framework for acoustic FWI.


This research was carried out as part of the SINBAD II project with the support of the member organizations of the SINBAD Consortium. This work was financially supported in part by EPSRC grant EP/L000407/1 and the Imperial College London Intel Parallel Computing Centre.