예제 #1
0
def plate_fields(A, B, dx, dz, xc, zc, rotAng, sigplate, sighalf):
    # Create halfspace model
    mhalf = np.log(sighalf * np.ones([mesh.nC]))

    # Create true model with plate
    mtrue = createPlateMod(xc, zc, dx, dz, rotAng, sigplate, sighalf)

    Mx = np.empty(shape=(0, 2))
    Nx = np.empty(shape=(0, 2))
    rx = DC.Rx.Dipole(Mx, Nx)
    if B == []:
        src = DC.Src.Pole([rx], np.r_[A, 0.0])
    else:
        src = DC.Src.Dipole([rx], np.r_[A, 0.0], np.r_[B, 0.0])

    survey = DC.Survey([src])
    survey_prim = DC.Survey([src])

    problem = DC.Problem3D_CC(mesh, sigmaMap=mapping)
    problem_prim = DC.Problem3D_CC(mesh, sigmaMap=mapping)
    problem.Solver = SolverLU
    problem_prim.Solver = SolverLU
    problem.pair(survey)
    problem_prim.pair(survey_prim)

    primary_field = problem_prim.fields(mhalf)

    total_field = problem.fields(mtrue)

    return mtrue, mhalf, src, primary_field, total_field
예제 #2
0
def model_fields(A, B, zcLayer, dzLayer, xc, zc, r, sigLayer, sigTarget, sigHalf):
    # Create halfspace model
    mhalf = sigHalf * np.ones([mesh.nC])
    # Add layer to model
    mLayer = addLayer2Mod(zcLayer, dzLayer, mhalf, sigLayer)
    # Add plate or cylinder
    # fullMod = addPlate2Mod(xc,zc,dx,dz,rotAng,LayerMod,sigTarget)
    mtrue = addCylinder2Mod(xc, zc, r, mLayer, sigTarget)

    Mx = np.empty(shape=(0, 2))
    Nx = np.empty(shape=(0, 2))
    rx = DC.Rx.Dipole(Mx, Nx)
    if B == []:
        src = DC.Src.Pole([rx], np.r_[A, 0.0])
    else:
        src = DC.Src.Dipole([rx], np.r_[A, 0.0], np.r_[B, 0.0])

    survey = DC.Survey([src])
    survey_prim = DC.Survey([src])

    problem = DC.Problem3D_CC(mesh, sigmaMap=sigmaMap)
    problem_prim = DC.Problem3D_CC(mesh, sigmaMap=sigmaMap)
    problem.Solver = SolverLU
    problem_prim.Solver = SolverLU
    problem.pair(survey)
    problem_prim.pair(survey_prim)

    primary_field = problem_prim.fields(mhalf)

    total_field = problem.fields(mtrue)

    return mtrue, mhalf, src, primary_field, total_field
예제 #3
0
def getSensitivity(survey, A, B, M, N, model):

    if survey == "Dipole-Dipole":
        rx = DC.Rx.Dipole(np.r_[M, 0.0], np.r_[N, 0.0])
        src = DC.Src.Dipole([rx], np.r_[A, 0.0], np.r_[B, 0.0])
    elif survey == "Pole-Dipole":
        rx = DC.Rx.Dipole(np.r_[M, 0.0], np.r_[N, 0.0])
        src = DC.Src.Pole([rx], np.r_[A, 0.0])
    elif survey == "Dipole-Pole":
        rx = DC.Rx.Pole(np.r_[M, 0.0])
        src = DC.Src.Dipole([rx], np.r_[A, 0.0], np.r_[B, 0.0])
    elif survey == "Pole-Pole":
        rx = DC.Rx.Pole(np.r_[M, 0.0])
        src = DC.Src.Pole([rx], np.r_[A, 0.0])

    # Model mappings
    expmap = Maps.ExpMap(mesh)
    mapping = expmap

    survey = DC.Survey([src])
    problem = DC.Problem3D_CC(mesh, sigmaMap=mapping)
    problem.Solver = SolverLU
    problem.pair(survey)
    fieldObj = problem.fields(model)

    J = problem.Jtvec(model, np.array([1.0]), f=fieldObj)

    return J
예제 #4
0
    def setUp(self):
        mesh = Mesh.TensorMesh([30, 30], x0=[-0.5, -1.])
        sigma = np.ones(mesh.nC)
        model = np.log(sigma)

        prob = DC.Problem3D_CC(mesh, rhoMap=Maps.ExpMap(mesh))

        rx = DC.Rx.Pole(
            Utils.ndgrid([mesh.vectorCCx, np.r_[mesh.vectorCCy.max()]])
        )
        src = DC.Src.Dipole(
            [rx], np.r_[-0.25, mesh.vectorCCy.max()],
            np.r_[0.25, mesh.vectorCCy.max()]
        )
        survey = DC.Survey([src])

        prob.pair(survey)

        self.std = 0.01
        survey.std = self.std
        dobs = survey.makeSyntheticData(model)
        self.eps = 1e-8 * np.min(np.abs(dobs))
        survey.eps = self.eps
        dmis = DataMisfit.l2_DataMisfit(survey)

        self.model = model
        self.mesh = mesh
        self.survey = survey
        self.prob = prob
        self.dobs = dobs
        self.dmis = dmis
