def test_adjoint_F(self, shape, kernel, space_order, nbpml, save, Eu, Erec, Ev, Esrca): """ Unlike `test_adjoint_F` in test_adjoint.py, here we explicitly check the norms of all Operator-evaluated Functions. The numbers we check against are derived "manually" from sequential runs of test_adjoint::test_adjoint_F """ tn = 500. # Final time nrec = 130 # Number of receivers # Create solver from preset solver = acoustic_setup(shape=shape, spacing=[15. for _ in shape], kernel=kernel, nbpml=nbpml, tn=tn, space_order=space_order, nrec=nrec, preset='layers-isotropic', dtype=np.float64) # Run forward operator rec, u, _ = solver.forward(save=save) assert np.isclose(norm(u), Eu, rtol=Eu*1.e-8) assert np.isclose(norm(rec), Erec, rtol=Erec*1.e-8) # Run adjoint operator srca, v, _ = solver.adjoint(rec=rec) assert np.isclose(norm(v), Ev, rtol=Ev*1.e-8) assert np.isclose(norm(srca), Esrca, rtol=Esrca*1.e-8) # Adjoint test: Verify <Ax,y> matches <x, A^Ty> closely term1 = inner(srca, solver.geometry.src) term2 = norm(rec)**2 assert np.isclose((term1 - term2)/term1, 0., rtol=1.e-10)
t0 = 0. tn = 1300. dt = model.critical_dt nt = int(1 + (tn - t0) / dt) time_axis = np.linspace(t0, tn, nt) # Source f1 = 0.008 src1 = RickerSource(name='src', grid=model.grid, f0=f1, time=time_axis) src1.coordinates.data[0, :] = np.array(model.domain_size) * 0.5 src1.coordinates.data[0, -1] = 20. # Receiver for observed data rec_t = Receiver(name='rec_t', grid=model.grid, npoint=301, ntime=nt) rec_t.coordinates.data[:, 0] = np.linspace(0., 3000., num=301) rec_t.coordinates.data[:, 1] = 20. # Test data and source d_hat, u1, _ = forward(model, src1.coordinates.data, rec_t.coordinates.data, src1.data) # Adjoint q0, _, _ = adjoint(model, d_hat, src1.coordinates.data, rec_t.coordinates.data) # Adjoint test a = inner(d_hat, d_hat) b = inner(q0, src1) print("Adjoint test F") print("a = %2.2e, b = %2.2e, diff = %2.2e: " % (a, b, a - b)) print("Relative error: ", a / b - 1)
rec_t.coordinates.data, src.data, save=True) # Forward print("Forward") _, u0, _ = forward(model, src.coordinates.data, rec_t.coordinates.data, src.data, save=True) # gradient print("Adjoint J") dm_hat, _ = gradient(model, dD_hat, rec_t.coordinates.data, u0) # Adjoint test a = model.critical_dt * inner(dD_hat, dD_hat) b = inner(dm_hat, model.dm) if is_tti: c = np.linalg.norm(u0[0].data.flatten() - u0l[0].data.flatten(), np.inf) else: c = np.linalg.norm(u0.data.flatten() - u0l.data.flatten(), np.inf) print("Difference between saving with forward and born", c) print("Adjoint test J") print("a = %2.2e, b = %2.2e, diff = %2.2e: " % (a, b, a - b)) print("Relative error: ", a / b - 1)