@pytest.fixture(scope="session") def dims(): return { 'i': Dimension(name='i'), 'j': Dimension(name='j'), 'k': Dimension(name='k'), 'l': Dimension(name='l'), 's': Dimension(name='s'), 'q': Dimension(name='q') } # Testing dimensions for space and time time = TimeDimension('time', spacing=Constant(name='dt')) t = SteppingDimension('t', parent=time) x = SpaceDimension('x', spacing=Constant(name='h_x')) y = SpaceDimension('y', spacing=Constant(name='h_y')) z = SpaceDimension('z', spacing=Constant(name='h_z')) @pytest.fixture(scope="session") def iters(dims): return [ lambda ex: Iteration(ex, dims['i'], (0, 3, 1)), lambda ex: Iteration(ex, dims['j'], (0, 5, 1)), lambda ex: Iteration(ex, dims['k'], (0, 7, 1)), lambda ex: Iteration(ex, dims['s'], (0, 4, 1)), lambda ex: Iteration(ex, dims['q'], (0, 4, 1)), lambda ex: Iteration(ex, dims['l'], (0, 6, 1)),
def test_full_model(): shape = (50, 50, 50) spacing = [10. for _ in shape] nbl = 10 # Create two-layer model from preset model = demo_model(preset='layers-isotropic', vp_top=1., vp_bottom=2., spacing=spacing, shape=shape, nbl=nbl) # Test Model pickling pkl_model = pickle.dumps(model) new_model = pickle.loads(pkl_model) assert np.isclose(np.linalg.norm(model.vp.data[:] - new_model.vp.data[:]), 0) f0 = .010 dt = model.critical_dt t0 = 0.0 tn = 350.0 time_range = TimeAxis(start=t0, stop=tn, step=dt) # Test TimeAxis pickling pkl_time_range = pickle.dumps(time_range) new_time_range = pickle.loads(pkl_time_range) assert np.isclose(np.linalg.norm(time_range.time_values), np.linalg.norm(new_time_range.time_values)) # Test Class Constant pickling pkl_origin = pickle.dumps(model.grid.origin) new_origin = pickle.loads(pkl_origin) for a, b in zip(model.grid.origin, new_origin): assert a.compare(b) == 0 # Test Class TimeDimension pickling time_dim = TimeDimension(name='time', spacing=Constant(name='dt', dtype=np.float32)) pkl_time_dim = pickle.dumps(time_dim) new_time_dim = pickle.loads(pkl_time_dim) assert time_dim.spacing._value == new_time_dim.spacing._value # Test Class SteppingDimension stepping_dim = SteppingDimension(name='t', parent=time_dim) pkl_stepping_dim = pickle.dumps(stepping_dim) new_stepping_dim = pickle.loads(pkl_stepping_dim) assert stepping_dim.is_Time == new_stepping_dim.is_Time # Test Grid pickling pkl_grid = pickle.dumps(model.grid) new_grid = pickle.loads(pkl_grid) assert model.grid.shape == new_grid.shape assert model.grid.extent == new_grid.extent assert model.grid.shape == new_grid.shape for a, b in zip(model.grid.dimensions, new_grid.dimensions): assert a.compare(b) == 0 ricker = RickerSource(name='src', grid=model.grid, f0=f0, time_range=time_range) pkl_ricker = pickle.dumps(ricker) new_ricker = pickle.loads(pkl_ricker) assert np.isclose(np.linalg.norm(ricker.data), np.linalg.norm(new_ricker.data))
so = 6 # Spatial derivatives are eighth order accurate extent = (150., 150.) # Grid is 2km x 2km with spacing 10m shape = (151, 151) dt = (1. / sqrt(2.)) / 2500. # Where did this come from again? # Define x and z as spatial dimentions for Sympy x = SpaceDimension(name='x', spacing=Constant(name='h_x', value=extent[0] / (shape[0] - 1))) # Dimension called x, with constant spacing of 10 (called h_x) z = SpaceDimension(name='z', spacing=Constant(name='h_z', value=extent[1] / (shape[1] - 1))) t = TimeDimension(name='t', spacing=Constant(name='dt', value=dt)) grid = Grid(extent=extent, shape=shape, dimensions=(x, z), time_dimension=t) t0, tn = 0., 75. # Start and end times in ms ns = int(tn / dt) time_range = TimeAxis(start=t0, stop=tn, step=dt / 2.) #Set up time axis object for ricker source src = RickerSource(name='src', grid=grid, f0=0.100, time_range=time_range) # Ricker wavelet source src.coordinates.data[:] = array([75., 75.]) rho = Function(name="rho", grid=grid, space_order=2) #Bouyancy rho.data[:] = 1 / 1900. # k_1,2,3,4 refer to components in the stress tensor as follows: