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
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
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)
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
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
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
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)
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)
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)
def setUp(self): # Note: Pole-Pole requires bigger boundary to obtain good accuracy. # One can use greater padding rate. Here 1.5 is used. cs = 12.5 hx = [(cs, 7, -1.5), (cs, 61), (cs, 7, 1.5)] hy = [(cs, 7, -1.5), (cs, 20)] mesh = Mesh.TensorMesh([hx, hy], x0="CN") sighalf = 1e-2 sigma = np.ones(mesh.nC) * sighalf x = np.linspace(0, 250., 20) M = Utils.ndgrid(x - 12.5, np.r_[0.]) A0loc = np.r_[-150, 0.] rxloc = np.c_[M, np.zeros(20)] data_anal = EM.Analytics.DCAnalytic_Pole_Pole(np.r_[A0loc, 0.], rxloc, sighalf, earth_type="halfspace") rx = DC.Rx.Pole_ky(M) src0 = DC.Src.Pole([rx], A0loc) survey = DC.Survey_ky([src0]) self.survey = survey self.mesh = mesh self.sigma = sigma self.data_anal = data_anal try: from pymatsolver import PardisoSolver self.Solver = PardisoSolver except ImportError: self.Solver = SolverLU
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)
def setUp(self): cs = 12.5 npad = 2 hx = [(cs, npad, -1.3), (cs, 21), (cs, npad, 1.3)] hy = [(cs, npad, -1.3), (cs, 21), (cs, npad, 1.3)] hz = [(cs, npad, -1.3), (cs, 20)] mesh = Mesh.TensorMesh([hx, hy, hz], x0="CCN") x = mesh.vectorCCx[(mesh.vectorCCx > -80.) & (mesh.vectorCCx < 80.)] y = mesh.vectorCCx[(mesh.vectorCCy > -80.) & (mesh.vectorCCy < 80.)] Aloc = np.r_[-100., 0., 0.] Bloc = np.r_[100., 0., 0.] M = Utils.ndgrid(x-12.5, y, np.r_[0.]) N = Utils.ndgrid(x+12.5, y, np.r_[0.]) radius = 50. xc = np.r_[0., 0., -100] blkind = Utils.ModelBuilder.getIndicesSphere(xc, radius, mesh.gridCC) sigmaInf = np.ones(mesh.nC)*1e-2 eta = np.zeros(mesh.nC) eta[blkind] = 0.1 sigma0 = sigmaInf*(1.-eta) rx = DC.Rx.Dipole(M, N) src = DC.Src.Dipole([rx], Aloc, Bloc) surveyDC = DC.Survey([src]) self.surveyDC = surveyDC self.mesh = mesh self.sigmaInf = sigmaInf self.sigma0 = sigma0 self.src = src self.eta = eta
def setUp(self): cs = 25. hx = [(cs, 7, -1.5), (cs, 21), (cs, 7, 1.5)] hy = [(cs, 7, -1.5), (cs, 21), (cs, 7, 1.5)] hz = [(cs, 7, -1.5), (cs, 20)] mesh = Mesh.TensorMesh([hx, hy, hz], x0="CCN") sigma = np.ones(mesh.nC) * 1e-2 x = mesh.vectorCCx[(mesh.vectorCCx > -155.) & (mesh.vectorCCx < 155.)] y = mesh.vectorCCy[(mesh.vectorCCy > -155.) & (mesh.vectorCCy < 155.)] Aloc = np.r_[-200., 0., 0.] M = Utils.ndgrid(x, y, np.r_[0.]) phiA = EM.Analytics.DCAnalytic_Pole_Pole(Aloc, M, 1e-2, earth_type="halfspace") data_ana = phiA rx = DC.Rx.Pole(M) src = DC.Src.Pole([rx], Aloc) survey = DC.Survey([src]) self.survey = survey self.mesh = mesh self.sigma = sigma self.data_ana = data_ana
def simpeg_survey(self): """ Create the measurement setup as an instance of DC Survey. :return: DC.Survey instance """ if self._simpeg_survey is None: probe_points = self.points.all_points group_by_cc = {} for ca, cb, pa, pb in self.measurements: group_by_cc.setdefault((ca, cb), []) group_by_cc[(ca, cb)].append((pa, pb)) src_list = [] sorted = [(cc, pp) for cc, pp in group_by_cc.items()] sorted.sort() for cc, pp_list in sorted: rx_list = [ DC.Rx.Dipole(probe_points[pp[0], :], probe_points[pp[1], :]) for pp in pp_list ] I = 1.0 src = DC.Src.Dipole(rx_list, probe_points[cc[0], :], probe_points[cc[1], :], current=I) src_list.append(src) self._simpeg_survey = DC.Survey(src_list) if self._values is not None: self._simpeg_survey.dobs = self._values self._simpeg_survey.std = self._errors return self._simpeg_survey
def setUp(self): aSpacing = 2.5 nElecs = 10 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_N(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
def setUp(self): cs = 12.5 hx = [(cs, 7, -1.3), (cs, 61), (cs, 7, 1.3)] hy = [(cs, 7, -1.3), (cs, 20)] mesh = Mesh.TensorMesh([hx, hy], x0="CN") x = np.linspace(-135, 250., 20) M = Utils.ndgrid(x - 12.5, np.r_[0.]) N = Utils.ndgrid(x + 12.5, np.r_[0.]) A0loc = np.r_[-150, 0.] A1loc = np.r_[-130, 0.] rxloc = [np.c_[M, np.zeros(20)], np.c_[N, np.zeros(20)]] rx = DC.Rx.Dipole_ky(M, N) src0 = DC.Src.Pole([rx], A0loc) src1 = DC.Src.Pole([rx], A1loc) survey = DC.Survey_ky([src0, src1]) problem = DC.Problem2D_N(mesh, mapping=[('rho', Maps.IdentityMap(mesh))]) problem.pair(survey) mSynth = np.ones(mesh.nC) * 1. 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=1e0) 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
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
def _setupSurvey(self): epp = self.tunnelParams.getSingleArrayTunnelCelingEnds() p1, s1 = Tunnel_SurveyTools.getLinearArraySurvey(epp, 5, self.surveyType) epp = self.tunnelParams.getSingleArrayFloorEnds() p2, s2 = Tunnel_SurveyTools.getLinearArraySurvey(epp, 5, self.surveyType) epp = self.tunnelParams.getSingleArrayRightSideEnds() p3, s3 = Tunnel_SurveyTools.getLinearArraySurvey(epp, 5, self.surveyType) epp = self.tunnelParams.getSingleArrayLeftSideEnds() p4, s4 = Tunnel_SurveyTools.getLinearArraySurvey(epp, 5, self.surveyType) self.allSurveyPoints = numpy.vstack((p1, p2, p3, p4)) self.survey = DC.Survey(s1.srcList + s2.srcList + s3.srcList + s4.srcList) pass
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