예제 #5
0
def run(plotIt=True):

    cs = 25.
    hx = [(cs, 7, -1.3), (cs, 21), (cs, 7, 1.3)]
    hy = [(cs, 7, -1.3), (cs, 21), (cs, 7, 1.3)]
    hz = [(cs, 7, -1.3), (cs, 20)]
    mesh = Mesh.TensorMesh([hx, hy, hz], 'CCN')
    sighalf = 1e-2
    sigma = np.ones(mesh.nC)*sighalf
    xtemp = np.linspace(-150, 150, 21)
    ytemp = np.linspace(-150, 150, 21)
    xyz_rxP = Utils.ndgrid(xtemp-10., ytemp, np.r_[0.])
    xyz_rxN = Utils.ndgrid(xtemp+10., ytemp, np.r_[0.])
    xyz_rxM = Utils.ndgrid(xtemp, ytemp, np.r_[0.])

    # if plotIt:
    #     fig, ax = plt.subplots(1,1, figsize = (5,5))
    #     mesh.plotSlice(sigma, grid=True, ax = ax)
    #     ax.plot(xyz_rxP[:,0],xyz_rxP[:,1], 'w.')
    #     ax.plot(xyz_rxN[:,0],xyz_rxN[:,1], 'r.', ms = 3)

    rx = DC.Rx.Dipole(xyz_rxP, xyz_rxN)
    src = DC.Src.Dipole([rx], np.r_[-200, 0, -12.5], np.r_[+200, 0, -12.5])
    survey = DC.Survey([src])
    problem = DC.Problem3D_CC(mesh, Solver=Solver, sigma=sigma)
    problem.pair(survey)

    data = survey.dpred()

    def DChalf(srclocP, srclocN, rxloc, sigma, I=1.):
        rp = (srclocP.reshape([1, -1])).repeat(rxloc.shape[0], axis=0)
        rn = (srclocN.reshape([1, -1])).repeat(rxloc.shape[0], axis=0)
        rP = np.sqrt(((rxloc-rp)**2).sum(axis=1))
        rN = np.sqrt(((rxloc-rn)**2).sum(axis=1))
        return I/(sigma*2.*np.pi)*(1/rP-1/rN)

    data_anaP = DChalf(
        np.r_[-200, 0, 0.], np.r_[+200, 0, 0.], xyz_rxP, sighalf
    )
    data_anaN = DChalf(
        np.r_[-200, 0, 0.], np.r_[+200, 0, 0.], xyz_rxN, sighalf
    )
    data_ana = data_anaP - data_anaN
    Data_ana = data_ana.reshape((21, 21), order='F')
    Data = data.reshape((21, 21), order='F')
    X = xyz_rxM[:, 0].reshape((21, 21), order='F')
    Y = xyz_rxM[:, 1].reshape((21, 21), order='F')

    if plotIt:
        fig, ax = plt.subplots(1, 2, figsize=(12, 5))
        vmin = np.r_[data, data_ana].min()
        vmax = np.r_[data, data_ana].max()
        dat0 = ax[0].contourf(X, Y, Data_ana, 60, vmin=vmin, vmax=vmax)
        dat1 = ax[1].contourf(X, Y, Data, 60, vmin=vmin, vmax=vmax)
        plt.colorbar(dat0, orientation='horizontal', ax=ax[0])
        plt.colorbar(dat1, orientation='horizontal', ax=ax[1])
        ax[1].set_title('Analytic')
        ax[0].set_title('Computed')

    return np.linalg.norm(data-data_ana)/np.linalg.norm(data_ana)
예제 #6
0
def run(plotIt=True):
    cs = 25.
    hx = [(cs, 7, -1.3), (cs, 21), (cs, 7, 1.3)]
    hy = [(cs, 7, -1.3), (cs, 21), (cs, 7, 1.3)]
    hz = [(cs, 7, -1.3), (cs, 20)]
    mesh = Mesh.TensorMesh([hx, hy, hz], 'CCN')
    sighalf = 1e-2
    sigma = np.ones(mesh.nC) * sighalf
    xtemp = np.linspace(-150, 150, 21)
    ytemp = np.linspace(-150, 150, 21)
    xyz_rxP = Utils.ndgrid(xtemp - 10., ytemp, np.r_[0.])
    xyz_rxN = Utils.ndgrid(xtemp + 10., ytemp, np.r_[0.])
    xyz_rxM = Utils.ndgrid(xtemp, ytemp, np.r_[0.])

    # if plotIt:
    #     fig, ax = plt.subplots(1,1, figsize = (5,5))
    #     mesh.plotSlice(sigma, grid=True, ax = ax)
    #     ax.plot(xyz_rxP[:,0],xyz_rxP[:,1], 'w.')
    #     ax.plot(xyz_rxN[:,0],xyz_rxN[:,1], 'r.', ms = 3)

    rx = DC.Rx.Dipole(xyz_rxP, xyz_rxN)
    src = DC.Src.Dipole([rx], np.r_[-200, 0, -12.5], np.r_[+200, 0, -12.5])
    survey = DC.Survey([src])
    problem = DC.Problem3D_CC(mesh)
    problem.pair(survey)
    try:
        from pymatsolver import MumpsSolver
        problem.Solver = MumpsSolver
    except Exception, e:
        pass
