Exemple #1
0
    def setUp(self):

        # Define inducing field and sphere parameters
        H0 = (50000.0, 60.0, 250.0)
        # H0 = (50000., 90., 0.)
        self.b0 = mag.analytics.IDTtoxyz(-H0[1], H0[2], H0[0])
        self.rad = 2.0
        self.chi = 0.01

        # 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 susceptibility 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.chi * Vratio
        self.model = model[sph_ind]

        # Creat 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)
        self.xr = xr
        self.yr = yr
        X, Y = np.meshgrid(xr, yr)
        components = ["bx", "by", "bz", "tmi"]

        # 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)]
        rxLoc = mag.Point(self.locXyz, components=components)
        srcField = mag.SourceField([rxLoc], parameters=H0)
        self.survey = mag.Survey(srcField)

        self.sim = mag.Simulation3DIntegral(
            mesh,
            survey=self.survey,
            chiMap=idenMap,
            actInd=sph_ind,
            store_sensitivities="forward_only",
        )
    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",
        )
Exemple #3
0
    def setUp(self):

        Inc = 45.0
        Dec = 45.0
        Btot = 51000
        H0 = (Btot, Inc, Dec)

        self.b0 = mag.analytics.IDTtoxyz(-Inc, Dec, Btot)

        cs = 25.0
        hxind = [(cs, 5, -1.3), (cs / 2.0, 41), (cs, 5, 1.3)]
        hyind = [(cs, 5, -1.3), (cs / 2.0, 41), (cs, 5, 1.3)]
        hzind = [(cs, 5, -1.3), (cs / 2.0, 40), (cs, 5, 1.3)]
        M = discretize.TensorMesh([hxind, hyind, hzind], "CCC")

        chibkg = 0.0
        self.chiblk = 0.01
        chi = np.ones(M.nC) * chibkg

        self.rad = 100
        self.sphere_center = [0.0, 0.0, 0.0]
        sph_ind = getIndicesSphere(self.sphere_center, self.rad, M.gridCC)
        chi[sph_ind] = self.chiblk

        xr = np.linspace(-300, 300, 41)
        yr = np.linspace(-300, 300, 41)
        X, Y = np.meshgrid(xr, yr)
        Z = np.ones((xr.size, yr.size)) * 150
        components = ["bx", "by", "bz"]
        self.xr = xr
        self.yr = yr
        self.rxLoc = np.c_[utils.mkvc(X), utils.mkvc(Y), utils.mkvc(Z)]
        receivers = mag.Point(self.rxLoc, components=components)
        srcField = mag.SourceField([receivers], parameters=H0)

        self.survey = mag.Survey(srcField)

        self.sim = mag.simulation.Simulation3DDifferential(
            M,
            survey=self.survey,
            muMap=maps.ChiMap(M),
            solver=Pardiso,
        )
        self.M = M
        self.chi = chi
Exemple #4
0
                                       directiveList=directives_list)

# Run inversion
recovered_conductivity_model = dc_inversion.run(starting_conductivity_model)

###############################################################
# Recreate True Conductivity Model
# --------------------------------
#

background_value = 1e-2
conductor_value = 1e-1
resistor_value = 1e-3
true_conductivity_model = background_value * np.ones(nC)

ind_conductor = model_builder.getIndicesSphere(
    np.r_[-350.0, 0.0, -300.0], 160.0, mesh.cell_centers[ind_active, :])
true_conductivity_model[ind_conductor] = conductor_value

ind_resistor = model_builder.getIndicesSphere(np.r_[350.0, 0.0, -300.0], 160.0,
                                              mesh.cell_centers[ind_active, :])
true_conductivity_model[ind_resistor] = resistor_value
true_conductivity_model_log10 = np.log10(true_conductivity_model)

###############################################################
# Plotting True and Recovered Conductivity Model
# ----------------------------------------------
#

# Plot True Model
fig = plt.figure(figsize=(10, 4))
Exemple #5
0
# Define model. Models in SimPEG are vector arrays.
true_model = background_density * np.ones(nC)

