def setUp(self): # Define sphere parameters self.rad = 2.0 self.rho = 0.1 # Define a mesh cs = 0.2 hxind = [(cs, 21)] hyind = [(cs, 21)] hzind = [(cs, 21)] mesh = discretize.TensorMesh([hxind, hyind, hzind], "CCC") # Get cells inside the sphere sph_ind = getIndicesSphere([0.0, 0.0, 0.0], self.rad, mesh.gridCC) # Adjust density for volume difference Vratio = (4.0 / 3.0 * np.pi * self.rad**3.0) / (np.sum(sph_ind) * cs**3.0) model = np.ones(mesh.nC) * self.rho * Vratio self.model = model[sph_ind] # Create reduced identity map for Linear Pproblem idenMap = maps.IdentityMap(nP=int(sum(sph_ind))) # Create plane of observations xr = np.linspace(-20, 20, nx) yr = np.linspace(-20, 20, ny) X, Y = np.meshgrid(xr, yr) self.xr = xr self.yr = yr components = ["gx", "gy", "gz"] # Move obs plane 2 radius away from sphere Z = np.ones((xr.size, yr.size)) * 2.0 * self.rad self.locXyz = np.c_[utils.mkvc(X), utils.mkvc(Y), utils.mkvc(Z)] receivers = gravity.Point(self.locXyz, components=components) sources = gravity.SourceField([receivers]) self.survey = gravity.Survey(sources) self.sim = gravity.Simulation3DIntegral( mesh, survey=self.survey, rhoMap=idenMap, actInd=sph_ind, store_sensitivities="disk", )
def setUp(self): ndv = -100 # Create a self.mesh dx = 5.0 hxind = [(dx, 5, -1.3), (dx, 5), (dx, 5, 1.3)] hyind = [(dx, 5, -1.3), (dx, 5), (dx, 5, 1.3)] hzind = [(dx, 5, -1.3), (dx, 6)] self.mesh = discretize.TensorMesh([hxind, hyind, hzind], "CCC") # Get index of the center midx = int(self.mesh.nCx / 2) midy = int(self.mesh.nCy / 2) # Lets create a simple Gaussian topo and set the active cells [xx, yy] = np.meshgrid(self.mesh.vectorNx, self.mesh.vectorNy) zz = -np.exp((xx**2 + yy**2) / 75**2) + self.mesh.vectorNz[-1] # Go from topo to actv cells topo = np.c_[utils.mkvc(xx), utils.mkvc(yy), utils.mkvc(zz)] actv = utils.surface2ind_topo(self.mesh, topo, "N") actv = np.where(actv)[0] # Create active map to go from reduce space to full self.actvMap = maps.InjectActiveCells(self.mesh, actv, -100) nC = len(actv) # Create and array of observation points xr = np.linspace(-20.0, 20.0, 20) yr = np.linspace(-20.0, 20.0, 20) X, Y = np.meshgrid(xr, yr) # Move the observation points 5m above the topo Z = -np.exp((X**2 + Y**2) / 75**2) + self.mesh.vectorNz[-1] + 5.0 # Create a MAGsurvey locXYZ = np.c_[utils.mkvc(X.T), utils.mkvc(Y.T), utils.mkvc(Z.T)] rxLoc = gravity.Point(locXYZ) srcField = gravity.SourceField([rxLoc]) survey = gravity.Survey(srcField) # We can now create a density model and generate data # Here a simple block in half-space model = np.zeros((self.mesh.nCx, self.mesh.nCy, self.mesh.nCz)) model[(midx - 2):(midx + 2), (midy - 2):(midy + 2), -6:-2] = 0.5 model = utils.mkvc(model) self.model = model[actv] # Create active map to go from reduce set to full actvMap = maps.InjectActiveCells(self.mesh, actv, ndv) # Create reduced identity map idenMap = maps.IdentityMap(nP=nC) # Create the forward model operator sim = gravity.Simulation3DIntegral( self.mesh, survey=survey, rhoMap=idenMap, actInd=actv, store_sensitivities="ram", ) # Compute linear forward operator and compute some data # computing sensitivities to ram is best using dask processes with dask.config.set(scheduler="processes"): data = sim.make_synthetic_data(self.model, relative_error=0.0, noise_floor=0.001, add_noise=True) print(sim.G) # Create a regularization reg = regularization.Sparse(self.mesh, indActive=actv, mapping=idenMap) reg.norms = np.c_[0, 0, 0, 0] reg.gradientType = "component" # reg.eps_p, reg.eps_q = 5e-2, 1e-2 # Data misfit function dmis = data_misfit.L2DataMisfit(simulation=sim, data=data) # Add directives to the inversion opt = optimization.ProjectedGNCG(maxIter=100, lower=-1.0, upper=1.0, maxIterLS=20, maxIterCG=10, tolCG=1e-3) invProb = inverse_problem.BaseInvProblem(dmis, reg, opt, beta=1e8) # Here is where the norms are applied IRLS = directives.Update_IRLS(f_min_change=1e-4, minGNiter=1) update_Jacobi = directives.UpdatePreconditioner() sensitivity_weights = directives.UpdateSensitivityWeights( everyIter=False) self.inv = inversion.BaseInversion( invProb, directiveList=[IRLS, sensitivity_weights, update_Jacobi]) self.sim = sim