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 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") sighalf = 1e-2 sigma = np.ones(mesh.nC) * sighalf 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)]] data_anal = EM.Analytics.DCAnalytic_Pole_Dipole(np.r_[A0loc, 0.], rxloc, sighalf, earth_type="halfspace") rx = DC.Rx.Dipole_ky(M, N) 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): # 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): 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 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(-200, 200., 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.] B0loc = np.r_[-130, 0.] B1loc = np.r_[-110, 0.] rx = DC.Rx.Dipole_ky(M, N) src0 = DC.Src.Dipole([rx], A0loc, B0loc) src1 = DC.Src.Dipole([rx], A1loc, B1loc) src0_ip = DC.Src.Dipole([rx], A0loc, B0loc) src1_ip = DC.Src.Dipole([rx], A1loc, B1loc) srcLists = [src0, src1] srcLists_ip = [src0_ip, src1_ip] surveyDC = DC.Survey_ky([src0, src1]) sigmaInf = np.ones(mesh.nC) * 1. blkind = Utils.ModelBuilder.getIndicesSphere(np.r_[0, -150], 40, mesh.gridCC) eta = np.zeros(mesh.nC) eta[blkind] = 0.1 sigma0 = sigmaInf * (1. - eta) self.surveyDC = surveyDC self.mesh = mesh self.sigmaInf = sigmaInf self.sigma0 = sigma0 self.srcLists = srcLists self.srcLists_ip = srcLists_ip self.eta = eta
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 gen_DCIPsurvey(endl, survey_type, a, b, n, dim=3, d2flag='2.5D'): """ Load in endpoints and survey specifications to generate Tx, Rx location stations. Assumes flat topo for now... Input: :param numpy.ndarray endl: input endpoints [x1, y1, z1, x2, y2, z2] :param discretize.BaseMesh mesh: discretize mesh object :param str survey_type: 'dipole-dipole' | 'pole-dipole' | 'dipole-pole' | 'pole-pole' | 'gradient' :param int a: pole seperation :param int b: dipole separation :param int n: number of rx dipoles per tx :param str d2flag: choose for 2D mesh between a '2D' or a '2.5D' survey Output: :return SimPEG.EM.Static.DC.SurveyDC.Survey dc_survey: DC survey object """ def xy_2_r(x1, x2, y1, y2): r = np.sqrt(np.sum((x2 - x1)**2. + (y2 - y1)**2.)) return r # Evenly distribute electrodes and put on surface # Mesure survey length and direction dl_len = xy_2_r(endl[0, 0], endl[1, 0], endl[0, 1], endl[1, 1]) dl_x = (endl[1, 0] - endl[0, 0]) / dl_len dl_y = (endl[1, 1] - endl[0, 1]) / dl_len nstn = int(np.floor(dl_len / a)) # Compute discrete pole location along line stn_x = endl[0, 0] + np.array(range(int(nstn))) * dl_x * a stn_y = endl[0, 1] + np.array(range(int(nstn))) * dl_y * a if dim == 2: ztop = np.linspace(endl[0, 1], endl[0, 1], nstn) # Create line of P1 locations M = np.c_[stn_x, ztop] # Create line of P2 locations N = np.c_[stn_x + a * dl_x, ztop] elif dim == 3: stn_z = np.linspace(endl[0, 2], endl[0, 2], nstn) # Create line of P1 locations M = np.c_[stn_x, stn_y, stn_z] # Create line of P2 locations N = np.c_[stn_x + a * dl_x, stn_y + a * dl_y, stn_z] # Build list of Tx-Rx locations depending on survey type # Dipole-dipole: Moving tx with [a] spacing -> [AB a MN1 a MN2 ... a MNn] # Pole-dipole: Moving pole on one end -> [A a MN1 a MN2 ... MNn a B] SrcList = [] if survey_type != 'gradient': for ii in range(0, int(nstn) - 1): if survey_type == 'dipole-dipole' or survey_type == 'dipole-pole': tx = np.c_[M[ii, :], N[ii, :]] # Current elctrode separation AB = xy_2_r(tx[0, 1], endl[1, 0], tx[1, 1], endl[1, 1]) elif survey_type == 'pole-dipole' or survey_type == 'pole-pole': tx = np.r_[M[ii, :]] # Current elctrode separation AB = xy_2_r(tx[0], endl[1, 0], tx[1], endl[1, 1]) else: raise Exception( """survey_type must be 'dipole-dipole' | 'pole-dipole' | 'dipole-pole' | 'pole-pole'""" " not {}".format(survey_type)) # Rx.append(np.c_[M[ii+1:indx, :], N[ii+1:indx, :]]) # Number of receivers to fit nstn = int(np.min([np.floor((AB - b) / a), n])) # Check if there is enough space, else break the loop if nstn <= 0: continue # Compute discrete pole location along line stn_x = N[ii, 0] + dl_x * b + np.array(range(int(nstn))) * dl_x * a stn_y = N[ii, 1] + dl_y * b + np.array(range(int(nstn))) * dl_y * a # Create receiver poles if dim == 3: stn_z = np.linspace(endl[0, 2], endl[0, 2], nstn) # Create line of P1 locations P1 = np.c_[stn_x, stn_y, stn_z] # Create line of P2 locations P2 = np.c_[stn_x + a * dl_x, stn_y + a * dl_y, stn_z] if survey_type == 'dipole-dipole' or survey_type == 'pole-dipole': rxClass = DC.Rx.Dipole(P1, P2) elif survey_type == 'dipole-pole' or survey_type == 'pole-pole': rxClass = DC.Rx.Pole(P1) elif dim == 2: ztop = np.linspace(endl[0, 1], endl[0, 1], nstn) # Create line of P1 locations P1 = np.c_[stn_x, np.ones(nstn).T * ztop] # Create line of P2 locations P2 = np.c_[stn_x + a * dl_x, np.ones(nstn).T * ztop] if survey_type == 'dipole-dipole' or survey_type == 'pole-dipole': if d2flag == '2.5D': rxClass = DC.Rx.Dipole_ky(P1, P2) elif d2flag == '2D': rxClass = DC.Rx.Dipole(P1, P2) elif survey_type == 'dipole-pole' or survey_type == 'pole-pole': if d2flag == '2.5D': rxClass = DC.Rx.Pole_ky(P1) elif d2flag == '2D': rxClass = DC.Rx.Pole(P1) if survey_type == 'dipole-dipole' or survey_type == 'dipole-pole': srcClass = DC.Src.Dipole([rxClass], M[ii, :], N[ii, :]) elif survey_type == 'pole-dipole' or survey_type == 'pole-pole': srcClass = DC.Src.Pole([rxClass], M[ii, :]) SrcList.append(srcClass) elif survey_type == 'gradient': # Gradient survey takes the "b" parameter to define the limits of a # square survey grid. The pole seperation within the receiver grid is # define the "a" parameter. # Get the edge limit of survey area min_x = endl[0, 0] + dl_x * b min_y = endl[0, 1] + dl_y * b max_x = endl[1, 0] - dl_x * b max_y = endl[1, 1] - dl_y * b # Define the size of the survey grid (square for now) box_l = np.sqrt((min_x - max_x)**2. + (min_y - max_y)**2.) box_w = box_l / 2. nstn = int(np.floor(box_l / a)) # Compute discrete pole location along line stn_x = min_x + np.array(range(int(nstn))) * dl_x * a stn_y = min_y + np.array(range(int(nstn))) * dl_y * a # Define number of cross lines nlin = int(np.floor(box_w / a)) lind = range(-nlin, nlin + 1) npoles = int(nstn * len(lind)) rx = np.zeros([npoles, 6]) for ii in range(len(lind)): # Move station location to current survey line This is a # perpendicular move then line survey orientation, hence the y, x # switch lxx = stn_x - lind[ii] * a * dl_y lyy = stn_y + lind[ii] * a * dl_x M = np.c_[lxx, lyy, np.ones(nstn).T * ztop] N = np.c_[lxx + a * dl_x, lyy + a * dl_y, np.ones(nstn).T * ztop] rx[(ii * nstn):((ii + 1) * nstn), :] = np.c_[M, N] if mesh.dim == 3: rxClass = DC.Rx.Dipole(rx[:, :3], rx[:, 3:]) elif mesh.dim == 2: M = M[:, [0, 2]] N = N[:, [0, 2]] if d2flag == '2.5D': rxClass = DC.Rx.Dipole_ky(rx[:, [0, 2]], rx[:, [3, 5]]) elif d2flag == '2D': rxClass = DC.Rx.Dipole(rx[:, [0, 2]], rx[:, [3, 5]]) srcClass = DC.Src.Dipole([rxClass], (endl[0, :]), (endl[1, :])) SrcList.append(srcClass) else: raise Exception( """survey_type must be either 'pole-dipole', 'dipole-dipole', 'dipole-pole','pole-pole' or 'gradient'""" " not {}".format(survey_type)) if (d2flag == '2.5D') and (dim == 2): survey = DC.Survey_ky(SrcList) else: survey = DC.Survey(SrcList) return survey
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
problem = DC.Problem2D_N(mesh2d, sigmaMap=mapping) problem.Solver = PardisoSolver srcLists2D = [] for iSrc in range(survey2D.nSrc): src = survey2D.srcList[iSrc] locsM = np.c_[src.rxList[0].locs[0][:, 0], src.rxList[0].locs[0][:, 2] - dx_in / 2.] locsN = np.c_[src.rxList[0].locs[1][:, 0], src.rxList[0].locs[1][:, 2] - dx_in / 2.] rx = DC.Rx.Dipole_ky(locsM, locsN) locA = np.r_[src.loc[0][0], src.loc[0][2] - dx_in / 2.] locB = np.r_[src.loc[1][0], src.loc[1][2] - dx_in / 2.] src = DC.Src.Dipole([rx], locA, locB) srcLists2D.append(src) DCsurvey2D = DC.Survey_ky(srcLists2D) DCsurvey2D.dobs = survey2D.dobs problem.pair(DCsurvey2D) pred = DCsurvey2D.dpred(m0) dmisfit = DataMisfit.l2_DataMisfit(DCsurvey2D) actind = np.ones(mesh2d.nC, dtype=bool) # Ignoring points where we have poor accuracy dmisfit.Wd = 1. / survey2D.std regmap = Maps.IdentityMap(nP=mesh2d.nC) reg = Regularization.Simple(mesh2d, indActive=actind, mapping=regmap) #reg.mref = np.log10(ref_mod) mesh1D, topoCC = EM.Static.Utils.gettopoCC(mesh2d, ~actind)