Beispiel #1
0
 def test_sphericalInclusions(self):
     mesh = discretize.TensorMesh([4, 5, 3])
     mapping = maps.SelfConsistentEffectiveMedium(mesh,
                                                  sigma0=1e-1,
                                                  sigma1=1.0)
     m = np.abs(np.random.rand(mesh.nC))
     mapping.test(m=m, dx=0.05, num=3)
Beispiel #2
0
 def test_spheroidalInclusions(self):
     mesh = discretize.TensorMesh([4, 3, 2])
     mapping = maps.SelfConsistentEffectiveMedium(
         mesh, sigma0=1e-1, sigma1=1.0, alpha0=0.8, alpha1=0.9, rel_tol=1e-8
     )
     m = np.abs(np.random.rand(mesh.nC))
     mapping.test(m=m, dx=0.05, num=3)
def run(plotIt=True):

    nC = 40
    de = 1.0
    h = np.ones(nC) * de / nC
    M = discretize.TensorMesh([h, h])

    y = np.linspace(M.vectorCCy[0], M.vectorCCx[-1], int(np.floor(nC / 4)))
    rlocs = np.c_[0 * y + M.vectorCCx[-1], y]
    rx = tomo.Rx(rlocs)

    source_list = [
        tomo.Src(location=np.r_[M.vectorCCx[0], yi], receiver_list=[rx])
        for yi in y
    ]

    # phi model
    phi0 = 0
    phi1 = 0.65
    phitrue = utils.model_builder.defineBlock(M.gridCC, [0.4, 0.6], [0.6, 0.4],
                                              [phi1, phi0])

    knownVolume = np.sum(phitrue * M.vol)
    print("True Volume: {}".format(knownVolume))

    # Set up true conductivity model and plot the model transform
    sigma0 = np.exp(1)
    sigma1 = 1e4

    if plotIt:
        fig, ax = plt.subplots(1, 1)
        sigmaMapTest = maps.SelfConsistentEffectiveMedium(nP=1000,
                                                          sigma0=sigma0,
                                                          sigma1=sigma1,
                                                          rel_tol=1e-1,
                                                          maxIter=150)
        testphis = np.linspace(0.0, 1.0, 1000)

        sigetest = sigmaMapTest * testphis
        ax.semilogy(testphis, sigetest)
        ax.set_title("Model Transform")
        ax.set_xlabel("$\\varphi$")
        ax.set_ylabel("$\sigma$")

    sigmaMap = maps.SelfConsistentEffectiveMedium(M,
                                                  sigma0=sigma0,
                                                  sigma1=sigma1)

    # scale the slowness so it is on a ~linear scale
    slownessMap = maps.LogMap(M) * sigmaMap

    # set up the true sig model and log model dobs
    sigtrue = sigmaMap * phitrue

    # modt = Model.BaseModel(M);
    slownesstrue = slownessMap * phitrue  # true model (m = log(sigma))

    # set up the problem and survey
    survey = tomo.Survey(source_list)
    problem = tomo.Simulation(M, survey=survey, slownessMap=slownessMap)

    if plotIt:
        fig, ax = plt.subplots(1, 1)
        cb = plt.colorbar(M.plotImage(phitrue, ax=ax)[0], ax=ax)
        survey.plot(ax=ax)
        cb.set_label("$\\varphi$")

    # get observed data
    data = problem.make_synthetic_data(phitrue,
                                       relative_error=0.03,
                                       add_noise=True)
    dpred = problem.dpred(np.zeros(M.nC))

    # objective function pieces
    reg = regularization.Tikhonov(M)
    dmis = data_misfit.L2DataMisfit(simulation=problem, data=data)
    dmisVol = Volume(mesh=M, knownVolume=knownVolume)
    beta = 0.25
    maxIter = 15

    # without the volume regularization
    opt = optimization.ProjectedGNCG(maxIter=maxIter, lower=0.0, upper=1.0)
    opt.remember("xc")
    invProb = inverse_problem.BaseInvProblem(dmis, reg, opt, beta=beta)
    inv = inversion.BaseInversion(invProb)

    mopt1 = inv.run(np.zeros(M.nC) + 1e-16)
    print("\nTotal recovered volume (no vol misfit term in inversion): "
          "{}".format(dmisVol(mopt1)))

    # with the volume regularization
    vol_multiplier = 9e4
    reg2 = reg
    dmis2 = dmis + vol_multiplier * dmisVol
    opt2 = optimization.ProjectedGNCG(maxIter=maxIter, lower=0.0, upper=1.0)
    opt2.remember("xc")
    invProb2 = inverse_problem.BaseInvProblem(dmis2, reg2, opt2, beta=beta)
    inv2 = inversion.BaseInversion(invProb2)

    mopt2 = inv2.run(np.zeros(M.nC) + 1e-16)
    print("\nTotal volume (vol misfit term in inversion): {}".format(
        dmisVol(mopt2)))

    # plot results

    if plotIt:

        fig, ax = plt.subplots(1, 1)
        ax.plot(data.dobs)
        ax.plot(dpred)
        ax.plot(problem.dpred(mopt1), "o")
        ax.plot(problem.dpred(mopt2), "s")
        ax.legend(["dobs", "dpred0", "dpred w/o Vol", "dpred with Vol"])

        fig, ax = plt.subplots(1, 3, figsize=(16, 4))
        im0 = M.plotImage(phitrue, ax=ax[0])[0]
        im1 = M.plotImage(mopt1, ax=ax[1])[0]
        im2 = M.plotImage(mopt2, ax=ax[2])[0]

        for im in [im0, im1, im2]:
            im.set_clim([0.0, phi1])

        plt.colorbar(im0, ax=ax[0])
        plt.colorbar(im1, ax=ax[1])
        plt.colorbar(im2, ax=ax[2])

        ax[0].set_title("true, vol: {:1.3e}".format(knownVolume))
        ax[1].set_title("recovered(no Volume term), vol: {:1.3e} ".format(
            dmisVol(mopt1)))
        ax[2].set_title("recovered(with Volume term), vol: {:1.3e} ".format(
            dmisVol(mopt2)))

        plt.tight_layout()
Beispiel #4
0
#

sigma_fluid = 3
sigma1 = np.logspace(1, 5, 5)  # look at a range of particle conductivities
phi = np.linspace(0.0, 1, 1000)  # vary the volume of particles

###############################################################################
# Construct the Mapping
# ---------------------
#
# We set the conductivity of the phase-0 material to the conductivity of the
# fluid. The mapping will then take a concentration (by volume), of phase-1
# material and compute the effective conductivity
#

scemt = maps.SelfConsistentEffectiveMedium(sigma0=sigma_fluid, sigma1=1)

###############################################################################
# Loop over a range of particle conductivities
# --------------------------------------------
#
# We loop over the values defined as `sigma1` and compute the effective
# conductivity of the mixture for each concentration in the `phi` vector
#

sige = np.zeros([phi.size, sigma1.size])

for i, s in enumerate(sigma1):
    scemt.sigma1 = s
    sige[:, i] = scemt * phi