mirror of
https://github.com/wassname/simpeg.git
synced 2026-07-15 11:26:09 +08:00
177 KiB
177 KiB
In [1]:
from SimPEG import *
from simpegPF.MagAnalytics import spheremodel, MagSphereAnaFun, CongruousMagBC, MagSphereAnaFunA
from simpegPF.Magnetics import MagneticsDiffSecondary, MagneticsDiffSecondaryInv, BaseMag
%pylab inlinePopulating the interactive namespace from numpy and matplotlib
WARNING: pylab import has clobbered these variables: ['linalg'] `%matplotlib` prevents importing * from pylab and numpy
In [2]:
import matplotlib
matplotlib.rcParams.update({'font.size': 16, 'text.usetex': True})In [3]:
cs = 12.5
ncx, ncy, ncz, npad = 41, 41, 40, 5
hx = [(cs,npad,-1.4), (cs,ncx), (cs,npad,1.4)]
hy = [(cs,npad,-1.4), (cs,ncy), (cs,npad,1.4)]
hz = [(cs,npad,-1.4), (cs,ncz), (cs,npad,1.4)]
mesh = Mesh.TensorMesh([hx, hy, hz], 'CCC')
fig, ax = plt.subplots(1,2, figsize=(12, 5))
dat0 = mesh.plotSlice(np.zeros(mesh.nC), grid=True, ax=ax[0]); ax[0].set_title('XY plane')
dat1 = mesh.plotSlice(np.zeros(mesh.nC), grid=True, normal='X', ax=ax[1]); ax[1].set_title('YZ plane')Out [3]:
<matplotlib.text.Text at 0x13415908>
In [4]:
from scipy.constants import mu_0
mu0 = 4*np.pi*1e-7
chibkg = 0. # Background susceptibility
chiblk = 0.01 # Susceptibility for a sphere
chi = np.ones(mesh.nC)*chibkgIn [5]:
sph_ind = spheremodel(mesh, 0, 0, -100, 80) # A sphere is located at (0, 0, 0) and radius of the sphere is 100 m
chi[sph_ind] = chiblk # Assign susceptibility value for the sphere
mu = (1.+chi)*mu0In [6]:
fig, ax = plt.subplots(1,2, figsize=(12, 7))
indz = int(np.argmin(abs(mesh.vectorCCz-(-100.)))); indx = int(np.argmin(abs(mesh.vectorCCx-0.)))
dat0 = mesh.plotSlice(chi, grid=True, ind=indz, ax=ax[0]); ax[0].set_title(('XY plane at z=%5.2f')%(mesh.vectorCCz[indz]))
dat1 = mesh.plotSlice(chi, grid=True, normal='X', ind=indx, ax=ax[1]); ax[1].set_title(('YZ plane at x=%5.2f')%(mesh.vectorCCx[indx]))
cb0 = plt.colorbar(dat0[0], orientation='horizontal', ax=ax[0], ticks = linspace(0, 0.01, 5));
cb1 = plt.colorbar(dat1[0], orientation='horizontal', ax=ax[1], ticks = linspace(0, 0.01, 5));
cb0.set_label("Suceptibility")
cb1.set_label("Suceptibility")In [7]:
xr = np.linspace(-200, 200, 21)
yr = np.linspace(-200, 200, 21)
X, Y = np.meshgrid(xr, yr)
Z = np.ones((size(xr), size(yr)))*30.In [8]:
fig, ax = plt.subplots(1,1, figsize=(5, 5))
indz = int(np.argmin(abs(mesh.vectorCCz-(0.))));
dat0 = mesh.plotSlice(chi, grid=True, ind=indz, ax=ax); ax.set_title(('XY plane at z=%5.2f')%(mesh.vectorCCz[indz]))
ax.plot(X.flatten(), Y.flatten(), 'w.', ms=5)Out [8]:
[<matplotlib.lines.Line2D at 0x17706b70>]
In [9]:
Bxra, Byra, Bzra = MagSphereAnaFunA(X, Y, Z, 80., 0., 0., -100, chiblk, np.array([0., 0., 1.]), flag)
Bxra = np.reshape(Bxra, (size(xr), size(yr)), order='F')
Byra = np.reshape(Byra, (size(xr), size(yr)), order='F')
Bzra = np.reshape(Bzra, (size(xr), size(yr)), order='F')In [10]:
fig, ax = plt.subplots(1,3, figsize=(18, 4))
dat0=ax[0].contourf(X, Y, Bxra, 30); ax[0].set_title('Bx'); cb0 = plt.colorbar(dat0, ax=ax[0])
dat1=ax[1].contourf(X, Y, Byra, 30); ax[1].set_title('By'); cb1 = plt.colorbar(dat0, ax=ax[1])
dat2=ax[2].contourf(X, Y, Bzra, 30); ax[2].set_title('Bz'); cb2 = plt.colorbar(dat0, ax=ax[2])
for i in range(3):
ax[i].plot(X.flatten(), Y.flatten(), 'k.', ms=3)In [11]:
survey = BaseMag.BaseMagSurvey() # survey class for mag problem
Inc = 90.
Dec = 0.
Btot = 1
survey.setBackgroundField(Inc, Dec, Btot) # set inclination, declination, and strength of magnetic field
rxLoc = np.c_[Utils.mkvc(X), Utils.mkvc(Y), Utils.mkvc(Z)]
survey.rxLoc = rxLoc # set receiver locationsIn [12]:
prob = MagneticsDiffSecondary(mesh)
prob.pair(survey)In [13]:
data = survey.dpred(mu)In [15]:
fig, ax = plt.subplots(1,3, figsize=(18, 4))
vmin = Bzra.min()
vmax = Bzra.max()
residual = data.reshape((xr.size, yr.size), order='F')-Bzra
dat0=ax[0].contourf(X, Y, Bzra, 30, vmin=vmin, vmax=vmax)
dat1=ax[1].contourf(X, Y, data.reshape((xr.size, yr.size), order='F'), 30, vmin=vmin, vmax=vmax)
dat2=ax[2].contourf(X, Y, residual, 30)
cb0 = plt.colorbar(dat0, ax=ax[0])
cb1 = plt.colorbar(dat0, ax=ax[1])
cb2 = plt.colorbar(dat2, ax=ax[2])
ax[0].set_title('Bz (analytic)')
ax[1].set_title('Bz (simpegPF)')
ax[2].set_title('Residual')Out [15]:
<matplotlib.text.Text at 0x13826278>
