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.receivers.Dipole(Mx, Nx) if B == []: src = DC.sources.Pole([rx], np.r_[A, 0.0]) else: src = DC.sources.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 setUp(self): mesh = Mesh.TensorMesh([30, 30], x0=[-0.5, -1.0]) 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 model_fields(A, B, mtrue, mhalf, mair, mover, whichprimary="overburden"): re_run = (_cache["A"] != A or _cache["B"] != B or np.any(_cache["mtrue"] != mtrue) or np.any(_cache["mhalf"] != mhalf) or np.any(_cache["mair"] != mair) or np.any(_cache["mover"] != mover) or _cache["whichprimary"] != whichprimary) if re_run: idA, surfaceA = get_Surface(mtrue, A) idB, surfaceB = get_Surface(mtrue, B) if B == []: src = DC.sources.Pole([], np.r_[A, surfaceA]) else: src = DC.sources.Dipole([], np.r_[A, surfaceA], np.r_[B, surfaceB]) survey = DC.Survey([src]) # Create three simulations so the fields object is accurate sim_primary = DC.Simulation2DCellCentered(mesh, survey=survey, sigmaMap=mapping, solver=Pardiso) sim_total = DC.Simulation2DCellCentered(mesh, survey=survey, sigmaMap=mapping, solver=Pardiso) sim_air = DC.Simulation2DCellCentered(mesh, survey=survey, sigmaMap=mapping, solver=Pardiso) mesh.setCellGradBC("neumann") if whichprimary == "air": primary_field = sim_primary.fields(mair) elif whichprimary == "half": primary_field = sim_primary.fields(mhalf) elif whichprimary == "overburden": primary_field = sim_primary.fields(mover) air_field = sim_total.fields(mtrue) total_field = sim_air.fields(mair) _cache["A"] = A _cache["B"] = B _cache["mtrue"] = mtrue _cache["mhalf"] = mhalf _cache["mair"] = mair _cache["mover"] = mover _cache["whichprimary"] = whichprimary _cache["src"] = src _cache["primary_field"] = primary_field _cache["air_field"] = air_field _cache["total_field"] = total_field else: src = _cache["src"] primary_field = _cache["primary_field"] air_field = _cache["air_field"] total_field = _cache["total_field"] return src, primary_field, air_field, total_field
def getSensitivity(survey, A, B, M, N, model): if survey == "Dipole-Dipole": rx = DC.receivers.Dipole(np.r_[M, 0.0], np.r_[N, 0.0]) src = DC.sources.Dipole([rx], np.r_[A, 0.0], np.r_[B, 0.0]) elif survey == "Pole-Dipole": rx = DC.receivers.Dipole(np.r_[M, 0.0], np.r_[N, 0.0]) src = DC.sources.Pole([rx], np.r_[A, 0.0]) elif survey == "Dipole-Pole": rx = DC.receivers.Pole(np.r_[M, 0.0]) src = DC.sources.Dipole([rx], np.r_[A, 0.0], np.r_[B, 0.0]) elif survey == "Pole-Pole": rx = DC.receivers.Pole(np.r_[M, 0.0]) src = DC.sources.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 setUp(self): cs = 25.0 npad = 7 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 = discretize.TensorMesh([hx, hy, hz], x0="CCN") sigma = np.ones(mesh.nC) * 1e-2 x = mesh.vectorCCx[(mesh.vectorCCx > -155.0) & (mesh.vectorCCx < 155.0)] y = mesh.vectorCCy[(mesh.vectorCCy > -155.0) & (mesh.vectorCCy < 155.0)] Aloc = np.r_[-200.0, 0.0, 0.0] Bloc = np.r_[200.0, 0.0, 0.0] M = utils.ndgrid(x - 25.0, y, np.r_[0.0]) N = utils.ndgrid(x + 25.0, y, np.r_[0.0]) phiA = EM.analytics.DCAnalytic_Pole_Dipole(Aloc, [M, N], 1e-2, earth_type="halfspace") phiB = EM.analytics.DCAnalytic_Pole_Dipole(Bloc, [M, N], 1e-2, earth_type="halfspace") data_ana = phiA - phiB rx = DC.Rx.Dipole(M, N) src = DC.Src.Dipole([rx], Aloc, Bloc) survey = DC.Survey([src]) self.survey = survey self.mesh = mesh self.sigma = sigma self.data_ana = data_ana
def setUp(self): IO = dc.IO() ABMN = np.loadtxt(my_dir + "/resources/mixed_survey.loc") A = ABMN[:100, :2] B = ABMN[:100, 2:4] M = ABMN[:100, 4:6] N = ABMN[:100, 6:8] survey = IO.from_ambn_locations_to_survey(A, B, M, N, survey_type="dipole-dipole") # add some other receivers and sources to the mix electrode_locations = np.unique(np.r_[A, B, M, N], axis=0) rx_p = dc.receivers.Pole(electrode_locations[[2, 4, 6]]) rx_d = dc.receivers.Dipole(electrode_locations[[2, 4, 6]], electrode_locations[[3, 5, 9]]) tx_pd = dc.sources.Pole([rx_d], electrode_locations[0]) tx_pp = dc.sources.Pole([rx_p], electrode_locations[1]) tx_dp = dc.sources.Dipole([rx_p], electrode_locations[0], electrode_locations[1]) source_list = survey.source_list source_list.append(tx_pd) source_list.append(tx_pp) source_list.append(tx_dp) survey = dc.Survey(source_list) self.survey = survey # This survey is a mix of d-d, d-p, p-d, and p-p txs and rxs. # This mesh is meant only for testing mesh, inds = IO.set_mesh(dx=10, dz=40) self.sim1 = dc.Simulation2DNodal( survey=survey, mesh=mesh, solver=Pardiso, storeJ=False, sigmaMap=maps.IdentityMap(mesh), miniaturize=False, ) self.sim2 = dc.Simulation2DNodal( survey=survey, mesh=mesh, solver=Pardiso, storeJ=False, sigmaMap=maps.IdentityMap(mesh), miniaturize=True, ) self.model = np.ones(mesh.nC) self.f1 = self.sim1.fields(self.model) self.f2 = self.sim2.fields(self.model)
def model_soundings(h0, h1, rho0, rho1, rho2): hz = np.r_[h0, h1] rho = np.r_[rho0, rho1, rho2] srcList_w = [] srcList_s = [] AB2 = np.arange(4, 89, 3) + 0.5 for i, a in enumerate(AB2): a_loc = -a b_loc = a m_loc_wen = -a + (a * 2) // 3 n_loc_wen = -m_loc_wen m_loc_sch = -1.5 n_loc_sch = 1.5 rx_w = DC.Rx.Dipole(np.r_[m_loc_wen, 0, 0], np.r_[n_loc_wen, 0, 0]) rx_s = DC.Rx.Dipole(np.r_[m_loc_sch, 0, 0], np.r_[n_loc_sch, 0, 0]) locA = np.r_[a_loc, 0, 0] locB = np.r_[b_loc, 0, 0] src = DC.Src.Dipole([rx_w], locA, locB) srcList_w.append(src) src = DC.Src.Dipole([rx_s], locA, locB) srcList_s.append(src) m = np.r_[rho, hz] wires = maps.Wires(('rho', rho.size), ('t', rho.size - 1)) mapping_rho = maps.IdentityMap(nP=rho.size) * wires.rho mapping_t = maps.IdentityMap(nP=hz.size) * wires.t survey = DC.Survey(srcList_w) simulation = DC.Simulation1DLayers(rhoMap=mapping_rho, thicknessesMap=mapping_t, survey=survey, data_type='apparent_resistivity') data_w = simulation.make_synthetic_data(m) survey = DC.Survey(srcList_s) simulation = DC.Simulation1DLayers(rhoMap=mapping_rho, thicknessesMap=mapping_t, survey=survey, data_type='apparent_resistivity') data_s = simulation.make_synthetic_data(m) return data_w, data_s
def cylinder_fields(A, B, r, sigcyl, sighalf, xc=0.0, zc=-20.0): re_run = ( _cache["A"] != A or _cache["B"] != B or _cache["sigcyl"] != sigcyl or _cache["sighalf"] != sighalf or _cache["xc"] != xc or _cache["zc"] != zc or _cache["r"] != r ) if re_run: 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 if B == []: src = DC.sources.Pole([], np.r_[A, 0.0]) else: src = DC.sources.Dipole([], np.r_[A, 0.0], np.r_[B, 0.0]) survey = DC.Survey([src]) # make two simulations for the seperate field objects sim_primary = DC.Simulation2DCellCentered( mesh, survey=survey, sigmaMap=sigmaMap, solver=Pardiso, bc_type='Dirichlet' ) sim_total = DC.Simulation2DCellCentered( mesh, survey=survey, sigmaMap=sigmaMap, solver=Pardiso, bc_type='Dirichlet' ) primary_field = sim_primary.fields(mhalf) total_field = sim_total.fields(mtrue) _cache["A"] = A _cache["B"] = B _cache["sigcyl"] = sigcyl _cache["sighalf"] = sighalf _cache["xc"] = xc _cache["zc"] = zc _cache["r"] = r _cache["mtrue"] = mtrue _cache["mhalf"] = mhalf _cache["src"] = src _cache["total_field"] = total_field _cache["primary_field"] = primary_field else: mtrue = _cache["mtrue"] mhalf = _cache["mhalf"] src = _cache["src"] total_field = _cache["total_field"] primary_field = _cache["primary_field"] return mtrue, mhalf, src, total_field, primary_field
def getSensitivity(survey, A, B, M, N, model): src_type, rx_type = survey.split("-") if rx_type == "Pole": rx = DC.receivers.Pole(np.r_[M, 0.0]) else: rx = DC.receivers.Dipole(np.r_[M, 0.0], np.r_[N, 0.0]) if src_type == "Pole": src = DC.sources.Pole([rx], np.r_[A, 0.0]) else: src = DC.sources.Dipole([rx], np.r_[A, 0.0], np.r_[B, 0.0]) Src = DC.Survey([src]) sim = DC.Simulation2DCellCentered( mesh, survey=Src, sigmaMap=mapping, solver=Pardiso ) J = sim.getJ(model) return J[0]
B_location = np.r_[1.5 * a, 0.0, 0.0] # MN electrode locations for receivers. Each is an (N, 3) numpy array M_location = np.r_[-0.5 * a, 0.0, 0.0] N_location = np.r_[0.5 * a, 0.0, 0.0] # Create receivers list. Define as pole or dipole. receiver_list = dc.receivers.Dipole(M_location, N_location) receiver_list = [receiver_list] # Define the source properties and associated receivers source_list.append(dc.sources.Dipole(receiver_list, A_location, B_location)) # Define survey survey = dc.Survey(source_list) ############################################### # Defining a 1D Layered Earth Model # --------------------------------- # # Here, we define the layer thicknesses and electrical resistivities for our # 1D simulation. If we have N layers, we define N electrical resistivity # values and N-1 layer thicknesses. The lowest layer is assumed to extend to # infinity. # # Define layer thicknesses. layer_thicknesses = np.r_[100.0, 100.0] # Define layer resistivities.
def setUp(self): aSpacing = 2.5 nElecs = 5 surveySize = nElecs * aSpacing - aSpacing cs = surveySize / nElecs / 4 mesh = discretize.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", ) survey_end_points = np.array([[-surveySize / 2, 0, 0], [surveySize / 2, 0, 0]]) survey = gen_DCIPsurvey(survey_end_points, "dipole-dipole", aSpacing, aSpacing, nElecs, dim=2) A = survey.locations_a B = survey.locations_b M = survey.locations_m N = survey.locations_n # add some other receivers and sources to the mix electrode_locations = np.unique(np.r_[A, B, M, N], axis=0) rx_p = dc.receivers.Pole(electrode_locations[[2]]) rx_d = dc.receivers.Dipole(electrode_locations[[2]], electrode_locations[[3]]) tx_pd = dc.sources.Pole([rx_d], electrode_locations[0]) tx_pp = dc.sources.Pole([rx_p], electrode_locations[0]) tx_dp = dc.sources.Dipole([rx_p], electrode_locations[0], electrode_locations[1]) source_list = survey.source_list source_list.append(tx_pd) source_list.append(tx_pp) source_list.append(tx_dp) survey = dc.Survey(source_list) self.survey = survey # This survey is a mix of d-d, d-p, p-d, and p-p txs and rxs. self.sim1 = dc.Simulation3DNodal( survey=survey, mesh=mesh, solver=Pardiso, storeJ=False, sigmaMap=maps.IdentityMap(mesh), miniaturize=False, ) self.sim2 = dc.Simulation3DNodal( survey=survey, mesh=mesh, solver=Pardiso, storeJ=False, sigmaMap=maps.IdentityMap(mesh), miniaturize=True, ) self.model = np.ones(mesh.nC) self.f1 = self.sim1.fields(self.model) self.f2 = self.sim2.fields(self.model)
n=8) # Line 3 xmin, xmax = -15.0, 15.0 ymin, ymax = -5.0, -5.0 zmin, zmax = 0, 0 endl = np.array([[xmin, ymin, zmin], [xmax, ymax, zmax]]) survey3 = DCutils.gen_DCIPsurvey(endl, "dipole-dipole", dim=mesh.dim, a=3, b=3, n=8) # Concatenate lines survey = DC.Survey(survey1.source_list + survey2.source_list + survey3.source_list) # Setup Problem with exponential mapping and Active cells only in the core mesh expmap = maps.ExpMap(mesh) mapactive = maps.InjectActiveCells(mesh=mesh, indActive=actind, valInactive=-5.0) mapping = expmap * mapactive problem = DC.Simulation3DCellCentered(mesh, survey=survey, sigmaMap=mapping, solver=Solver, bc_type="Neumann") data = problem.make_synthetic_data(mtrue[actind], relative_error=0.05,
def model_fields(A, B, zcLayer, dzLayer, xc, zc, r, sigLayer, sigTarget, sigHalf): re_run = ( _cache["A"] != A or _cache["B"] != B or _cache["zcLayer"] != zcLayer or _cache["dzLayer"] != dzLayer or _cache["xc"] != xc or _cache["zc"] != zc or _cache["r"] != r or _cache["sigLayer"] != sigLayer or _cache["sigTarget"] != sigTarget or _cache["sigHalf"] != sigHalf ) if re_run: # Create halfspace model halfspaceMod = sigHalf * np.ones([mesh.nC]) mhalf = np.log(halfspaceMod) # Add layer to model LayerMod = addLayer2Mod(zcLayer, dzLayer, halfspaceMod, sigLayer) # Add plate or cylinder fullMod = addCylinder2Mod(xc, zc, r, LayerMod, sigTarget) mtrue = np.log(fullMod) if B == []: src = DC.sources.Pole([], np.r_[A, 0.0]) else: src = DC.sources.Dipole([], np.r_[A, 0.0], np.r_[B, 0.0]) survey = DC.Survey([src]) sim = DC.Simulation2DCellCentered( mesh, survey=survey, sigmaMap=mapping, solver=Pardiso ) total_field = sim.fields(mtrue) sim_prim = DC.Simulation2DCellCentered( mesh, survey=survey, sigmaMap=mapping, solver=Pardiso ) primary_field = sim_prim.fields(mhalf) _cache["A"] = A _cache["B"] = B _cache["zcLayer"] = zcLayer _cache["dzLayer"] = dzLayer _cache["xc"] = xc _cache["zc"] = zc _cache["r"] = r _cache["sigLayer"] = sigLayer _cache["sigTarget"] = sigTarget _cache["sigHalf"] = sigHalf _cache["mtrue"] = mtrue _cache["mhalf"] = mhalf _cache["src"] = src _cache["total_field"] = total_field _cache["primary_field"] = primary_field else: mtrue = _cache["mtrue"] mhalf = _cache["mhalf"] src = _cache["src"] total_field = _cache["total_field"] primary_field = _cache["primary_field"] return mtrue, mhalf, src, primary_field, total_field
def DC2Dsurvey(flag="PolePole"): """ Function that define a surface DC survey :param str flag: Survey Type 'PoleDipole', 'DipoleDipole', 'DipolePole', 'PolePole' """ if flag == "PoleDipole": ntx, nmax = xr.size - 2, 8 elif flag == "DipolePole": ntx, nmax = xr.size - 2, 8 elif flag == "DipoleDipole": ntx, nmax = xr.size - 3, 8 elif flag == "PolePole": ntx, nmax = xr.size - 2, 8 else: raise Exception("Not Implemented") xzlocs = getPseudoLocs(xr, ntx, nmax, flag) txList = [] zloc = -2.5 for i in range(ntx): if flag == "PoleDipole": A = np.r_[xr[i], zloc] B = np.r_[mesh.vectorCCx.min(), zloc] if i < ntx - nmax + 1: M = np.c_[xr[i + 1:i + 1 + nmax], np.ones(nmax) * zloc] N = np.c_[xr[i + 2:i + 2 + nmax], np.ones(nmax) * zloc] else: M = np.c_[xr[i + 1:ntx + 1], np.ones(ntx - i) * zloc] N = np.c_[xr[i + 2:i + 2 + nmax], np.ones(ntx - i) * zloc] elif flag == "DipolePole": A = np.r_[xr[i], zloc] B = np.r_[xr[i + 1], zloc] if i < ntx - nmax + 1: M = np.c_[xr[i + 2:i + 2 + nmax], np.ones(nmax) * zloc] N = np.c_[np.ones(nmax) * mesh.vectorCCx.max(), np.ones(nmax) * zloc] else: M = np.c_[xr[i + 2:ntx + 2], np.ones(ntx - i) * zloc] N = np.c_[np.ones(ntx - i) * mesh.vectorCCx.max(), np.ones(ntx - i) * zloc] elif flag == "DipoleDipole": A = np.r_[xr[i], zloc] B = np.r_[xr[i + 1], zloc] if i < ntx - nmax: M = np.c_[xr[i + 2:i + 2 + nmax], np.ones(len(xr[i + 2:i + 2 + nmax])) * zloc, ] N = np.c_[xr[i + 3:i + 3 + nmax], np.ones(len(xr[i + 3:i + 3 + nmax])) * zloc, ] else: M = np.c_[xr[i + 2:len(xr) - 1], np.ones(len(xr[i + 2:len(xr) - 1])) * zloc, ] N = np.c_[xr[i + 3:len(xr)], np.ones(len(xr[i + 3:len(xr)])) * zloc] elif flag == "PolePole": A = np.r_[xr[i], zloc] B = np.r_[mesh.vectorCCx.min(), zloc] if i < ntx - nmax + 1: M = np.c_[xr[i + 2:i + 2 + nmax], np.ones(nmax) * zloc] N = np.c_[np.ones(nmax) * mesh.vectorCCx.max(), np.ones(nmax) * zloc] else: M = np.c_[xr[i + 2:ntx + 2], np.ones(ntx - i) * zloc] N = np.c_[np.ones(ntx - i) * mesh.vectorCCx.max(), np.ones(ntx - i) * zloc] rx = DC.receivers.Dipole(M, N) src = DC.sources.Dipole([rx], A, B) txList.append(src) survey = DC.Survey(txList) simulation = DC.Simulation2DCellCentered(mesh, survey=survey, sigmaMap=mapping, solver=Pardiso) sigblk, sighalf, siglayer = 2e-2, 2e-3, 1e-3 xc, yc, r, zh = -15, -8, 4, -5 mtrue = np.r_[np.log(sighalf), np.log(siglayer), np.log(sigblk), xc, yc, r, zh] dtrue = simulation.dpred(mtrue) perc = 0.0001 floor = np.linalg.norm(dtrue) * 1e-8 np.random.seed([1]) uncert = np.random.randn(survey.nD) * perc + floor dobs = dtrue + uncert return dobs, uncert, simulation, xzlocs
def DC2Dsimulation(mtrue, flag="PoleDipole", nmax=8): if flag == "PoleDipole": ntx = xr.size - 2 elif flag == "DipolePole": ntx = xr.size - 2 elif flag == "DipoleDipole": ntx = xr.size - 3 else: raise Exception("Not Implemented") xzlocs = getPseudoLocs(xr, ntx, nmax, flag) txList = [] zloc = -cs / 2.0 for i in range(ntx): if flag == "PoleDipole": A = np.r_[xr[i], zloc] B = np.r_[mesh.vectorCCx.min(), zloc] if i < ntx - nmax + 1: Mx = xr[i + 1:i + 1 + nmax] _, Mz = get_Surface(mtrue, Mx) Nx = xr[i + 2:i + 2 + nmax] _, Nz = get_Surface(mtrue, Nx) M = np.c_[Mx, Mz] N = np.c_[Nx, Nz] else: Mx = xr[i + 1:ntx + 1] _, Mz = get_Surface(mtrue, Mx) Nx = xr[i + 2:i + 2 + nmax] _, Nz = get_Surface(mtrue, Nx) M = np.c_[Mx, Mz] N = np.c_[Nx, Nz] elif flag == "DipolePole": A = np.r_[xr[i], zloc] B = np.r_[xr[i + 1], zloc] if i < ntx - nmax + 1: Mx = xr[i + 2:i + 2 + nmax] _, Mz = get_Surface(mtrue, Mx) Nx = np.ones(nmax) * mesh.vectorCCx.max() _, Nz = get_Surface(mtrue, Nx) M = np.c_[Mx, Mz] N = np.c_[Nx, Nz] else: Mx = xr[i + 2:ntx + 2] _, Mz = get_Surface(mtrue, Mx) Nx = np.ones(ntx - i) * mesh.vectorCCx.max() _, Nz = get_Surface(mtrue, Nx) M = np.c_[Mx, Mz] N = np.c_[Nx, Nz] elif flag == "DipoleDipole": A = np.r_[xr[i], zloc] B = np.r_[xr[i + 1], zloc] if i < ntx - nmax: Mx = xr[i + 2:i + 2 + nmax] _, Mz = get_Surface(mtrue, Mx) Nx = xr[i + 3:i + 3 + nmax] _, Nz = get_Surface(mtrue, Nx) M = np.c_[Mx, Mz] N = np.c_[Nx, Nz] else: Mx = xr[i + 2:len(xr) - 1] _, Mz = get_Surface(mtrue, Mx) Nx = xr[i + 3:len(xr)] _, Nz = get_Surface(mtrue, Nx) M = np.c_[Mx, Mz] N = np.c_[Nx, Nz] rx = DC.receivers.Dipole(M, N) src = DC.sources.Dipole([rx], A, B) txList.append(src) survey = DC.Survey(txList) simulation = DC.Simulation2DCellCentered(mesh, sigmaMap=mapping, survey=survey, solver=Pardiso) return simulation, xzlocs
cs = 25.0 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 = discretize.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.0, ytemp, np.r_[0.0]) xyz_rxN = utils.ndgrid(xtemp + 10.0, ytemp, np.r_[0.0]) xyz_rxM = utils.ndgrid(xtemp, ytemp, np.r_[0.0]) 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]) sim = DC.Simulation3DCellCentered(mesh, survey=survey, solver=Solver, sigma=sigma, bc_type="Neumann") data = sim.dpred() def DChalf(srclocP, srclocN, rxloc, sigma, I=1.0): 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.0 * np.pi) * (1 / rP - 1 / rN)
def model_fields(A, B, zcLayer, dzLayer, xc, zc, r, sigLayer, sigTarget, sigHalf): re_run = (_cache["A"] != A or _cache["B"] != B or _cache["zcLayer"] != zcLayer or _cache["dzLayer"] != dzLayer or _cache["xc"] != xc or _cache["zc"] != zc or _cache["r"] != r or _cache["sigLayer"] != sigLayer or _cache["sigTarget"] != sigTarget or _cache["sigHalf"] != sigHalf) if re_run: # Create halfspace model mhalf = sigHalf * np.ones([mesh.nC]) # Add layer to model mLayer = addLayer2Mod(zcLayer, dzLayer, mhalf, sigLayer) # Add plate or cylinder mtrue = addCylinder2Mod(xc, zc, r, mLayer, sigTarget) Mx = np.empty(shape=(0, 2)) Nx = np.empty(shape=(0, 2)) rx = DC.receivers.Dipole(Mx, Nx) if B == []: src = DC.sources.Pole([rx], np.r_[A, 0.0]) else: src = DC.sources.Dipole([rx], np.r_[A, 0.0], np.r_[B, 0.0]) survey = DC.Survey([src]) problem = DC.Simulation3DCellCentered(mesh, sigmaMap=sigmaMap, solver=Pardiso, survey=survey) problem_prim = DC.Simulation3DCellCentered(mesh, sigmaMap=sigmaMap, solver=Pardiso, survey=survey) primary_field = problem_prim.fields(mhalf) total_field = problem.fields(mtrue) _cache["A"] = A _cache["B"] = B _cache["zcLayer"] = zcLayer _cache["dzLayer"] = dzLayer _cache["xc"] = xc _cache["zc"] = zc _cache["r"] = r _cache["sigLayer"] = sigLayer _cache["sigTarget"] = sigTarget _cache["sigHalf"] = sigHalf _cache["mtrue"] = mtrue _cache["mhalf"] = mhalf _cache["src"] = src _cache["total_field"] = total_field _cache["primary_field"] = primary_field else: mtrue = _cache["mtrue"] mhalf = _cache["mhalf"] src = _cache["src"] total_field = _cache["total_field"] primary_field = _cache["primary_field"] return mtrue, mhalf, src, primary_field, total_field