mirror of
https://github.com/wassname/simpeg.git
synced 2026-07-14 11:18:18 +08:00
126 KiB
126 KiB
In [20]:
# Test 1D solution of MT problem and compare to a analytic solution
%pylab inlinePopulating the interactive namespace from numpy and matplotlib
In [21]:
# import the simpegMT module
from simpegMT.Utils import MT1Danalytic, MT1Dsolutions
import SimPEG as simpeg
from scipy.constants import mu_0
def omega(freq):
"""Change frequency to angular frequency, omega"""
return 2.*np.pi*freqIn [22]:
# Set up the mesh.
freq = 10
z = 100.
hz = [(z,10,-1.5),(z,10),(z,10,1.5)]
M = simpeg.Mesh.TensorMesh([hz],'C')
sig = np.zeros(M.nC) + 1e-8
sig[M.vectorCCx<=300] = 0.01
In [23]:
M.vectorNxOut [23]:
array([-17499.51171875, -11733.0078125 , -7888.671875 , -5325.78125 ,
-3617.1875 , -2478.125 , -1718.75 , -1212.5 ,
-875. , -650. , -500. , -400. ,
-300. , -200. , -100. , 0. ,
100. , 200. , 300. , 400. ,
500. , 650. , 875. , 1212.5 ,
1718.75 , 2478.125 , 3617.1875 , 5325.78125 ,
7888.671875 , 11733.0078125 , 17499.51171875])In [24]:
# Get the fields
anaEd, anaEu, anaHd, anaHu = MT1Danalytic.getEHfields(M,sig,freq,M.vectorNx)
anaEtemp = (anaEd+anaEu)
anaHtemp = (anaHd+anaHu)
# Scale the solution
anaZ = (anaEtemp/anaHtemp)[np.argmin(M.vectorNx**2)]
anaEcor = anaEtemp/anaEtemp[-1] #.real/np.abs(anaEtemp[-1].real)+1j*anaEtemp.imag/np.abs(anaEtemp[-1].imag)
anaHcor = anaHtemp/anaEtemp[-1] # .real/np.abs(anaEtemp[-1].real)+1j*anaHtemp.imag/np.abs(anaEtemp[-1].imag)
solE = MT1Dsolutions.get1DEfields(M,sig,freq,sourceAmp=1).conj()
solH = -M.nodalGrad*solE/(1j*omega(freq)*mu_0)In [25]:
anaEtemp[-1]Out [25]:
(922807.04800415318-689021.35510797054j)
In [26]:
np.hstack((simpeg.mkvc(anaEcor,2),simpeg.mkvc(solE,2)))Out [26]:
array([[ 6.95763292e-07 +5.19497296e-07j,
6.95763292e-07 -5.19497296e-07j],
[ -1.40834457e-05 -2.93173032e-05j,
9.74760218e-06 -1.09092785e-05j],
[ 3.35815988e-04 +1.40732501e-04j,
1.74907169e-04 +1.24344756e-04j],
[ -7.70118008e-04 +1.65141317e-03j,
-5.21083562e-04 +1.34839517e-03j],
[ -5.32123445e-03 +3.24450003e-04j,
-4.87010903e-03 +6.63069113e-04j],
[ -8.64982593e-03 -6.64134560e-03j,
-8.61854919e-03 -6.03020882e-03j],
[ -7.46721859e-03 -1.59079740e-02j,
-7.68552978e-03 -1.53974787e-02j],
[ -2.91038457e-03 -2.39785146e-02j,
-3.16876824e-03 -2.35863583e-02j],
[ 2.72167021e-03 -2.97359468e-02j,
2.49400722e-03 -2.94018473e-02j],
[ 7.92975642e-03 -3.34680056e-02j,
7.73825040e-03 -3.31542272e-02j],
[ 1.21356998e-02 -3.57924928e-02j,
1.19706555e-02 -3.54839735e-02j],
[ 1.52903430e-02 -3.72269264e-02j,
1.51424717e-02 -3.69189921e-02j],
[ 1.87388388e-02 -3.85404390e-02j,
1.86057886e-02 -3.82344505e-02j],
[ 2.24915402e-02 -3.97057953e-02j,
2.23709926e-02 -3.94030035e-02j],
[ 2.65576291e-02 -4.06933593e-02j,
2.64473102e-02 -4.03949222e-02j],
[ 3.09448819e-02 -4.14710213e-02j,
3.08425733e-02 -4.11780213e-02j],
[ 3.56594159e-02 -4.20041369e-02j,
3.55629651e-02 -4.17175972e-02j],
[ 4.07054159e-02 -4.22554788e-02j,
4.06127458e-02 -4.19763792e-02j],
[ 4.60848403e-02 -4.21852042e-02j,
4.59939588e-02 -4.19144958e-02j],
[ 5.16310109e-02 -4.19401825e-02j,
5.15406437e-02 -4.16710354e-02j],
[ 5.71771819e-02 -4.16951603e-02j,
5.70873289e-02 -4.14275746e-02j],
[ 6.54964388e-02 -4.13276262e-02j,
6.54073573e-02 -4.10623825e-02j],
[ 7.79753255e-02 -4.07763228e-02j,
7.78874014e-02 -4.05145921e-02j],
[ 9.66936582e-02 -3.99493614e-02j,
9.66074704e-02 -3.96929008e-02j],
[ 1.24771163e-01 -3.87089021e-02j,
1.24687581e-01 -3.84603474e-02j],
[ 1.66887432e-01 -3.68481633e-02j,
1.66807761e-01 -3.66114701e-02j],
[ 2.30061859e-01 -3.40569049e-02j,
2.29988062e-01 -3.38380118e-02j],
[ 3.24823538e-01 -2.98695515e-02j,
3.24758579e-01 -2.96773825e-02j],
[ 4.66966101e-01 -2.35870424e-02j,
4.66914483e-01 -2.34350351e-02j],
[ 6.80179899e-01 -1.41584953e-02j,
6.80148567e-01 -1.40669735e-02j],
[ 1.00000000e+00 +0.00000000e+00j,
1.00000000e+00 -0.00000000e+00j]])In [27]:
plot(solE.real,M.vectorNx,'r*--',anaEcor.real,M.vectorNx,'b+:')
#axis([-.2,.2,-10000,10000])Out [27]:
[<matplotlib.lines.Line2D at 0x7feb9a686510>, <matplotlib.lines.Line2D at 0x7feb9a686790>]
In [28]:
plot((abs(solE.real)-abs(anaEcor.real))/abs(anaEcor.real),M.vectorNx,'b+:')Out [28]:
[<matplotlib.lines.Line2D at 0x7feb9981fad0>]
In [29]:
plot(solE.imag,M.vectorNx,'r*--',anaEcor.imag,M.vectorNx,'b+:')Out [29]:
[<matplotlib.lines.Line2D at 0x7feb997604d0>, <matplotlib.lines.Line2D at 0x7feb99760750>]
In [30]:
plot((abs(solE.imag)-abs(anaEcor.imag))/abs(anaEcor.imag),M.vectorNx,'b+:')Out [30]:
/home/gudni/anaconda/lib/python2.7/site-packages/IPython/kernel/__main__.py:1: RuntimeWarning: invalid value encountered in divide if __name__ == '__main__':
[<matplotlib.lines.Line2D at 0x7feb9970fad0>]
In [31]:
semilogx(abs(solE),M.vectorNx,'r*--',abs(anaEcor),M.vectorNx,'b+:')Out [31]:
[<matplotlib.lines.Line2D at 0x7feb9967c590>, <matplotlib.lines.Line2D at 0x7feb99638890>]
In [32]:
plot((abs(solE)-abs(anaEcor))/abs(anaEcor),M.vectorNx,'b+:')Out [32]:
[<matplotlib.lines.Line2D at 0x7feb993ce610>]
In [33]:
def appResPhs(freq,z):
app_res = ((1./(8e-7*np.pi**2))/freq)*np.abs(z)**2
app_phs = np.arctan2(z.imag,z.real)*(180/np.pi)
return app_res, app_phs
app_rAna, app_pAna = appResPhs(freq,anaZ)
app_rSol, app_pSol = appResPhs(freq,solE[np.argmin(M.hx**2)]/solH[np.argmin(M.hx**2)])
print app_rAna, app_pAna
print app_rSol, app_pSol100.0 44.999998407 91.3634893888 -137.014649098
In [34]:
M.nodalGrad.dot(solE).shapeOut [34]:
(30,)
In [35]:
M.nN
Out [35]:
31
In [36]:
plot(-solH.imag,M.vectorCCx,'r*--',anaHcor.imag,M.vectorNx,'b+:')
Out [36]:
[<matplotlib.lines.Line2D at 0x7feb99304550>, <matplotlib.lines.Line2D at 0x7feb993047d0>]
In [37]:
M.vectorCCxOut [37]:
array([-14616.25976562, -9810.83984375, -6607.2265625 , -4471.484375 ,
-3047.65625 , -2098.4375 , -1465.625 , -1043.75 ,
-762.5 , -575. , -450. , -350. ,
-250. , -150. , -50. , 50. ,
150. , 250. , 350. , 450. ,
575. , 762.5 , 1043.75 , 1465.625 ,
2098.4375 , 3047.65625 , 4471.484375 , 6607.2265625 ,
9810.83984375, 14616.25976562])In [ ]:
In [ ]:
In [ ]: