def model_fields(A, B, zcLayer, dzLayer, xc, zc, r, sigLayer, sigTarget, sigHalf): # Create halfspace model halfspaceMod = sigHalf * np.ones([ mesh.nC, ]) mhalf = np.log(halfspaceMod) # Add layer to model LayerMod = addLayer2Mod(zcLayer, dzLayer, halfspaceMod, sigLayer) mLayer = np.log(LayerMod) # Add plate or cylinder # fullMod = addPlate2Mod(xc,zc,dx,dz,rotAng,LayerMod,sigTarget) fullMod = addCylinder2Mod(xc, zc, r, LayerMod, sigTarget) mtrue = np.log(fullMod) Mx = mesh.gridCC # Nx = np.empty(shape=(mesh.nC, 2)) rx = DC.Rx.Pole_ky(Mx) # rx = DC.Rx.Dipole(Mx,Nx) if (B == []): src = DC.Src.Pole([rx], np.r_[A, 0.]) else: src = DC.Src.Dipole([rx], np.r_[A, 0.], np.r_[B, 0.]) # src = DC.Src.Dipole_ky([rx], np.r_[A,0.], np.r_[B,0.]) survey = DC.Survey_ky([src]) # survey = DC.Survey([src]) # survey_prim = DC.Survey([src]) survey_prim = DC.Survey_ky([src]) #problem = DC.Problem3D_CC(mesh, sigmaMap = mapping) problem = DC.Problem2D_CC(mesh, sigmaMap=mapping) # problem_prim = DC.Problem3D_CC(mesh, sigmaMap = mapping) problem_prim = DC.Problem2D_CC(mesh, sigmaMap=mapping) problem.Solver = SolverLU problem_prim.Solver = SolverLU problem.pair(survey) problem_prim.pair(survey_prim) mesh.setCellGradBC("neumann") cellGrad = mesh.cellGrad faceDiv = mesh.faceDiv phi_primary = survey_prim.dpred(mhalf) 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} 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, ])) # mhalf = sighalf*np.ones([mesh.nC,]) # Create true model with plate mtrue = createPlateMod(xc, zc, dx, dz, rotAng, sigplate, sighalf) Mx = mesh.gridCC # Nx = np.empty(shape=(mesh.nC, 2)) rx = DC.Rx.Pole_ky(Mx) # rx = DC.Rx.Dipole(Mx,Nx) if (B == []): src = DC.Src.Pole([rx], np.r_[A, 0.]) else: src = DC.Src.Dipole([rx], np.r_[A, 0.], np.r_[B, 0.]) # src = DC.Src.Dipole_ky([rx], np.r_[A,0.], np.r_[B,0.]) survey = DC.Survey_ky([src]) # survey = DC.Survey([src]) # survey_prim = DC.Survey([src]) survey_prim = DC.Survey_ky([src]) #problem = DC.Problem3D_CC(mesh, sigmaMap = mapping) problem = DC.Problem2D_CC(mesh, sigmaMap=mapping) # problem_prim = DC.Problem3D_CC(mesh, sigmaMap = mapping) problem_prim = DC.Problem2D_CC(mesh, sigmaMap=mapping) problem.Solver = SolverLU problem_prim.Solver = SolverLU problem.pair(survey) problem_prim.pair(survey_prim) mesh.setCellGradBC("neumann") cellGrad = mesh.cellGrad faceDiv = mesh.faceDiv phi_primary = survey_prim.dpred(mhalf) 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} return mtrue, mhalf, src, primary_field, total_field
def test_Problem2D_CC(self): problemDC = DC.Problem2D_CC(self.mesh, rhoMap=Maps.IdentityMap(self.mesh)) problemDC.Solver = Solver problemDC.pair(self.surveyDC) data0 = self.surveyDC.dpred(1. / self.sigma0) finf = problemDC.fields(1. / self.sigmaInf) datainf = self.surveyDC.dpred(1. / self.sigmaInf, f=finf) problemIP = IP.Problem2D_CC(self.mesh, rho=1. / self.sigmaInf, etaMap=Maps.IdentityMap(self.mesh)) problemIP.Solver = Solver surveyIP = IP.Survey(self.srcLists_ip) 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 Problem2D_CC is passed") else: import matplotlib.pyplot as plt passed = False print(">> IP forward test for Problem2D_CC is failed") print(err) plt.plot(data_full) plt.plot(data, 'k.') plt.show() self.assertTrue(passed)
def test_Problem3D_CC(self): problem = DC.Problem2D_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)/self.data_anal)**2 / self.data_anal.size if err < 0.05: 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)
def test_Problem2D_CC(self, tolerance=0.05): problem = DC.Problem2D_CC(self.mesh, sigma=self.sigma) problem.Solver = self.Solver problem.pair(self.survey) data = self.survey.dpred() err = (np.linalg.norm( (data - self.data_anal) / self.data_anal)**2 / self.data_anal.size) if err < tolerance: passed = True print(">> DC analytic test for PDP Problem2D_CC is passed") else: print(err) passed = False print(">> DC analytic test for PDP Problem2D_CC is failed") self.assertTrue(passed)
def test_Problem3D_CC(self): problem = DC.Problem2D_CC(self.mesh, sigma=self.sigma) problem.Solver = self.Solver problem.pair(self.survey) data = self.survey.dpred() err = (np.linalg.norm( (data - self.data_anal) / self.data_anal)**2 / self.data_anal.size) if err < 0.3: passed = True print(">> DC analytic test for Problem3D_CC is passed") else: passed = False print(">> DC analytic test for Problem3D_CC is failed") print(err) plt.plot(data) plt.plot(self.data_anal) plt.show() self.assertTrue(passed)
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_CC(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 getSensitivity(survey, A, B, M, N, model): if (survey == "Dipole-Dipole"): rx = DC.Rx.Dipole_ky(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_ky(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_ky(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_ky(np.r_[M, 0.]) src = DC.Src.Pole([rx], np.r_[A, 0.]) survey = DC.Survey_ky([src]) problem = DC.Problem2D_CC(mesh, sigmaMap=mapping) problem.Solver = SolverLU problem.pair(survey) fieldObj = problem.fields(model) J = problem.Jtvec(model, np.array([1.]), f=fieldObj) return J
def model_fields(A, B, mtrue, mhalf, mair, mover, whichprimary='air'): 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_ky(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_ky([rx], np.r_[A, 0.], np.r_[B, 0.]) survey = DC.Survey_ky([src]) # survey = DC.Survey([src]) # survey_prim = DC.Survey([src]) survey_prim = DC.Survey_ky([src]) survey_air = DC.Survey_ky([src]) #problem = DC.Problem3D_CC(mesh, sigmaMap = mapping) problem = DC.Problem2D_CC(mesh, sigmaMap=mapping) # problem_prim = DC.Problem3D_CC(mesh, sigmaMap = mapping) problem_prim = DC.Problem2D_CC(mesh, sigmaMap=mapping) problem_air = DC.Problem2D_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