def test_3d(): # Setup # Define Domain pmlx = PML(0.1, 100) pmlz = PML(0.1, 100) x_config = (0.1, 1.0, pmlx, pmlx) y_config = (0.1, 0.9, pmlx, pmlx) z_config = (0.1, 0.8, pmlz, pmlz) d = RectangularDomain(x_config, y_config, z_config) m = CartesianMesh(d, 90, 80, 70) # Generate true wave speed C, C0, m, d = horizontal_reflector(m) # Set up shots zmin = d.z.lbound zmax = d.z.rbound zpos = zmin + (1./9.)*zmax shots = equispaced_acquisition(m, RickerWavelet(10.0), sources=(1,1), source_depth=zpos, source_kwargs={}, receivers='max', receiver_depth=zpos, receiver_kwargs={}, ) # Define and configure the wave solver trange = (0.0,1.0) solver = ConstantDensityAcousticWave(m, spatial_accuracy_order=2, trange=trange, kernel_implementation='cpp') # Generate synthetic Seismic data tt = time.time() wavefields = [] base_model = solver.ModelParameters(m,{'C': C}) generate_seismic_data(shots, solver, base_model, wavefields=wavefields) print 'Data generation: {0}s'.format(time.time()-tt) return wavefields, m
def test_1d(): pmlz = PML(0.1, 100, ftype='quadratic') # pmlz = Dirichlet() z_config = (0.1, 0.8, pmlz, Dirichlet()) z_config = (0.1, 0.8, pmlz, pmlz) # z_config = (0.1, 0.8, Dirichlet(), Dirichlet()) d = RectangularDomain(z_config) m = CartesianMesh(d, 301) # Generate true wave speed C, C0, m, d = horizontal_reflector(m) # Set up shots shots = [] # Define source location and type zpos = 0.2 source = PointSource(m, (zpos), RickerWavelet(25.0)) # Define set of receivers receiver = PointReceiver(m, (zpos)) # receivers = ReceiverSet([receiver]) # Create and store the shot shot = Shot(source, receiver) # shot = Shot(source, receivers) shots.append(shot) # Define and configure the wave solver trange = (0.0, 3.0) solver = ConstantDensityAcousticWave(m, spatial_accuracy_order=2, trange=trange, kernel_implementation='cpp') # Generate synthetic Seismic data tt = time.time() wavefields = [] base_model = solver.ModelParameters(m,{'C': C}) generate_seismic_data(shots, solver, base_model, wavefields=wavefields) print 'Data generation: {0}s'.format(time.time()-tt) return wavefields, m
from pysit.gallery import horizontal_reflector bc = Dirichlet() dim = 2 deriv = 1 # 2 order = 4 if dim == 1: z_config = (0.0, 7.0, bc, bc) d = RectangularDomain(z_config) m = CartesianMesh(d, 7) # Generate true wave speed C, C0 = horizontal_reflector(m) D = build_derivative_matrix(m, deriv, order, dimension='all').todense() Dz = build_derivative_matrix(m, deriv, order, dimension='z').todense() if dim == 2: x_config = (0.0, 7.0, bc, bc) z_config = (0.0, 7.0, bc, bc) d = RectangularDomain(x_config, z_config) m = CartesianMesh(d, 7, 7)
# PML with auxilary fields # pmlx = PML(0.1, 100) # pmlz = PML(0.1, 100) # PML without auxilary fields pmlx = PML(0.1, 100,compact=True) pmlz = PML(0.1, 100,compact=True) x_config = (0.1, 1.0, pmlx, pmlx) z_config = (0.1, 0.8, pmlz, pmlz) d = RectangularDomain(x_config, z_config) m = CartesianMesh(d, 100, 100) # Generate true wave speed C, C0, m, d = horizontal_reflector(m) # Set up shots zmin = d.z.lbound zmax = d.z.rbound zpos = zmin + (1./9.)*zmax shots = equispaced_acquisition(m, RickerWavelet(10.0), sources=4, source_depth=zpos, source_kwargs={}, receivers='max', receiver_depth=zpos, receiver_kwargs={}, )
def adjoint_test(frequencies=[10.0, 10.5, 10.1413515123], plots=False, data_noise=0.0, purefrequency=False): # default frequencies are enough to indicate a bug due to integer offsets import numpy as np import matplotlib.pyplot as plt from pysit import ( PML, RectangularDomain, CartesianMesh, PointSource, ReceiverSet, Shot, ConstantDensityAcousticWave, generate_seismic_data, PointReceiver, RickerWavelet, FrequencyModeling, ConstantDensityHelmholtz, vis, ) from pysit.gallery import horizontal_reflector # Define Domain pmlx = PML(0.3, 100, ftype="quadratic") pmlz = PML(0.3, 100, ftype="quadratic") x_config = (0.1, 1.0, pmlx, pmlx) z_config = (0.1, 0.8, pmlz, pmlz) d = RectangularDomain(x_config, z_config) m = CartesianMesh(d, 90, 70) # Generate true wave speed # (M = C^-2 - C0^-2) C0, C = horizontal_reflector(m) # Set up shots Nshots = 1 shots = [] xmin = d.x.lbound xmax = d.x.rbound nx = m.x.n zmin = d.z.lbound zmax = d.z.rbound point_approx = "delta" for i in xrange(Nshots): # Define source location and type source = PointSource(m, (0.188888, 0.18888), RickerWavelet(10.0), approximation=point_approx) # Define set of receivers zpos = zmin + (1.0 / 9.0) * zmax xpos = np.linspace(xmin, xmax, nx) receivers = ReceiverSet(m, [PointReceiver(m, (x, zpos)) for x in xpos]) # Create and store the shot shot = Shot(source, receivers) shots.append(shot) # Define and configure the wave solver trange = (0.0, 3.0) solver = ConstantDensityAcousticWave( m, # formulation='ode', formulation="scalar", model_parameters={"C": C}, spatial_accuracy_order=4, # spatial_shifted_differences=True, # cfl_safety=0.01, trange=trange, time_accuracy_order=4, ) tools = HybridModeling(solver) m0 = solver.ModelParameters(m, {"C": C0}) solver_frequency = ConstantDensityHelmholtz( m, model_parameters={"C": C0}, spatial_shifted_differences=True, spatial_accuracy_order=4 ) frequencytools = FrequencyModeling(solver_frequency) m0_freq = solver_frequency.ModelParameters(m, {"C": C0}) np.random.seed(0) m1 = m0.perturbation() pert = np.random.rand(*m1.data.shape) m1 += pert # freqs = [10.5514213] #[3.0, 5.0, 10.0] # freqs = [10.5] # freqs = np.linspace(3,19,8) freqs = frequencies fwdret = tools.forward_model(shot, m0, freqs, ["wavefield", "dWaveOp", "simdata_time"]) dWaveOp0 = fwdret["dWaveOp"] data = fwdret["simdata_time"] u0hat = fwdret["wavefield"][freqs[0]] data += data_noise * np.random.rand(*data.shape) dhat = dict() for nu in freqs: dhat[nu] = 0 assert data.shape[0] == solver.nsteps for k in xrange(solver.nsteps): t = k * solver.dt for nu in freqs: dhat[nu] += data[k, :] * np.exp(-1j * 2 * np.pi * nu * t) * solver.dt print "Hybrid:" linfwdret = tools.linear_forward_model(shot, m0, m1, freqs, ["simdata", "wavefield1", "simdata_time"]) lindata = linfwdret["simdata"] lindata_time = linfwdret["simdata_time"] u1hat = linfwdret["wavefield1"][freqs[0]] adjret = tools.adjoint_model( shot, m0, data, freqs, return_parameters=["imaging_condition", "adjointfield"], dWaveOp=dWaveOp0 ) qhat = adjret["adjointfield"][freqs[0]] adjmodel = adjret["imaging_condition"].asarray() m1_ = m1.asarray() temp_data_prod = 0.0 for nu in freqs: temp_data_prod += np.dot(lindata[nu].reshape(dhat[nu].shape), np.conj(dhat[nu])) print temp_data_prod print np.dot(m1_.T, np.conj(adjmodel)).squeeze() * np.prod(m.deltas) print np.dot(m1_.T, np.conj(adjmodel)).squeeze() * np.prod(m.deltas) - temp_data_prod if purefrequency: print "Frequency:" linfwdret_freq = frequencytools.linear_forward_model(shot, m0, m1, freqs, ["simdata", "wavefield1", "dWaveOp0"]) lindata_freq = linfwdret_freq["simdata"] u1hat_freq = linfwdret_freq["wavefield1"][freqs[0]] dWaveOp0_freq = linfwdret_freq["dWaveOp0"] adjret_freq = frequencytools.adjoint_model( shot, m0, dhat, freqs, return_parameters=["imaging_condition", "adjointfield"], dWaveOp=dWaveOp0_freq ) qhat_freq = adjret_freq["adjointfield"][freqs[0]] adjmodel_freq = adjret_freq["imaging_condition"].asarray() temp_data_prod = 0.0 for nu in freqs: temp_data_prod += np.dot(lindata_freq[nu].reshape(dhat[nu].shape).T, np.conj(dhat[nu])) print temp_data_prod.squeeze() print np.dot(m1_.T, np.conj(adjmodel_freq)).squeeze() * np.prod(m.deltas) print np.dot(m1_.T, np.conj(adjmodel_freq)).squeeze() * np.prod(m.deltas) - temp_data_prod.squeeze() if plots: xx, zz = d.generate_grid() sl = [(xx >= 0.1) & (xx <= 0.99) & (zz >= 0.1) & (zz < 0.8)] pml_null = PML(0.0, 100) x_bulk = (0.1, 1.0, 90, pml_null, pml_null) z_bulk = (0.1, 0.8, 70, pml_null, pml_null) d_bulk = Domain((x_bulk, z_bulk)) def clims(*args): rclim = min([np.real(x).min() for x in args]), max([np.real(x).max() for x in args]) iclim = min([np.imag(x).min() for x in args]), max([np.imag(x).max() for x in args]) return rclim, iclim qrclim, qiclim = clims(qhat, qhat_freq) u1rclim, u1iclim = clims(u1hat, u1hat_freq) plt.figure() plt.subplot(2, 3, 1) display_on_grid(np.real(u0hat[sl]), d_bulk) plt.title(r"re(${\hat u_0}$)") plt.subplot(2, 3, 4) display_on_grid(np.imag(u0hat[sl]), d_bulk) plt.title(r"im(${\hat u_0}$)") plt.subplot(2, 3, 2) display_on_grid(np.real(qhat[sl]), d_bulk, clim=qrclim) plt.title(r"re(${\hat q}$) H") plt.subplot(2, 3, 5) display_on_grid(np.imag(qhat[sl]), d_bulk, clim=qiclim) plt.title(r"im(${\hat q}$) H") plt.subplot(2, 3, 3) display_on_grid(np.real(u1hat[sl]), d_bulk, clim=u1rclim) plt.title(r"re(${\hat u_1}$) H") plt.subplot(2, 3, 6) display_on_grid(np.imag(u1hat[sl]), d_bulk, clim=u1iclim) plt.title(r"im(${\hat u_1}$) H") plt.show() plt.figure() plt.subplot(2, 3, 1) display_on_grid(np.real(u0hat[sl]), d_bulk) plt.title(r"re(${\hat u_0}$)") plt.subplot(2, 3, 4) display_on_grid(np.imag(u0hat[sl]), d_bulk) plt.title(r"im(${\hat u_0}$)") plt.subplot(2, 3, 2) display_on_grid(np.real(qhat_freq[sl]), d_bulk, clim=qrclim) plt.title(r"re(${\hat q}$) P") plt.subplot(2, 3, 5) display_on_grid(np.imag(qhat_freq[sl]), d_bulk, clim=qiclim) plt.title(r"im(${\hat q}$) P") plt.subplot(2, 3, 3) display_on_grid(np.real(u1hat_freq[sl]), d_bulk, clim=u1rclim) plt.title(r"re(${\hat u_1}$) P") plt.subplot(2, 3, 6) display_on_grid(np.imag(u1hat_freq[sl]), d_bulk, clim=u1iclim) plt.title(r"im(${\hat u_1}$) P") plt.show()
def adjoint_test(): #if __name__ == '__main__': # from pysit import * import numpy as np import matplotlib.pyplot as plt from pysit import PML, Dirichlet, RectangularDomain, CartesianMesh, PointSource, ReceiverSet, Shot, ConstantDensityAcousticWave,ConstantDensityHelmholtz, generate_seismic_data, PointReceiver, RickerWavelet from pysit.gallery import horizontal_reflector # Define Domain bc = PML(0.3, 100, ftype='quadratic') # bc = Dirichlet() x_config = (0.1, 1.0, bc, bc) z_config = (0.1, 0.8, bc, bc) d = RectangularDomain( x_config, z_config ) m = CartesianMesh(d, 90, 70) # Generate true wave speed # (M = C^-2 - C0^-2) C0, C = horizontal_reflector(m) # Set up shots Nshots = 1 shots = [] xmin = d.x.lbound xmax = d.x.rbound nx = m.x.n zmin = d.z.lbound zmax = d.z.rbound point_approx = 'delta' for i in xrange(Nshots): # Define source location and type source = PointSource(m, (.188888, 0.18888), RickerWavelet(10.0), approximation=point_approx) # Define set of receivers zpos = zmin + (1./9.)*zmax xpos = np.linspace(xmin, xmax, nx) receivers = ReceiverSet(m, [PointReceiver(m, (x, zpos)) for x in xpos]) # Create and store the shot shot = Shot(source, receivers) shots.append(shot) # Define and configure the wave solver trange=(0.,3.0) solver = ConstantDensityAcousticWave(m, formulation='scalar', model_parameters={'C': C}, spatial_accuracy_order=4, trange=trange, time_accuracy_order=6) # Generate synthetic Seismic data print('Generating data...') base_model = solver.ModelParameters(m,{'C': C}) generate_seismic_data(shots, solver, base_model) solver_frequency = ConstantDensityHelmholtz(m, model_parameters={'C': C0}, spatial_shifted_differences=True, spatial_accuracy_order=4) tools = FrequencyModeling(solver_frequency) m0 = solver_frequency.ModelParameters(m,{'C': C0}) np.random.seed(0) m1 = m0.perturbation() # m1 += M m1 += np.random.rand(*m1.data.shape) freqs = [10.0, 10.5, 10.123334145252] # freqs = np.linspace(3,20,20) fwdret = tools.forward_model(shot, m0, freqs, ['wavefield', 'dWaveOp', 'simdata']) data = fwdret['simdata'] dWaveOp0 = fwdret['dWaveOp'] u0hat = fwdret['wavefield'][freqs[0]] # data -= shot.receivers.interpolate_data(solver.ts()) # data *= -1 # for nu in freqs: # data[nu] += np.random.rand(*data[nu].shape) linfwdret = tools.linear_forward_model(shot, m0, m1, freqs, ['simdata','wavefield1']) lindata = linfwdret['simdata'] u1hat = linfwdret['wavefield1'][freqs[0]] adjret = tools.adjoint_model(shot, m0, data, freqs, return_parameters=['imaging_condition', 'adjointfield'], dWaveOp=dWaveOp0) qhat = adjret['adjointfield'][freqs[0]] adjmodel = adjret['imaging_condition'].data # adjret2 = tools.adjoint_model(shot, m0, lindata_time, freqs, return_parameters=['imaging_condition', 'adjointfield'], dWaveOp=dWaveOp0) ## qhat = adjret['adjointfield'][freqs[0]] # adjmodel2 = adjret2['imaging_condition'].view(np.ndarray) m1 = m1.data temp_data_prod = 0.0 for nu in freqs: temp_data_prod += np.dot(lindata[nu].reshape(data[nu].shape).T, np.conj(data[nu])) print temp_data_prod.squeeze() print np.dot(m1.T, np.conj(adjmodel)).squeeze()*np.prod(m.deltas) print np.dot(m1.T, np.conj(adjmodel)).squeeze()*np.prod(m.deltas) - temp_data_prod.squeeze()
# Setup # Define Domain pmlx = PML(0.1, 100) pmlz = PML(0.1, 100) # The first 2 entires in these tuples indicates the physical domain dimensions we will use. x_config = (0.1, 1.0, pmlx, pmlx) z_config = (0.1, 0.8, pmlz, pmlz) d = RectangularDomain(x_config, z_config) # nx and nz specify the number of nodes used in the computation. nx = 91 nz = 71 m = CartesianMesh(d, nx, nz) C, C0, m, d = horizontal_reflector(m) # C has two reflectors at depth. # Generate the Model Parameters in terms of Kappa and Rho (with 2 reflectors at depth). # To do this we "split up" the two reflectors contained in dC. C0 = np.ones((nx, nz)) dC = C.reshape(nx, nz) - C0 dC1 = dC[:, : np.ceil(nz / 2)] dC2 = dC[:, np.ceil(nz / 2) :] dK = np.zeros((nx, nz)) dR = np.zeros((nx, nz)) # These next 4 lines allow us to modify the sign and magntiude of each of the bumps for kappa and rho. dK[:, : np.ceil(nz / 2)] += dC1 dR[:, : np.ceil(nz / 2)] += dC1 dK[:, np.ceil(nz / 2) :] += dC2 dR[:, np.ceil(nz / 2) :] += dC2
# Define Domain pmlx = PML(0.3, 100, ftype="quadratic") pmlz = PML(0.3, 100, ftype="quadratic") x_config = (0.1, 1.0, pmlx, pmlx) z_config = (0.1, 0.8, pmlz, pmlz) d = RectangularDomain(x_config, z_config) m = CartesianMesh(d, 2 * 90, 2 * 70) m = CartesianMesh(d, 90, 70) # Generate true wave speed # (M = C^-2 - C0^-2) C0, C = horizontal_reflector(m) # Set up shots shots = list() xmin = d.x.lbound xmax = d.x.rbound nx = m.x.n zmin = d.z.lbound zmax = d.z.rbound point_approx = "delta" # Define source location and type source = PointSource(m, (0.188888, 0.18888), RickerWavelet(10.0), approximation=point_approx)
from pysit.gallery import horizontal_reflector bc = Dirichlet() dim = 2 deriv = 1 # 2 order = 4 if dim == 1: z_config = (0.0, 7.0, bc, bc) d = RectangularDomain(z_config) m = CartesianMesh(d, 7) # Generate true wave speed C, C0 = horizontal_reflector(m) D = build_derivative_matrix(m, deriv, order, dimension='all').todense() Dz = build_derivative_matrix(m, deriv, order, dimension='z').todense() if dim == 2: x_config = (0.0, 7.0, bc, bc) z_config = (0.0, 7.0, bc, bc) d = RectangularDomain(x_config, z_config) m = CartesianMesh(d, 7, 7) # Generate true wave speed
def adjoint_test(): #if __name__ == '__main__': import numpy as np from pysit import PML, RectangularDomain, CartesianMesh, PointSource, ReceiverSet, Shot, ConstantDensityAcousticWave, generate_seismic_data, PointReceiver, RickerWavelet from pysit.gallery import horizontal_reflector # Setup # Define Domain pmlx = PML(0.1, 1000, ftype='quadratic') pmlz = PML(0.1, 1000, ftype='quadratic') x_config = (0.1, 1.0, pmlx, pmlx) z_config = (0.1, 0.8, pmlz, pmlz) d = RectangularDomain( x_config, z_config ) m = CartesianMesh(d, 90, 70) # Generate true wave speed # (M = C^-2 - C0^-2) C0, C = horizontal_reflector(m) # Set up shots Nshots = 1 shots = [] xmin = d.x.lbound xmax = d.x.rbound nx = m.x.n zmin = d.z.lbound zmax = d.z.rbound for i in xrange(Nshots): # Define source location and type # source = PointSource(d, (xmax*(i+1.0)/(Nshots+1.0), 0.1), RickerWavelet(10.0)) source = PointSource(m, (.188888, 0.18888), RickerWavelet(10.0)) # Define set of receivers zpos = zmin + (1./9.)*zmax xpos = np.linspace(xmin, xmax, nx) receivers = ReceiverSet(m, [PointReceiver(m, (x, zpos)) for x in xpos]) # Create and store the shot shot = Shot(source, receivers) shots.append(shot) # Define and configure the wave solver trange=(0.,3.0) solver = ConstantDensityAcousticWave(m, formulation='ode', # formulation='scalar', model_parameters={'C': C}, spatial_accuracy_order=4, # spatial_shifted_differences=True, # cfl_safety=0.01, trange=trange, time_accuracy_order=4) # Generate synthetic Seismic data np.random.seed(1) print('Generating data...') wavefields=[] base_model = solver.ModelParameters(m,{'C': C}) generate_seismic_data(shots, solver, base_model, wavefields=wavefields) tools = TemporalModeling(solver) m0 = solver.ModelParameters(m,{'C': C0}) m1 = m0.perturbation() m1 += np.random.rand(*m1.data.shape) fwdret = tools.forward_model(shot, m0, ['wavefield', 'dWaveOp', 'simdata']) dWaveOp0 = fwdret['dWaveOp'] inc_field = fwdret['wavefield'] data = fwdret['simdata'] # data += np.random.rand(*data.shape) linfwdret = tools.linear_forward_model(shot, m0, m1, ['simdata']) lindata = linfwdret['simdata'] adjret = tools.adjoint_model(shot, m0, data, return_parameters=['imaging_condition', 'adjointfield'], dWaveOp=dWaveOp0) adjmodel = adjret['imaging_condition'].asarray() adj_field = adjret['adjointfield'] m1 = m1.asarray() print data.shape, solver.nsteps print np.sum(data*lindata)*solver.dt print np.dot(m1.T, adjmodel).squeeze()*np.prod(m.deltas) print np.dot(m1.T, adjmodel).squeeze()*np.prod(m.deltas)-np.sum(data*lindata)*solver.dt qs = adj_field qhat = 0.0 dt = solver.dt for k in xrange(solver.nsteps): t = k * dt qhat += qs[k]*(np.exp(-1j*2.0*np.pi*10.0*t)*dt)
# Setup # Define Domain pmlx = PML(0.1, 100) pmlz = PML(0.1, 100) # The first 2 entires in these tuples indicates the physical domain dimensions we will use. x_config = (0.1, 1.0, pmlx, pmlx) z_config = (0.1, 0.8, pmlz, pmlz) d = RectangularDomain(x_config, z_config) # nx and nz specify the number of nodes used in the computation. nx = 91 nz = 71 m = CartesianMesh(d, nx, nz) C, C0, m, d = horizontal_reflector(m) # C has two reflectors at depth. # Generate the Model Parameters in terms of Kappa and Rho (with 2 reflectors at depth). # To do this we "split up" the two reflectors contained in dC. C0 = np.ones((nx, nz)) dC = C.reshape(nx, nz) - C0 dC1 = dC[:, :np.ceil(nz / 2)] dC2 = dC[:, np.ceil(nz / 2):] dK = np.zeros((nx, nz)) dR = np.zeros((nx, nz)) # These next 4 lines allow us to modify the sign and magntiude of each of the bumps for kappa and rho. dK[:, :np.ceil(nz / 2)] += dC1 dR[:, :np.ceil(nz / 2)] += dC1 dK[:, np.ceil(nz / 2):] += dC2 dR[:, np.ceil(nz / 2):] += dC2
def adjoint_test(frequencies=[10.0, 10.5, 10.1413515123], plots=False, data_noise=0.0, purefrequency=False): # default frequencies are enough to indicate a bug due to integer offsets import numpy as np import matplotlib.pyplot as plt from pysit import PML, RectangularDomain, CartesianMesh, PointSource, ReceiverSet, Shot, ConstantDensityAcousticWave, generate_seismic_data, PointReceiver, RickerWavelet, FrequencyModeling, ConstantDensityHelmholtz, vis from pysit.gallery import horizontal_reflector # Define Domain pmlx = PML(0.3, 100, ftype='quadratic') pmlz = PML(0.3, 100, ftype='quadratic') x_config = (0.1, 1.0, pmlx, pmlx) z_config = (0.1, 0.8, pmlz, pmlz) d = RectangularDomain( x_config, z_config ) m = CartesianMesh(d, 90, 70) # Generate true wave speed # (M = C^-2 - C0^-2) C0, C = horizontal_reflector(m) # Set up shots Nshots = 1 shots = [] xmin = d.x.lbound xmax = d.x.rbound nx = m.x.n zmin = d.z.lbound zmax = d.z.rbound point_approx = 'delta' for i in range(Nshots): # Define source location and type source = PointSource(m, (.188888, 0.18888), RickerWavelet(10.0), approximation=point_approx) # Define set of receivers zpos = zmin + (1./9.)*zmax xpos = np.linspace(xmin, xmax, nx) receivers = ReceiverSet(m, [PointReceiver(m, (x, zpos)) for x in xpos]) # Create and store the shot shot = Shot(source, receivers) shots.append(shot) # Define and configure the wave solver trange=(0.,3.0) solver = ConstantDensityAcousticWave(m, # formulation='ode', formulation='scalar', model_parameters={'C': C}, spatial_accuracy_order=4, # spatial_shifted_differences=True, # cfl_safety=0.01, trange=trange, time_accuracy_order=4) tools = HybridModeling(solver) m0 = solver.ModelParameters(m,{'C': C0}) solver_frequency = ConstantDensityHelmholtz(m, model_parameters={'C': C0}, spatial_shifted_differences=True, spatial_accuracy_order=4) frequencytools = FrequencyModeling(solver_frequency) m0_freq = solver_frequency.ModelParameters(m,{'C': C0}) np.random.seed(0) m1 = m0.perturbation() pert = np.random.rand(*m1.data.shape) m1 += pert # freqs = [10.5514213] #[3.0, 5.0, 10.0] # freqs = [10.5] # freqs = np.linspace(3,19,8) freqs = frequencies fwdret = tools.forward_model(shot, m0, freqs, ['wavefield', 'dWaveOp', 'simdata_time']) dWaveOp0 = fwdret['dWaveOp'] data = fwdret['simdata_time'] u0hat = fwdret['wavefield'][freqs[0]] data += data_noise*np.random.rand(*data.shape) dhat = dict() for nu in freqs: dhat[nu]=0 assert data.shape[0] == solver.nsteps for k in range(solver.nsteps): t = k*solver.dt for nu in freqs: dhat[nu] += data[k,:]*np.exp(-1j*2*np.pi*nu*t)*solver.dt print("Hybrid:") linfwdret = tools.linear_forward_model(shot, m0, m1, freqs, ['simdata','wavefield1','simdata_time']) lindata = linfwdret['simdata'] lindata_time = linfwdret['simdata_time'] u1hat = linfwdret['wavefield1'][freqs[0]] adjret = tools.adjoint_model(shot, m0, data, freqs, return_parameters=['imaging_condition', 'adjointfield'], dWaveOp=dWaveOp0) qhat = adjret['adjointfield'][freqs[0]] adjmodel = adjret['imaging_condition'].asarray() m1_ = m1.asarray() temp_data_prod = 0.0 for nu in freqs: temp_data_prod += np.dot(lindata[nu].reshape(dhat[nu].shape), np.conj(dhat[nu])) print(temp_data_prod) print(np.dot(m1_.T, np.conj(adjmodel)).squeeze()*np.prod(m.deltas)) print(np.dot(m1_.T, np.conj(adjmodel)).squeeze()*np.prod(m.deltas) - temp_data_prod) if purefrequency: print("Frequency:") linfwdret_freq = frequencytools.linear_forward_model(shot, m0, m1, freqs, ['simdata','wavefield1', 'dWaveOp0']) lindata_freq = linfwdret_freq['simdata'] u1hat_freq = linfwdret_freq['wavefield1'][freqs[0]] dWaveOp0_freq = linfwdret_freq['dWaveOp0'] adjret_freq = frequencytools.adjoint_model(shot, m0, dhat, freqs, return_parameters=['imaging_condition', 'adjointfield'], dWaveOp=dWaveOp0_freq) qhat_freq = adjret_freq['adjointfield'][freqs[0]] adjmodel_freq = adjret_freq['imaging_condition'].asarray() temp_data_prod = 0.0 for nu in freqs: temp_data_prod += np.dot(lindata_freq[nu].reshape(dhat[nu].shape).T, np.conj(dhat[nu])) print(temp_data_prod.squeeze()) print(np.dot(m1_.T, np.conj(adjmodel_freq)).squeeze()*np.prod(m.deltas)) print(np.dot(m1_.T, np.conj(adjmodel_freq)).squeeze()*np.prod(m.deltas) - temp_data_prod.squeeze()) if plots: xx, zz = d.generate_grid() sl = [(xx>=0.1) & (xx<=0.99) & (zz>=0.1) & (zz<0.8)] pml_null = PML(0.0,100) x_bulk = (0.1, 1.0, 90, pml_null, pml_null) z_bulk = (0.1, 0.8, 70, pml_null, pml_null) d_bulk = Domain( (x_bulk, z_bulk) ) def clims(*args): rclim = min([np.real(x).min() for x in args]), max([np.real(x).max() for x in args]) iclim = min([np.imag(x).min() for x in args]), max([np.imag(x).max() for x in args]) return rclim, iclim qrclim, qiclim = clims(qhat, qhat_freq) u1rclim, u1iclim = clims(u1hat, u1hat_freq) plt.figure() plt.subplot(2,3,1) display_on_grid(np.real(u0hat[sl]), d_bulk) plt.title(r're(${\hat u_0}$)') plt.subplot(2,3,4) display_on_grid(np.imag(u0hat[sl]), d_bulk) plt.title(r'im(${\hat u_0}$)') plt.subplot(2,3,2) display_on_grid(np.real(qhat[sl]), d_bulk, clim=qrclim) plt.title(r're(${\hat q}$) H') plt.subplot(2,3,5) display_on_grid(np.imag(qhat[sl]), d_bulk, clim=qiclim) plt.title(r'im(${\hat q}$) H') plt.subplot(2,3,3) display_on_grid(np.real(u1hat[sl]), d_bulk, clim=u1rclim) plt.title(r're(${\hat u_1}$) H') plt.subplot(2,3,6) display_on_grid(np.imag(u1hat[sl]), d_bulk, clim=u1iclim) plt.title(r'im(${\hat u_1}$) H') plt.show() plt.figure() plt.subplot(2,3,1) display_on_grid(np.real(u0hat[sl]), d_bulk) plt.title(r're(${\hat u_0}$)') plt.subplot(2,3,4) display_on_grid(np.imag(u0hat[sl]), d_bulk) plt.title(r'im(${\hat u_0}$)') plt.subplot(2,3,2) display_on_grid(np.real(qhat_freq[sl]), d_bulk, clim=qrclim) plt.title(r're(${\hat q}$) P') plt.subplot(2,3,5) display_on_grid(np.imag(qhat_freq[sl]), d_bulk, clim=qiclim) plt.title(r'im(${\hat q}$) P') plt.subplot(2,3,3) display_on_grid(np.real(u1hat_freq[sl]), d_bulk, clim=u1rclim) plt.title(r're(${\hat u_1}$) P') plt.subplot(2,3,6) display_on_grid(np.imag(u1hat_freq[sl]), d_bulk, clim=u1iclim) plt.title(r'im(${\hat u_1}$) P') plt.show()
# Define Domain pmlx = PML(0.3, 100, ftype='quadratic') pmlz = PML(0.3, 100, ftype='quadratic') x_config = (0.1, 1.0, pmlx, pmlx) z_config = (0.1, 0.8, pmlz, pmlz) d = RectangularDomain( x_config, z_config ) m = CartesianMesh(d, 2*90, 2*70) m = CartesianMesh(d, 90, 70) # Generate true wave speed # (M = C^-2 - C0^-2) C0, C = horizontal_reflector(m) # Set up shots shots = list() xmin = d.x.lbound xmax = d.x.rbound nx = m.x.n zmin = d.z.lbound zmax = d.z.rbound point_approx = 'delta' # Define source location and type source = PointSource(m, (.188888, 0.18888), RickerWavelet(10.0), approximation=point_approx)