Part 0: Preliminaries and Problem Formulation¶
Resources and Code Setup¶
These exercises are best solved using a single python script file, which we
will call fwi.py
(but you can name it whatever you wish). A starter
fwi.py
is provided.
We suggest you develop your solutions inside this file, and then run the script in an IPython console. This is accomplished by starting an IPython console, from an command prompt, with the command:
ipython --pylab
and running the script with the ‘magic’ run command:
%run solution.py
You will need a wave velocity model for these problems. This is provided in
the accompanying file models.py
. The funcion
basic_model
, which generates a simple model velocity, is imported at the
top of the provided fwi.py
using the command:
from models import basic_model
In Part 1: The Foward Problem, we will explore this model further.
Problem Configuration¶
In this exercise, the physical configuration in which we are working will have a significant amount of problem setup data (or meta data, if you will). It will be convenient to have a central place to store this.
To store this meta data, we could use a Python class, as if we had a MATLAB or
C-style struct, however it is much easier to use Python’s built-in dictionary
type dict
.
In PySIT, this information is stored in two classes: a domain class and
a mesh class, which store information about the physical domain and the
computational mesh, respectively. For these exercises, we will store
information about both in a dictionary called config
.
This configuration dictionary config
will be passed to all of your
routines and should contain the physical and numerical/computational
parameters of the problem, e.g., physical domain, number of points, time step,
CFL factor, etc.
The configuration dictionary is initialized in the sample fwi.py
by:
config = dict()
models.py¶
from __future__ import division
import numpy as np
def basic_model(config):
"""Returns 1D derivative of Gaussian reflector model.
Given a configuration dictionary that specifies:
1) 'x_limits': A tuple specifying the left and right bound of the domain
2) 'nx': The number of nodes or degrees of freedom, including the end
points
3) 'dx': The spatial step
returns a 2-tuple containing the true velocity model C and the background
velocity C0.
"""
x_limits = config['x_limits']
nx = config['nx']
dx = config['dx']
xs = x_limits[0] + np.arange(nx)*dx
C0 = np.ones(nx)
dC = -100.0*(xs-0.5)*np.exp(-((xs-0.5)**2)/(1e-4))
dC[np.where(abs(dC) < 1e-7)] = 0
C = C0 + dC
return C, C0