def test_checkpointed_vs_not_checkpointed(shape, kernel, space_order):
    """
    Verifies that the gradients with and without checkpointing are the SpaceDimension
    """
    spacing = tuple([15.0 for _ in shape])
    tn = 500.
    # checkpointing
    example = CheckpointingExample(shape, spacing, tn, kernel, space_order)
    m0, dm = example.initial_estimate()
    gradient, rec = example.gradient(m0)

    # No checkpointing
    wave = acoustic_setup(shape=shape,
                          spacing=spacing,
                          dtype=np.float32,
                          kernel=kernel,
                          space_order=space_order,
                          nbpml=10 + space_order / 2)

    m0 = Function(name='m0', grid=wave.model.m.grid, space_order=space_order)
    m0.data[:] = smooth10(wave.model.m.data, wave.model.m.shape_domain)
    # Compute receiver data for the true velocity
    rec, u, _ = wave.forward()
    # Compute receiver data and full wavefield for the smooth velocity
    rec0, u0, _ = wave.forward(m=m0, save=True)

    # Gradient: <J^T \delta d, dm>
    residual = Receiver(name='rec',
                        grid=wave.model.grid,
                        data=rec0.data - rec.data,
                        time_range=rec.time_range,
                        coordinates=rec0.coordinates.data)
    grad, _ = wave.gradient(residual, u0, m=m0)

    assert np.allclose(grad.data, gradient)
 def initial_estimate(self):
     m0 = Function(name='m0',
                   grid=self.model.m.grid,
                   space_order=self.space_order)
     m0.data[:] = smooth10(self.model.m.data, self.model.shape_domain)
     dm = np.float32(self.model.m.data - m0.data)
     return m0, dm
Ejemplo n.º 3
0
 def initial_estimate(self):
     m0 = smooth10(self.model.m.data, self.model.shape_domain)
     dm = np.float32(self.model.m.data - m0)
     return m0, dm
Ejemplo n.º 4
0
# Model
shape = (151, 101)
spacing = (10., 10.)
origin = (0., 0.)
v = np.empty(shape, dtype=np.float32)
v[:, :] = 1.5
v[:, 51:] = 2.5
model = Model(shape=shape,
              origin=origin,
              spacing=spacing,
              vp=v,
              space_order=1,
              nbpml=10)
m0 = Function(name="m0", grid=model.grid, space_order=1)
m0.data[:] = smooth10(model.m.data[:], model.m.data.shape)
dm0 = Function(name="dm0", grid=model.grid, space_order=1)
dm0.data[:] = -m0.data[:] + model.m.data[:]

# Derive timestepping from model spacing
dt = model.critical_dt
t0 = 0.0
tn = 1000.
time_range = TimeAxis(start=t0, stop=tn, step=dt)
# Source
f0 = 0.015
src = RickerSource(name='src', grid=model.grid, f0=f0, time_range=time_range)
src.coordinates.data[0, :] = np.array(model.domain_size) * 0.5
src.coordinates.data[0, -1] = 20.

# Receiver for observed data