예제 #7
0
    def setup(self):
        self.setup_geometry()
        self.setup_measurement()


        # Setup Problem with exponential mapping and Active cells only in the core mesh
        expmap = Maps.ExpMap(self.mesh)
        mapactive = Maps.InjectActiveCells(mesh=self.mesh, indActive=self.actind,
                                           valInactive=-5.)
        self.mapping = expmap * mapactive
        problem = DC.Problem3D_CC(self.mesh, sigmaMap=self.mapping)
        problem.pair(self.survey.simpeg_survey)
        problem.Solver = Solver

        # Compute prediction using the forward model and true conductivity data.
        # survey.dpred(mtrue[actind])
        # Make synthetic data adding a noise to the prediction.
        # In fact prediction is computed again.

        self.set_syntetic_conductivity()
        #self.survey.simpeg_survey.makeSyntheticData(self.mtrue[self.actind], std=0.05, force=True)

        m = self.mtrue[self.actind]
        std = 0.05
        dtrue = self.survey.simpeg_survey.dpred(m, f=None)
        noise = std*abs(dtrue)*np.random.randn(*dtrue.shape)
        self.survey.simpeg_survey.dobs = dtrue+noise
        self.survey.simpeg_survey.std = dtrue*0 + std
예제 #8
0
    def test_Problem3D_CC_Dirchlet(self, tolerance=0.1):
        problem = DC.Problem3D_CC(
            self.mesh, sigma=self.sigma, bc_type='Dirchlet'
            )
        problem.Solver = Solver
        problem.pair(self.survey)

        f = problem.fields()
        eNumeric = Utils.mkvc(f[self.survey.srcList,'e'])
        jNumeric = Utils.mkvc(f[self.survey.srcList,'j'])
        errE = (
            np.linalg.norm(jNumeric[self.ROIfaceInds] - self.J_analytic[self.ROIfaceInds]) /
            np.linalg.norm(self.J_analytic[self.ROIfaceInds])
        )
        errJ = (
            np.linalg.norm(eNumeric[self.ROIfaceInds] - self.E_analytic[self.ROIfaceInds]) /
            np.linalg.norm(self.E_analytic[self.ROIfaceInds])
        )
        if errE < tolerance and errJ < tolerance:
            print('\n')
            print ('E field error =', errE)
            print ('J field error =', errJ)
            passed = True
            print(">> DC analytic test for Problem3D_CC_Dirchlet passed")
        else:
            print('\n')
            print ('E field error =', errE)
            print ('J field error =', errJ)
            passed = False
            print(">> DC analytic test for Problem3D_CC_Dirchlet failed")
        self.assertTrue(passed)
예제 #9
0
    def test_Problem3D_CC(self):

        problemDC = DC.Problem3D_CC(self.mesh)
        problemDC.Solver = self.Solver
        problemDC.pair(self.surveyDC)
        data0 = self.surveyDC.dpred(self.sigma0)
        finf = problemDC.fields(self.sigmaInf)
        datainf = self.surveyDC.dpred(self.sigmaInf, f=finf)
        problemIP = IP.Problem3D_CC(self.mesh,
                                    rho=1. / self.sigmaInf,
                                    Ainv=problemDC.Ainv,
                                    f=finf)
        problemIP.Solver = self.Solver
        surveyIP = IP.Survey([self.src])
        problemIP.pair(surveyIP)
        data_full = data0 - datainf
        data = surveyIP.dpred(self.eta)
        err = np.linalg.norm(
            (data - data_full) / data_full)**2 / data_full.size
        if err < 0.05:
            passed = True
            print ">> IP forward test for Problem3D_CC is passed"
        else:
            passed = False
            print ">> IP forward test for Problem3D_CC is failed"
        self.assertTrue(passed)
예제 #10
0
    def setup(self):
        self.setup_geometry()
        self.set_syntetic_conductivity()
        self.setup_measurement()

        # Setup Problem with exponential mapping and Active cells only in the core mesh
        expmap = Maps.ExpMap(self.mesh)
        extrude = Maps.Surject2Dto3D(self.mesh_core, normal='Y')
        mapactive = Maps.InjectActiveCells(mesh=self.mesh,
                                           indActive=self.actind,
                                           valInactive=-5.)
        self.mapping = expmap * mapactive * extrude
        assert self.mapping.nP == self.mesh_core.nCx * self.mesh_core.nCz
        problem = DC.Problem3D_CC(self.mesh, sigmaMap=self.mapping)
        problem.pair(self.survey.simpeg_survey)
        problem.Solver = SolverLU
        #problem.Solver = SolverBiCG

        # Compute prediction using the forward model and true conductivity data.
        # survey.dpred(mtrue[actind])
        # Make synthetic data adding a noise to the prediction.
        # In fact prediction is computed again.
        self.survey.simpeg_survey.makeSyntheticData(self.mtrue,
                                                    std=0.05,
                                                    force=True)
예제 #11
0
    def setUp(self):
        cs = 10
        nc = 20
        npad = 10
        mesh = Mesh.CylMesh([[(cs, nc), (cs, npad, 1.3)], np.r_[2 * np.pi],
                             [(cs, npad, -1.3), (cs, nc), (cs, npad, 1.3)]])

        mesh.x0 = np.r_[0., 0., -mesh.hz[:npad + nc].sum()]

        # receivers
        rx_x = np.linspace(10, 200, 20)
        rx_z = np.r_[-5]
        rx_locs = Utils.ndgrid([rx_x, np.r_[0], rx_z])
        rx_list = [DC.Rx.BaseRx(rx_locs, 'ex')]

        # sources
        src_a = np.r_[0., 0., -5.]
        src_b = np.r_[55., 0., -5.]

        src_list = [DC.Src.Dipole(rx_list, locA=src_a, locB=src_b)]

        self.mesh = mesh
        self.sigma_map = Maps.ExpMap(mesh) * Maps.InjectActiveCells(
            mesh, mesh.gridCC[:, 2] <= 0, np.log(1e-8))
        self.prob = DC.Problem3D_CC(mesh,
                                    sigmaMap=self.sigma_map,
                                    Solver=Pardiso,
                                    bc_type="Dirichlet")
        self.survey = DC.Survey(src_list)
        self.prob.pair(self.survey)