# You could find the indicies of specific cells within the model and change their
# value to add structures.
ind_block = ((mesh.gridCC[ind_active, 0] > -50.0)
             & (mesh.gridCC[ind_active, 0] < -20.0)
             & (mesh.gridCC[ind_active, 1] > -15.0)
             & (mesh.gridCC[ind_active, 1] < 15.0)
             & (mesh.gridCC[ind_active, 2] > -50.0)
             & (mesh.gridCC[ind_active, 2] < -30.0))
true_model[ind_block] = block_density

# You can also use SimPEG utilities to add structures to the model more concisely
ind_sphere = model_builder.getIndicesSphere(np.r_[35.0, 0.0, -40.0], 15.0,
                                            mesh.gridCC)
ind_sphere = ind_sphere[ind_active]
true_model[ind_sphere] = sphere_density

############################################################
# Plotting True Model and Recovered Model
# ---------------------------------------
#

# Plot True Model
fig = plt.figure(figsize=(9, 4))
plotting_map = maps.InjectActiveCells(mesh, ind_active, np.nan)

ax1 = fig.add_axes([0.1, 0.1, 0.73, 0.8])
mesh.plotSlice(
    plotting_map * true_model,
# Run inversion
recovered_conductivity_model = dc_inversion.run(starting_conductivity_model)

############################################################
# Plotting True and Recovered Conductivity Model
# ----------------------------------------------
#

# Recreate true conductivity model
true_background_conductivity = 1e-2
true_conductor_conductivity = 1e-1
true_resistor_conductivity = 1e-3

true_conductivity_model = true_background_conductivity * np.ones(len(mesh))

ind_conductor = model_builder.getIndicesSphere(np.r_[-120.0, -180.0], 60.0,
                                               mesh.gridCC)
true_conductivity_model[ind_conductor] = true_conductor_conductivity

ind_resistor = model_builder.getIndicesSphere(np.r_[120.0, -180.0], 60.0,
                                              mesh.gridCC)
true_conductivity_model[ind_resistor] = true_resistor_conductivity

true_conductivity_model[~ind_active] = np.NaN

# Plot True Model
norm = LogNorm(vmin=1e-3, vmax=1e-1)

fig = plt.figure(figsize=(9, 4))
ax1 = fig.add_axes([0.1, 0.12, 0.72, 0.8])
im = mesh.plot_image(
    true_conductivity_model,
Exemple #7
0
# Print target misfit to compare with convergence
# print("Target misfit is " + str(target_misfit.target))

# Run the inversion
recovered_model = inv.run(starting_model)

##############################################################
# Recreate True Model
# -------------------
#

background_susceptibility = 0.0001
sphere_susceptibility = 0.01

true_model = background_susceptibility * np.ones(nC)
ind_sphere = model_builder.getIndicesSphere(np.r_[0.0, 0.0, -45.0], 15.0,
                                            mesh.cell_centers)
ind_sphere = ind_sphere[ind_active]
true_model[ind_sphere] = sphere_susceptibility

############################################################
# Plotting True Model and Recovered Model
# ---------------------------------------
#

# Plot True Model
fig = plt.figure(figsize=(9, 4))
plotting_map = maps.InjectActiveCells(mesh, ind_active, np.nan)

ax1 = fig.add_axes([0.08, 0.1, 0.75, 0.8])
mesh.plotSlice(
    plotting_map * true_model,
Exemple #8
0
# Define surface topography
[xx, yy] = np.meshgrid(mesh.vectorNx, mesh.vectorNy)
zz = -3 * np.exp((xx**2 + yy**2) / 60**2) + 45.0
topo = np.c_[mkvc(xx), mkvc(yy), mkvc(zz)]

# Set active cells and define unit values
air_value = 0.0
ind_active = surface2ind_topo(mesh, topo)
model_map = maps.InjectActiveCells(mesh, ind_active, air_value)

# Define model for cells under the surface topography
model = background_value * np.ones(ind_active.sum())

# Add a sphere
ind_sphere = model_builder.getIndicesSphere(np.r_[-25.0, 0.0, -15.0], 20.0,
                                            mesh.gridCC)
ind_sphere = ind_sphere[ind_active]  # So same size and order as model
model[ind_sphere] = sphere_value

# Add dyke defined by a set of points
xp = np.kron(np.ones((2)), [-10.0, 10.0, 55.0, 35.0])
yp = np.kron([-1000.0, 1000.0], np.ones((4)))
zp = np.kron(np.ones((2)), [-120.0, -120.0, 45.0, 45.0])
xyz_pts = np.c_[mkvc(xp), mkvc(yp), mkvc(zp)]
ind_polygon = model_builder.PolygonInd(mesh, xyz_pts)
ind_polygon = ind_polygon[ind_active]  # So same size and order as model
model[ind_polygon] = dyke_value

# Plot
fig = plt.figure(figsize=(5, 5))
ax = fig.add_subplot(111)
    def test_ana_boundary_computation(self):

        hxind = [(0, 25, 1.3), (21, 12.5), (0, 25, 1.3)]
        hyind = [(0, 25, 1.3), (21, 12.5), (0, 25, 1.3)]
        hzind = [(0, 25, 1.3), (20, 12.5), (0, 25, 1.3)]
        # hx, hy, hz = Utils.meshTensors(hxind, hyind, hzind)
        M3 = discretize.TensorMesh([hxind, hyind, hzind], "CCC")
        indxd, indxu, indyd, indyu, indzd, indzu = M3.faceBoundaryInd
        mu0 = 4 * np.pi * 1e-7
        chibkg = 0.0
        chiblk = 0.01
        chi = np.ones(M3.nC) * chibkg
        sph_ind = getIndicesSphere([0, 0, 0], 100, M3.gridCC)
        chi[sph_ind] = chiblk
        mu = (1.0 + chi) * mu0
        Bbc, const = mag.analytics.CongruousMagBC(M3, np.array([1.0, 0.0,
                                                                0.0]), chi)

        flag = "secondary"
        Box = 1.0
        H0 = Box / mu_0
        Bbcxx, Bbcxy, Bbcxz = mag.analytics.MagSphereAnaFun(
            M3.gridFx[(indxd | indxu), 0],
            M3.gridFx[(indxd | indxu), 1],
            M3.gridFx[(indxd | indxu), 2],
            100,
            0.0,
            0.0,
            0.0,
            mu_0,
            mu_0 * (1 + chiblk),
            H0,
            flag,
        )
        Bbcyx, Bbcyy, Bbcyz = mag.analytics.MagSphereAnaFun(
            M3.gridFy[(indyd | indyu), 0],
            M3.gridFy[(indyd | indyu), 1],
            M3.gridFy[(indyd | indyu), 2],
            100,
            0.0,
            0.0,
            0.0,
            mu_0,
            mu_0 * (1 + chiblk),
            H0,
            flag,
        )
        Bbczx, Bbczy, Bbczz = mag.analytics.MagSphereAnaFun(
            M3.gridFz[(indzd | indzu), 0],
            M3.gridFz[(indzd | indzu), 1],
            M3.gridFz[(indzd | indzu), 2],
            100,
            0.0,
            0.0,
            0.0,
            mu_0,
            mu_0 * (1 + chiblk),
            H0,
            flag,
        )
        Bbc_ana = np.r_[Bbcxx, Bbcyy, Bbczz]

        if plotIt:
            import matplotlib.pyplot as plt

            fig, ax = plt.subplots(1, 1, figsize=(10, 10))
            ax.plot(Bbc_ana)
            ax.plot(Bbc)
            plt.show()
        err = np.linalg.norm(Bbc - Bbc_ana) / np.linalg.norm(Bbc_ana)

        assert err < 0.1, "Mag Boundary computation is wrong!!, err = {}".format(
            err)