def test_getInterpMatCartMesh_Edges2Faces(self):

        Mr = discretize.TensorMesh([100, 100, 2], x0="CC0")
        Mc = discretize.CylMesh(
            [np.ones(10) / 5, 1, 10], x0="0C0", cartesianOrigin=[-0.2, -0.2, 0]
        )

        Pe2f = Mc.getInterpolationMatCartMesh(Mr, "E", locTypeTo="F")
        me = np.ones(Mc.nE)

        frect = Pe2f * me

        excc = Mr.aveFx2CC * Mr.r(frect, "F", "Fx")
        eycc = Mr.aveFy2CC * Mr.r(frect, "F", "Fy")
        ezcc = Mr.r(frect, "F", "Fz")

        indX = utils.closestPoints(Mr, [0.45, -0.2, 0.5])
        indY = utils.closestPoints(Mr, [-0.2, 0.45, 0.5])

        TOL = 1e-2
        assert np.abs(float(excc[indX]) - 0) < TOL
        assert np.abs(float(excc[indY]) + 1) < TOL
        assert np.abs(float(eycc[indX]) - 1) < TOL
        assert np.abs(float(eycc[indY]) - 0) < TOL
        assert np.abs(ezcc.sum()) < TOL

        mag = (excc ** 2 + eycc ** 2) ** 0.5
        dist = ((Mr.gridCC[:, 0] + 0.2) ** 2 + (Mr.gridCC[:, 1] + 0.2) ** 2) ** 0.5

        assert np.abs(mag[dist > 0.1].max() - 1) < TOL
        assert np.abs(mag[dist > 0.1].min() - 1) < TOL
    def test_getInterpMatCartMesh_Faces2Edges(self):

        Mr = discretize.TensorMesh([100, 100, 2], x0="CC0")
        Mc = discretize.CylMesh(
            [np.ones(10) / 5, 1, 10], x0="0C0", cartesianOrigin=[-0.2, -0.2, 0]
        )

        self.assertTrue((Mc.cartesianOrigin == [-0.2, -0.2, 0]).all())

        Pf2e = Mc.getInterpolationMatCartMesh(Mr, "F", locTypeTo="E")
        mf = np.ones(Mc.nF)

        ecart = Pf2e * mf

        excc = Mr.aveEx2CC * Mr.r(ecart, "E", "Ex")
        eycc = Mr.aveEy2CC * Mr.r(ecart, "E", "Ey")
        ezcc = Mr.r(ecart, "E", "Ez")

        indX = utils.closestPoints(Mr, [0.45, -0.2, 0.5])
        indY = utils.closestPoints(Mr, [-0.2, 0.45, 0.5])

        TOL = 1e-2
        assert np.abs(float(excc[indX]) - 1) < TOL
        assert np.abs(float(excc[indY]) - 0) < TOL
        assert np.abs(float(eycc[indX]) - 0) < TOL
        assert np.abs(float(eycc[indY]) - 1) < TOL
        assert np.abs((ezcc - 1).sum()) < TOL

        mag = (excc ** 2 + eycc ** 2) ** 0.5
        dist = ((Mr.gridCC[:, 0] + 0.2) ** 2 + (Mr.gridCC[:, 1] + 0.2) ** 2) ** 0.5

        assert np.abs(mag[dist > 0.1].max() - 1) < TOL
        assert np.abs(mag[dist > 0.1].min() - 1) < TOL
    def test_getInterpMatCartMesh_Faces(self):

        Mr = discretize.TensorMesh([100, 100, 2], x0="CC0")
        Mc = discretize.CylMesh(
            [np.ones(10) / 5, 1, 10], x0="0C0", cartesianOrigin=[-0.2, -0.2, 0]
        )

        Pf = Mc.getInterpolationMatCartMesh(Mr, "F")
        mf = np.ones(Mc.nF)

        frect = Pf * mf

        fxcc = Mr.aveFx2CC * Mr.r(frect, "F", "Fx")
        fycc = Mr.aveFy2CC * Mr.r(frect, "F", "Fy")
        fzcc = Mr.r(frect, "F", "Fz")

        indX = utils.closestPoints(Mr, [0.45, -0.2, 0.5])
        indY = utils.closestPoints(Mr, [-0.2, 0.45, 0.5])

        TOL = 1e-2
        assert np.abs(float(fxcc[indX]) - 1) < TOL
        assert np.abs(float(fxcc[indY]) - 0) < TOL
        assert np.abs(float(fycc[indX]) - 0) < TOL
        assert np.abs(float(fycc[indY]) - 1) < TOL
        assert np.abs((fzcc - 1).sum()) < TOL

        mag = (fxcc ** 2 + fycc ** 2) ** 0.5
        dist = ((Mr.gridCC[:, 0] + 0.2) ** 2 + (Mr.gridCC[:, 1] + 0.2) ** 2) ** 0.5

        assert np.abs(mag[dist > 0.1].max() - 1) < TOL
        assert np.abs(mag[dist > 0.1].min() - 1) < TOL