예제 #12
0
 def _setupDCProblem(self):
     expMap = Maps.ExpMap(self.mesh)
     inactiveCellIndices = numpy.logical_not(self.activeCellIndices)
     inactiveCellData = self.givenModelCond[inactiveCellIndices]
     mapActive = Maps.InjectActiveCells(mesh=self.mesh, indActive=self.activeCellIndices,
                                        valInactive=inactiveCellData)
     self.mapping = expMap * mapActive
     self.DCproblem = DC.Problem3D_CC(self.mesh, sigmaMap=self.mapping)
     self.DCproblem.pair(self.survey)
     self.DCproblem.Solver = Solver
     pass
예제 #13
0
def cylinder_fields(A, B, r, sigcyl, sighalf, xc=0.0, zc=-20.0):

    circhalf = np.r_[np.log(sighalf), np.log(sighalf), xc, zc, r]
    circtrue = np.r_[np.log(sigcyl), np.log(sighalf), xc, zc, r]

    mhalf = circmap * circhalf
    mtrue = circmap * circtrue

    Mx = np.empty(shape=(0, 2))
    Nx = np.empty(shape=(0, 2))
    # rx = DC.Rx.Dipole_ky(Mx,Nx)
    rx = DC.Rx.Dipole(Mx, Nx)
    if B == []:
        src = DC.Src.Pole([rx], np.r_[A, 0.0])
    else:
        src = DC.Src.Dipole([rx], np.r_[A, 0.0], np.r_[B, 0.0])
    # survey = DC.Survey_ky([src])
    survey = DC.Survey([src])
    survey_prim = DC.Survey([src])
    # problem = DC.Problem2D_CC(mesh, sigmaMap = sigmaMap)
    problem = DC.Problem3D_CC(mesh, sigmaMap=sigmaMap)
    problem_prim = DC.Problem3D_CC(mesh, sigmaMap=sigmaMap)
    problem.Solver = SolverLU
    problem_prim.Solver = SolverLU
    problem.pair(survey)
    problem_prim.pair(survey_prim)

    primary_field = problem_prim.fields(mhalf)
    # phihalf = f[src, 'phi', 15]
    # ehalf = f[src, 'e']
    # jhalf = f[src, 'j']
    # charge = f[src, 'charge']

    total_field = problem.fields(mtrue)
    # phi = f[src, 'phi', 15]
    # e = f[src, 'e']
    # j = f[src, 'j']
    # charge = f[src, 'charge']

    return mtrue, mhalf, src, total_field, primary_field
예제 #14
0
    def __init__(self, **kwargs):
        super(SimulationDC, self).__init__(**kwargs)

        self._prob = DC.Problem3D_CC(
            self.meshGenerator.mesh,
            sigmaMap=self.physprops.wires.sigma,
            bc_type='Dirichlet',
            Solver=Pardiso
        )
        self._src = DC.Src.Dipole([], self.src_a, self.src_b)
        self._survey = DC.Survey([self._src])

        self._prob.pair(self._survey)
예제 #15
0
    def setUp(self):
        mesh = Mesh.TensorMesh([30, 30], x0=[-0.5, -1.])
        sigma = np.random.rand(mesh.nC)
        model = np.log(sigma)

        prob = DC.Problem3D_CC(mesh, rhoMap=Maps.ExpMap(mesh))
        prob1 = DC.Problem3D_CC(mesh, rhoMap=Maps.ExpMap(mesh))

        rx = DC.Rx.Pole(
            Utils.ndgrid([mesh.vectorCCx, np.r_[mesh.vectorCCy.max()]]))
        rx1 = DC.Rx.Pole(
            Utils.ndgrid([mesh.vectorCCx, np.r_[mesh.vectorCCy.min()]]))
        src = DC.Src.Dipole([rx], np.r_[-0.25, mesh.vectorCCy.max()],
                            np.r_[0.25, mesh.vectorCCy.max()])
        src1 = DC.Src.Dipole([rx1], np.r_[-0.25, mesh.vectorCCy.max()],
                             np.r_[0.25, mesh.vectorCCy.max()])
        survey = DC.Survey([src])
        prob.pair(survey)

        survey1 = DC.Survey([src1])
        prob1.pair(survey1)

        dobs0 = survey.makeSyntheticData(model)
        dobs1 = survey1.makeSyntheticData(model)

        self.mesh = mesh
        self.model = model

        self.survey0 = survey
        self.prob0 = prob

        self.survey1 = survey1
        self.prob1 = prob1

        self.dmis0 = DataMisfit.l2_DataMisfit(self.survey0)
        self.dmis1 = DataMisfit.l2_DataMisfit(self.survey1)

        self.dmiscobmo = self.dmis0 + self.dmis1
예제 #16
0
 def test_Problem3D_CC(self):
     problem = DC.Problem3D_CC(self.mesh)
     problem.Solver = self.Solver
     problem.pair(self.survey)
     data = self.survey.dpred(self.sigma)
     err = np.linalg.norm(data - self.data_anal) / np.linalg.norm(
         self.data_anal)
     if err < 0.2:
         passed = True
         print ">> DC analytic test for Problem3D_CC is passed"
     else:
         passed = False
         print ">> DC analytic test for Problem3D_CC is failed"
     self.assertTrue(passed)
