def test_Problem3D_N(self): problemDC = DC.Problem3D_N(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_N(self.mesh, sigma=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_N is passed" else: passed = False print ">> IP forward test for Problem3D_N is failed" self.assertTrue(passed)
def test_Problem3D_N(self, tolerance=0.1): problem = DC.Problem3D_N(self.mesh, sigma=self.sigma) 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.ROIedgeInds] - self.J_analytic[self.ROIedgeInds]) / np.linalg.norm(self.J_analytic[self.ROIedgeInds]) ) errJ = ( np.linalg.norm(eNumeric[self.ROIedgeInds] - self.E_analytic[self.ROIedgeInds]) / np.linalg.norm(self.E_analytic[self.ROIedgeInds]) ) 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_N passed") else: print('\n') print ('E field error =', errE) print ('J field error =', errJ) passed = False print(">> DC analytic test for Problem3D_N failed") self.assertTrue(passed)
def test_Problem3D_N(self): problem = DC.Problem3D_N(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_N is passed" else: passed = False print ">> DC analytic test for Problem3D_N is failed" self.assertTrue(passed)
def test_Problem3D_N(self, tolerance=0.2): problem = DC.Problem3D_N(self.mesh, sigma=self.sigma) 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 < 0.2: print(err) passed = True print(">> DC analytic test for Problem3D_N is passed") else: print(err) passed = False print(">> DC analytic test for Problem3D_N is failed") self.assertTrue(passed)
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
nC = int(actv.sum()) midLocs = survey.srcList[0].rxList[0].locs[0] + survey.srcList[0].rxList[ 0].locs[1] midLocs /= 2 idenMap = Maps.IdentityMap(nP=nC) expmap = Maps.ExpMap(mesh) actmap = Maps.InjectActiveCells(mesh, actv, np.log(1e-8)) mapping = expmap * actmap logmap = Maps.LogMap(mesh) m0 = np.log(np.ones_like(sigma) * 1e-3)[actv] mref = np.log(np.ones_like(sigma) * mref_val) problem = DC.Problem3D_N(mesh, sigmaMap=mapping, storeJ=True) problem.Solver = PardisoSolver problem.pair(survey) mtrue = np.log(sigma[actv]) # Depth weight #depth = 1./(abs(mesh.gridCC[:,2]))**1.5 #depth = depth/depth.max() d0 = survey.dpred(m0) dobs = survey.makeSyntheticData(mtrue, std=0.02) survey.std = abs(dobs) * 5e-2 + 1e-4 # EM.Static.Utils.writeUBC_DCobs('Survey_Synthetic.dat',survey,'3D','SURFACE') #wd = 1./(abs(dobs)*0.005)
survey.n_locations))) electrode_locations = uniq[0] actinds = Utils.surface2ind_topo(mesh, electrode_locations, method='cubic') survey.drapeTopo(mesh, actinds) # Begin Formulating Problem ############################################################ # print minE, maxE, minN, maxN # Setup Problem with exponential mapping and Active cells only in the core mesh expmap = Maps.ExpMap(mesh) mapactive = Maps.InjectActiveCells(mesh=mesh, indActive=actinds, valInactive=np.log(1e-8)) mapping = expmap * mapactive problem = DC.Problem3D_N(mesh, sigmaMap=mapping) problem.pair(survey) problem.Solver = Solver # %pylab inline # Assign Uncertainty out = plt.hist(np.log10(abs(survey.dobs) + 1e-5), bins=100) # print out plt.show() survey.std = 0.05 survey.eps = 1e-2 # Tikhonov Inversion# ############################################################
#survey = DC.Survey([src]) survey = EM.Static.Utils.gen_DCIPsurvey(endl, arrayType, 100, 100, 10) midLocs = survey.srcList[0].rxList[0].locs[0]+ survey.srcList[0].rxList[0].locs[1] midLocs /= 2 idenMap = Maps.IdentityMap(nP=mesh.nC) expmap = Maps.ExpMap(mesh) logmap = Maps.LogMap(mesh) m0 = np.log(np.ones_like(sigma)*mref_val) mref = np.log(np.ones_like(sigma)*mref_val) problem = DC.Problem3D_N(mesh, sigmaMap=expmap, storeJ=True) problem.Solver = PardisoSolver problem.pair(survey) mtrue = np.log(sigma) # Depth weight depth = 1./(abs(mesh.gridCC[:,2]))**1.5 depth = depth/depth.max() d0 = survey.dpred(m0) dobs = survey.makeSyntheticData(mtrue, std=0.02) wd = 1./(abs(dobs)*0.005) # Create inversion objects and run