def forward(ctx, input, model, src, rec, device): input = input.to('cpu') # Save modeling parameters for backward pass ctx.model = model ctx.src = src ctx.rec = rec ctx.device = device # Prepare input input = input.detach() model.dm = DevFunc(name="dm", grid=model.grid) model.dm.data[:] = nn.ReflectionPad2d((40))(input).numpy()[0, 0, :, :] # Linearized forward modeling d_lin = forward_born(model, src.coordinates.data, src.data, rec.coordinates.data) return torch.from_numpy(d_lin).to(ctx.device)
src_type='Ricker', f0=f0) # Resample input data to computational grid dorig = resample(dorig, t0, tn, nt, nt_comp) dobs = Receiver(name='rec_t', grid=model.grid, ntime=nt_comp, coordinates=rec_coordinates) dobs.data[:] = dorig # Predicted data if iteration > 1: dpred, summary0 = forward_born(model, geometry.src_positions, geometry.src.data, geometry.rec_positions, space_order=space_order) # Residual and function value dpred = dpred - dobs else: dpred = Receiver(name='rec', grid=model.grid, ntime=nt_comp, coordinates=rec_coordinates) dpred.data[:] = -dorig # Function value fval = np.array([.5 * np.linalg.norm(dpred.data)**2], dtype='float32') print("fval, dpred.shape, dobs.shape: ", fval, dpred.shape, dobs.shape)
f0 = 0.010 src = RickerSource(name='src', grid=model.grid, f0=f0, time=time_axis) src.coordinates.data[0, :] = np.array(model.domain_size) * 0.5 src.coordinates.data[0, -1] = 20. # Receiver for observed data rec_t = Receiver(name='rec_t', grid=model.grid, npoint=401, ntime=nt) rec_t.coordinates.data[:, 0] = np.linspace(100, 900, num=401) rec_t.coordinates.data[:, 1] = 20. # Linearized data print("Forward J") t1 = time.time() dD_hat = forward_born(model_const, src.coordinates.data, src.data, rec_t.coordinates.data, isic=False, dt=dt) dm_hat = model0.dm.data t2 = time.time() print(t2 - t1) # Forward print("Forward J") t1 = time.time() dD = forward_born(model0, src.coordinates.data, src.data, rec_t.coordinates.data, isic=True, dt=dt)
t0=0.0, tn=tn, src_type='Ricker', f0=f0) # Resample input data to computational grid dorig = resample(dorig, t0, tn, nt, nt_comp) dobs = Receiver(name='rec_t', grid=model.grid, ntime=nt_comp, coordinates=rec_coordinates) dobs.data[:] = dorig # Predicted data if iteration > 1: dpred = forward_born(model, geometry.src_positions, geometry.src.data, geometry.rec_positions)[0] # Residual and function value dpred = dpred - dobs else: dpred = Receiver(name='rec', grid=model.grid, ntime=nt_comp, coordinates=rec_coordinates) dpred.data[:] = -dorig # Function value fval = np.array([.5 * np.linalg.norm(dpred.data)**2], dtype='float32') print("fval, dpred.shape, dobs.shape: ", fval, dpred.shape, dobs.shape) # Wavefields in memory t1 = time.time()