예제 #17
0
    def __init__(self, **kwargs):
        super(SimulationDC, self).__init__(**kwargs)

        self._prob = DC.Problem3D_CC(self.meshGenerator.mesh,
                                     sigmaMap=self.physprops.wires.sigma,
                                     bc_type='Dirichlet',
                                     Solver=Solver)
        self._srcList = [
            DC.Src.Dipole([], self.src_a[i, :], self.src_b[i, :])
            for i in range(self.src_a.shape[0])
        ]
        # self._src = DC.Src.Dipole([], self.src_a, self.src_b)
        self._survey = DC.Survey(self._srcList)

        self._prob.pair(self._survey)
예제 #18
0
 def test_Problem3D_CC_Mixed(self, tolerance=0.2):
     problem = DC.Problem3D_CC(self.mesh, sigma=self.sigma, bc_type='Mixed')
     problem.Solver = Solver
     problem.pair(self.survey)
     data = self.survey.dpred()
     err = (np.linalg.norm(data - self.data_ana) /
            np.linalg.norm(self.data_ana))
     if err < tolerance:
         print(err)
         passed = True
         print(">> DC analytic test for Problem3D_CC is passed")
     else:
         print(err)
         passed = False
         print(">> DC analytic test for Problem3D_CC is failed")
     self.assertTrue(passed)
예제 #19
0
 def test_Problem3D_CC_Dirchlet(self):
     problem = DC.Problem3D_CC(self.mesh, sigma=self.sigma, bc_type = 'Dirchlet')
     problem.Solver = Solver
     problem.pair(self.survey)
     data = self.survey.dpred()
     err = (
         np.linalg.norm(data - self.data_anal) /
         np.linalg.norm(self.data_anal)
     )
     if err < 0.2:
         passed = True
         print(">> DC analytic test for Problem3D_CC_Dirchlet is passed")
     else:
         passed = False
         print(">> DC analytic test for Problem3D_CC_Dirchlet is failed")
     self.assertTrue(passed)
예제 #20
0
    def setUp(self):

        aSpacing = 2.5
        nElecs = 5

        surveySize = nElecs * aSpacing - aSpacing
        cs = surveySize / nElecs / 4

        mesh = Mesh.TensorMesh(
            [
                [(cs, 10, -1.3), (cs, surveySize / cs), (cs, 10, 1.3)],
                [(cs, 3, -1.3), (cs, 3, 1.3)],
                # [(cs, 5, -1.3), (cs, 10)]
            ],
            'CN')

        srcList = DC.Utils.WennerSrcList(nElecs, aSpacing, in2D=True)
        survey = DC.Survey(srcList)
        problem = DC.Problem3D_CC(mesh,
                                  rhoMap=Maps.IdentityMap(mesh),
                                  storeJ=True)
        problem.pair(survey)

        mSynth = np.ones(mesh.nC)
        survey.makeSyntheticData(mSynth)

        # Now set up the problem to do some minimization
        dmis = DataMisfit.l2_DataMisfit(survey)
        reg = Regularization.Tikhonov(mesh)
        opt = Optimization.InexactGaussNewton(maxIterLS=20,
                                              maxIter=10,
                                              tolF=1e-6,
                                              tolX=1e-6,
                                              tolG=1e-6,
                                              maxIterCG=6)
        invProb = InvProblem.BaseInvProblem(dmis, reg, opt, beta=1e4)
        inv = Inversion.BaseInversion(invProb)

        self.inv = inv
        self.reg = reg
        self.p = problem
        self.mesh = mesh
        self.m0 = mSynth
        self.survey = survey
        self.dmis = dmis
예제 #21
0
    def setup(self):
        self.setup_geometry()
        self.set_real_data_survey()
        #self.set_syntetic_conductivity()
        #self.setup_measurement()

        self.ln_sigback = np.log(self.survey.median_apparent_conductivity())
        print("ln cond med: ", self.ln_sigback)

        # Setup Problem with exponential mapping and Active cells only in the core mesh
        expmap = Maps.ExpMap(self.mesh)
        mapactive = Maps.InjectActiveCells(mesh=self.mesh,
                                           indActive=self.actind,
                                           valInactive=self.ln_sigback)
        self.mapping = expmap * mapactive
        problem = DC.Problem3D_CC(self.mesh, sigmaMap=self.mapping)
        problem.pair(self.survey.simpeg_survey)
        problem.Solver = Solver
예제 #22
0
def getSensitivity(survey, A, B, M, N, model):

    if (survey == "Dipole-Dipole"):
        rx = DC.Rx.Dipole(np.r_[M, 0.], np.r_[N, 0.])
        src = DC.Src.Dipole([rx], np.r_[A, 0.], np.r_[B, 0.])
    elif (survey == "Pole-Dipole"):
        rx = DC.Rx.Dipole(np.r_[M, 0.], np.r_[N, 0.])
        src = DC.Src.Pole([rx], np.r_[A, 0.])
    elif (survey == "Dipole-Pole"):
        rx = DC.Rx.Pole(np.r_[M, 0.])
        src = DC.Src.Dipole([rx], np.r_[A, 0.], np.r_[B, 0.])
    elif (survey == "Pole-Pole"):
        rx = DC.Rx.Pole(np.r_[M, 0.])
        src = DC.Src.Pole([rx], np.r_[A, 0.])

    Srv = DC.Survey([src])
    problem = DC.Problem3D_CC(mesh, sigmaMap=sigmaMap)
    problem.Solver = SolverLU
    problem.pair(Srv)
    fieldObj = problem.fields(model)

    J = problem.Jtvec(model, np.array([1.]), f=fieldObj)

    return J