Exemple #4
0
    def test_getInterpMatCartMesh_Edges(self):

        Mr = discretize.TensorMesh([100, 100, 2], x0='CC0')
        Mc = discretize.CylMesh([np.ones(10) / 5, 1, 10],
                                x0='0C0',
                                cartesianOrigin=[-0.2, -0.2, 0])

        Pe = Mc.getInterpolationMatCartMesh(Mr, 'E')
        me = np.ones(Mc.nE)

        ecart = Pe * me

        excc = Mr.aveEx2CC * Mr.r(ecart, 'E', 'Ex')
        eycc = Mr.aveEy2CC * Mr.r(ecart, 'E', 'Ey')
        ezcc = Mr.aveEz2CC * Mr.r(ecart, 'E', 'Ez')

        indX = utils.closestPoints(Mr, [0.45, -0.2, 0.5])
        indY = utils.closestPoints(Mr, [-0.2, 0.45, 0.5])

        TOL = 1e-2
        assert np.abs(float(excc[indX]) - 0) < TOL
        assert np.abs(float(excc[indY]) + 1) < TOL
        assert np.abs(float(eycc[indX]) - 1) < TOL
        assert np.abs(float(eycc[indY]) - 0) < TOL
        assert np.abs(ezcc.sum()) < TOL

        mag = (excc**2 + eycc**2)**0.5
        dist = ((Mr.gridCC[:, 0] + 0.2)**2 + (Mr.gridCC[:, 1] + 0.2)**2)**0.5

        assert np.abs(mag[dist > 0.1].max() - 1) < TOL
        assert np.abs(mag[dist > 0.1].min() - 1) < TOL
Exemple #5
0
 def src_b_closest(self):
     """
     closest face to where we want the return current electrode
     """
     if getattr(self, '_src_b_closest', None) is None:
         # find the z location of the closest face to the src
         src_b_closest = (self.mesh.gridFz[
             closestPoints(self.mesh, self.src_b, 'Fz'), :])
         assert (len(src_b_closest) == 1), 'multiple source locs found'
         self._src_b_closest = src_b_closest[0]
     return self._src_b_closest
Exemple #6
0
    def createLocalProb(rxLoc, wrGlobal, lims):

        # Grab the data for current tile
        ind_t = np.all([
            rxLoc[:, 0] >= lims[0], rxLoc[:, 0] <= lims[1],
            rxLoc[:, 1] >= lims[2], rxLoc[:, 1] <= lims[3], surveyMask
        ],
                       axis=0)

        # Remember selected data in case of tile overlap
        surveyMask[ind_t] = False

        # Create new survey
        rxLoc_t = PF.BaseGrav.RxObs(rxLoc[ind_t, :])
        srcField = PF.BaseGrav.SrcField([rxLoc_t])
        survey_t = PF.BaseGrav.LinearSurvey(srcField)
        survey_t.dobs = survey.dobs[ind_t]
        survey_t.std = survey.std[ind_t]
        survey_t.ind = ind_t

        # mesh_t = meshTree.copy()
        mesh_t = Utils.modelutils.meshBuilder(rxLoc[ind_t, :],
                                              h,
                                              padDist,
                                              meshGlobal=meshInput,
                                              meshType='TREE',
                                              gridLoc='CC')

        mesh_t = Utils.modelutils.refineTree(mesh_t,
                                             topo,
                                             dtype='surface',
                                             nCpad=[0, 3, 2],
                                             finalize=False)

        mesh_t = Utils.modelutils.refineTree(mesh_t,
                                             rxLoc[ind_t, :],
                                             dtype='surface',
                                             nCpad=[10, 5, 5],
                                             finalize=False)

        center = np.mean(rxLoc[ind_t, :], axis=0)
        tileCenter = np.r_[np.mean(lims[0:2]), np.mean(lims[2:]), center[2]]

        ind = closestPoints(mesh, tileCenter, gridLoc='CC')

        shift = np.squeeze(mesh.gridCC[ind, :]) - center

        mesh_t.x0 += shift
        mesh_t.finalize()

        print(mesh_t.nC)
        actv_t = Utils.surface2ind_topo(mesh_t, topo)

        # Create reduced identity map
        tileMap = Maps.Tile((mesh, actv), (mesh_t, actv_t))
        tileMap.nCell = 40
        tileMap.nBlock = 1

        # Create the forward model operator
        prob = PF.Gravity.GravityIntegral(mesh_t,
                                          rhoMap=tileMap,
                                          actInd=actv_t,
                                          memory_saving_mode=True,
                                          parallelized=True)
        survey_t.pair(prob)

        # Data misfit function
        dmis = DataMisfit.l2_DataMisfit(survey_t)
        dmis.W = 1. / survey_t.std

        wrGlobal += prob.getJtJdiag(np.ones(tileMap.P.shape[1]))

        # Create combo misfit function
        return dmis, wrGlobal