예제 #23
0
                                   indActive=actind2,
                                   valInactive=-6.)
mapping2 = expmap2 * mapactive

ymin, ymax = -1., 1.
zmin, zmax = -20., 0.
xyzlim = np.r_[[[xmin, xmax], [ymin, ymax], [zmin, zmax]]]
actind3, meshCore3 = Utils.meshutils.ExtractCoreMesh(xyzlim, mesh_3d)
expmap3 = Maps.ExpMap(mesh_3d)
mapactive = Maps.InjectActiveCells(mesh=mesh_3d,
                                   indActive=actind3,
                                   valInactive=-6.)
mapping3 = expmap3 * mapactive

# Setup forward problem:
problem_2d = DC.Problem3D_CC(mesh_2d, sigmaMap=mapping2)
problem_2d.pair(survey_2)
problem_2d.Solver = Solver
survey_2.dpred(mtrue_2[actind2])
survey_2.makeSyntheticData(mtrue_2[actind2], std=0.05, force=True)

problem_3d = DC.Problem3D_CC(mesh_3d, sigmaMap=mapping3)
problem_3d.pair(survey_3)
problem_3d.Solver = Solver
survey_3.dpred(mtrue_3[actind3])
survey_3.makeSyntheticData(mtrue_3[actind3], std=0.05, force=True)

# Plotting:
# rescaling:
k = survey_3.dobs.sum() / survey_2.dobs.sum()
plt.plot(k * survey_2.dobs, 'r*')
def DC2Dsurvey(mtrue, flag="PoleDipole", nmax=8):

    if flag == "PoleDipole":
        ntx = xr.size - 2
    elif flag == "DipolePole":
        ntx = xr.size - 2
    elif flag == "DipoleDipole":
        ntx = xr.size - 3
    else:
        raise Exception("Not Implemented")
    xzlocs = getPseudoLocs(xr, ntx, nmax, flag)

    txList = []
    zloc = -cs / 2.0
    for i in range(ntx):
        if flag == "PoleDipole":
            A = np.r_[xr[i], zloc]
            B = np.r_[mesh.vectorCCx.min(), zloc]
            if i < ntx - nmax + 1:
                Mx = xr[i + 1:i + 1 + nmax]
                _, Mz = get_Surface(mtrue, Mx)
                Nx = xr[i + 2:i + 2 + nmax]
                _, Nz = get_Surface(mtrue, Nx)

                M = np.c_[Mx, Mz]
                N = np.c_[Nx, Nz]
            else:
                Mx = xr[i + 1:ntx + 1]
                _, Mz = get_Surface(mtrue, Mx)
                Nx = xr[i + 2:i + 2 + nmax]
                _, Nz = get_Surface(mtrue, Nx)

                M = np.c_[Mx, Mz]
                N = np.c_[Nx, Nz]

        elif flag == "DipolePole":
            A = np.r_[xr[i], zloc]
            B = np.r_[xr[i + 1], zloc]
            if i < ntx - nmax + 1:
                Mx = xr[i + 2:i + 2 + nmax]
                _, Mz = get_Surface(mtrue, Mx)
                Nx = np.ones(nmax) * mesh.vectorCCx.max()
                _, Nz = get_Surface(mtrue, Nx)

                M = np.c_[Mx, Mz]
                N = np.c_[Nx, Nz]

            else:
                Mx = xr[i + 2:ntx + 2]
                _, Mz = get_Surface(mtrue, Mx)
                Nx = np.ones(ntx - i) * mesh.vectorCCx.max()
                _, Nz = get_Surface(mtrue, Nx)
                M = np.c_[Mx, Mz]
                N = np.c_[Nx, Nz]

        elif flag == "DipoleDipole":
            A = np.r_[xr[i], zloc]
            B = np.r_[xr[i + 1], zloc]
            if i < ntx - nmax:
                Mx = xr[i + 2:i + 2 + nmax]
                _, Mz = get_Surface(mtrue, Mx)
                Nx = xr[i + 3:i + 3 + nmax]
                _, Nz = get_Surface(mtrue, Nx)
                M = np.c_[Mx, Mz]
                N = np.c_[Nx, Nz]

            else:
                Mx = xr[i + 2:len(xr) - 1]
                _, Mz = get_Surface(mtrue, Mx)
                Nx = xr[i + 3:len(xr)]
                _, Nz = get_Surface(mtrue, Nx)
                M = np.c_[Mx, Mz]
                N = np.c_[Nx, Nz]

        rx = DC.Rx.Dipole(M, N)
        src = DC.Src.Dipole([rx], A, B)
        txList.append(src)

    survey = DC.Survey(txList)
    problem = DC.Problem3D_CC(mesh, sigmaMap=mapping)
    problem.pair(survey)

    return survey, xzlocs
def model_fields(A, B, mtrue, mhalf, mair, mover, whichprimary="overburden"):

    idA, surfaceA = get_Surface(mtrue, A)
    idB, surfaceB = get_Surface(mtrue, B)

    Mx = mesh.gridCC
    # Nx = np.empty(shape =(mesh.nC, 2))
    rx = DC.Rx.Pole(Mx)
    # rx = DC.Rx.Dipole(Mx, Nx)
    if B == []:
        src = DC.Src.Pole([rx], np.r_[A, surfaceA])
    else:
        src = DC.Src.Dipole([rx], np.r_[A, surfaceA], np.r_[B, surfaceB])
    # src = DC.Src.Dipole([rx], np.r_[A, 0.], np.r_[B, 0.])
    survey = DC.Survey([src])
    # survey = DC.Survey([src])
    # survey_prim = DC.Survey([src])
    survey_prim = DC.Survey([src])
    survey_air = DC.Survey([src])
    # problem = DC.Problem3D_CC(mesh, sigmaMap = mapping)
    problem = DC.Problem3D_CC(mesh, sigmaMap=mapping)
    # problem_prim = DC.Problem3D_CC(mesh, sigmaMap = mapping)
    problem_prim = DC.Problem3D_CC(mesh, sigmaMap=mapping)
    problem_air = DC.Problem3D_CC(mesh, sigmaMap=mapping)

    problem.Solver = SolverLU
    problem_prim.Solver = SolverLU
    problem_air.Solver = SolverLU

    problem.pair(survey)
    problem_prim.pair(survey_prim)
    problem_air.pair(survey_air)

    mesh.setCellGradBC("neumann")
    cellGrad = mesh.cellGrad
    faceDiv = mesh.faceDiv

    if whichprimary == "air":
        phi_primary = survey_prim.dpred(mair)
    elif whichprimary == "half":
        phi_primary = survey_prim.dpred(mhalf)
    elif whichprimary == "overburden":
        phi_primary = survey_prim.dpred(mover)
    e_primary = -cellGrad * phi_primary
    j_primary = problem_prim.MfRhoI * problem_prim.Grad * phi_primary
    q_primary = epsilon_0 * problem_prim.Vol * (faceDiv * e_primary)
    primary_field = {
        "phi": phi_primary,
        "e": e_primary,
        "j": j_primary,
        "q": q_primary
    }

    phi_total = survey.dpred(mtrue)
    e_total = -cellGrad * phi_total
    j_total = problem.MfRhoI * problem.Grad * phi_total
    q_total = epsilon_0 * problem.Vol * (faceDiv * e_total)
    total_field = {"phi": phi_total, "e": e_total, "j": j_total, "q": q_total}

    phi_air = survey.dpred(mair)
    e_air = -cellGrad * phi_air
    j_air = problem.MfRhoI * problem.Grad * phi_air
    q_air = epsilon_0 * problem.Vol * (faceDiv * e_air)
    air_field = {"phi": phi_air, "e": e_air, "j": j_air, "q": q_air}

    return src, primary_field, air_field, total_field
예제 #26
0
def DC2Dsurvey(flag="PoleDipole"):

    if flag == "PoleDipole":
        ntx, nmax = xr.size - 2, 8
    elif flag == "DipolePole":
        ntx, nmax = xr.size - 2, 8
    elif flag == "DipoleDipole":
        ntx, nmax = xr.size - 3, 8
    else:
        raise Exception('Not Implemented')
    xzlocs = getPseudoLocs(xr, ntx, nmax, flag)

    txList = []
    zloc = -2.5
    for i in range(ntx):
        if flag == "PoleDipole":
            A = np.r_[xr[i], zloc]
            B = np.r_[mesh.vectorCCx.min(), zloc]
            if i < ntx - nmax + 1:
                M = np.c_[xr[i + 1:i + 1 + nmax], np.ones(nmax) * zloc]
                N = np.c_[xr[i + 2:i + 2 + nmax], np.ones(nmax) * zloc]
            else:
                M = np.c_[xr[i + 1:ntx + 1], np.ones(ntx - i) * zloc]
                N = np.c_[xr[i + 2:i + 2 + nmax], np.ones(ntx - i) * zloc]
        elif flag == "DipolePole":
            A = np.r_[xr[i], zloc]
            B = np.r_[xr[i + 1], zloc]
            if i < ntx - nmax + 1:
                M = np.c_[xr[i + 2:i + 2 + nmax], np.ones(nmax) * zloc]
                N = np.c_[np.ones(nmax) * mesh.vectorCCx.max(),
                          np.ones(nmax) * zloc]
            else:
                M = np.c_[xr[i + 2:ntx + 2], np.ones(ntx - i) * zloc]
                N = np.c_[np.ones(ntx - i) * mesh.vectorCCx.max(),
                          np.ones(ntx - i) * zloc]
        elif flag == "DipoleDipole":
            A = np.r_[xr[i], zloc]
            B = np.r_[xr[i + 1], zloc]
            if i < ntx - nmax:
                M = np.c_[xr[i + 2:i + 2 + nmax],
                          np.ones(len(xr[i + 2:i + 2 + nmax])) * zloc]
                N = np.c_[xr[i + 3:i + 3 + nmax],
                          np.ones(len(xr[i + 3:i + 3 + nmax])) * zloc]
            else:
                M = np.c_[xr[i + 2:len(xr) - 1],
                          np.ones(len(xr[i + 2:len(xr) - 1])) * zloc]
                N = np.c_[xr[i + 3:len(xr)],
                          np.ones(len(xr[i + 3:len(xr)])) * zloc]

        rx = DC.Rx.Dipole(M, N)
        src = DC.Src.Dipole([rx], A, B)
        txList.append(src)

    survey = DC.Survey(txList)
    problem = DC.Problem3D_CC(mesh, mapping=mapping)
    problem.pair(survey)

    sigblk, sighalf = 2e-2, 2e-3
    xc, yc, r = -15, -8, 4
    mtrue = np.r_[np.log(sigblk), np.log(sighalf), xc, yc, r]
    dtrue = survey.dpred(mtrue)
    perc = 0.1
    floor = np.linalg.norm(dtrue) * 1e-3
    np.random.seed([1])
    uncert = np.random.randn(survey.nD) * perc + floor
    dobs = dtrue + uncert

    return dobs, uncert, survey, xzlocs
예제 #27
0
dl_y = (Tx[-1][1] - Tx[0][1]) / dl_len
azm = np.arctan(dl_y / dl_x)

# Plot stations along line
if stype == 'gradient':
    Rx = survey.srcList[0].rxList[0].locs
    plt.scatter(Tx[0][0::3], Tx[0][1::3], s=40, c='r')
    plt.scatter(np.c_[Rx[0][:, 0], Rx[1][:, 0]],
                np.c_[Rx[0][:, 1], Rx[1][:, 1]],
                s=20,
                c='y')

#%% Forward model data
data = []  #np.zeros( nstn*nrx )
unct = []
problem = DC.Problem3D_CC(mesh)

for src in survey.srcList:
    start_time = time.time()

    # Select dipole locations for receiver
    rxloc_M = np.asarray(src.rxList[0].locs[0])
    rxloc_N = np.asarray(src.rxList[0].locs[1])

    # Number of receivers
    nrx = rxloc_M.shape[0]

    if not re.match(stype, 'pole-dipole'):
        tx = np.squeeze(src.loc)
        inds = Utils.closestPoints(mesh, tx)
        RHS = mesh.getInterpolationMat(tx, 'CC').T * ([-1, 1] / mesh.vol[inds])
예제 #28
0
            #M = np.c_[np.arange(locA[0]+1.,12.,2),np.ones(nSrc-i)*z]
            #N = np.c_[np.arange(locA[0]+3.,14.,2),np.ones(nSrc-i)*z]
            M = np.c_[np.arange(-12., 10 + 1, 2), np.ones(12) * z]
            N = np.c_[np.arange(-10., 12 + 1, 2), np.ones(12) * z]
            rx = DC.Rx.Dipole(M, N)
            src = DC.Src.Dipole([rx], locA, locB)
            srclist.append(src)
            #print "line2",locA,locB,"\n",[M,N],"\n"

            #rx = DC.Rx.Dipole(-M,-N)
            #src= DC.Src.Dipole([rx],-locA,-locB)
            #srclist.append(src)

mapping = Maps.ExpMap(mesh)
survey = DC.Survey(srclist)
problem = DC.Problem3D_CC(mesh, sigmaMap=mapping)
problem.pair(survey)
problem.Solver = PardisoSolver

survey.dpred(mtrue)
survey.makeSyntheticData(mtrue, std=0.05, force=True)

print '# of data: ', survey.dobs.shape

#Simple Inversion
regmesh = mesh
m0 = (-5.) * np.ones(mapping.nP)
dmis = DataMisfit.l2_DataMisfit(survey)
reg = Regularization.Tikhonov(regmesh)  #,mapping = mapping)#,indActive=actind)
reg.mref = m0
opt = Optimization.InexactGaussNewton(maxIter=20, tolX=1e-6)
예제 #29
0
hx = [(cs, 7, -1.3), (cs, 21), (cs, 7, 1.3)]
hy = [(cs, 7, -1.3), (cs, 21), (cs, 7, 1.3)]
hz = [(cs, 7, -1.3), (cs, 20)]
mesh = Mesh.TensorMesh([hx, hy, hz], 'CCN')
sighalf = 1e-2
sigma = np.ones(mesh.nC) * sighalf
xtemp = np.linspace(-150, 150, 21)
ytemp = np.linspace(-150, 150, 21)
xyz_rxP = Utils.ndgrid(xtemp - 10., ytemp, np.r_[0.])
xyz_rxN = Utils.ndgrid(xtemp + 10., ytemp, np.r_[0.])
xyz_rxM = Utils.ndgrid(xtemp, ytemp, np.r_[0.])

rx = DC.Rx.Dipole(xyz_rxP, xyz_rxN)
src = DC.Src.Dipole([rx], np.r_[-200, 0, -12.5], np.r_[+200, 0, -12.5])
survey = DC.Survey([src])
problem = DC.Problem3D_CC(mesh, Solver=Solver, sigma=sigma)
problem.pair(survey)

data = survey.dpred()


def DChalf(srclocP, srclocN, rxloc, sigma, I=1.):
    rp = (srclocP.reshape([1, -1])).repeat(rxloc.shape[0], axis=0)
    rn = (srclocN.reshape([1, -1])).repeat(rxloc.shape[0], axis=0)
    rP = np.sqrt(((rxloc - rp)**2).sum(axis=1))
    rN = np.sqrt(((rxloc - rn)**2).sum(axis=1))
    return I / (sigma * 2. * np.pi) * (1 / rP - 1 / rN)


data_anaP = DChalf(np.r_[-200, 0, 0.], np.r_[+200, 0, 0.], xyz_rxP, sighalf)
data_anaN = DChalf(np.r_[-200, 0, 0.], np.r_[+200, 0, 0.], xyz_rxN, sighalf)