mirror of
https://github.com/wassname/simpeg.git
synced 2026-07-08 05:38:58 +08:00
removedFWI example to merge into master.
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -1,101 +0,0 @@
|
||||
try:
|
||||
import sys
|
||||
sys.path.append('/Users/haber/dropbox/simpegMaster/')
|
||||
except Exception, e:
|
||||
pass
|
||||
|
||||
import SimPEG
|
||||
import scipy.sparse as sp
|
||||
import numpy as np
|
||||
import SimPEG.utils as utils
|
||||
import matplotlib.pylab as plt
|
||||
from SimPEG.mesh import TensorMesh
|
||||
|
||||
|
||||
def HelmholtzSol(model,mesh,w,mbc,q,P):
|
||||
|
||||
n1 = mesh.nCx; n2 = mesh.nCy;
|
||||
h1 = mesh.hx; h2 = mesh.hy;
|
||||
|
||||
k = np.sqrt(w**2 * mbc)
|
||||
|
||||
# D1 = utils.sdiag(1./h1) * utils.ddx(mesh.nCx)
|
||||
# D2 = utils.sdiag(1./h2) * utils.ddx(mesh.nCy)
|
||||
|
||||
# L1 = - D1.T*D1
|
||||
# L2 = - D2.T*D2
|
||||
|
||||
Av = mesh.aveN2CC
|
||||
|
||||
B1 = utils.spzeros(n1+1,n1+1);
|
||||
B2 = utils.spzeros(n2+1,n2+1);
|
||||
|
||||
B1.dtype = complex
|
||||
B2.dtype = complex
|
||||
B1[0,0] = 2*1j*k*h1[0]; B1[-1,-1] = 2*1j*k*h1[-1]
|
||||
B2[0,0] = 2*1j*k*h2[0]; B2[-1,-1] = 2*1j*k*h2[-1]
|
||||
|
||||
# generate the 2D Laplacian
|
||||
# L = sp.kron(sp.identity(n2+1),L1) + sp.kron(L2,sp.identity(n1+1))
|
||||
L = mesh.nodalLaplacian
|
||||
B = sp.kron(sp.identity(n2+1),B1) + sp.kron(B2,sp.identity(n1+1))
|
||||
L = L+B
|
||||
#plt.spy(L)
|
||||
#plt.show()
|
||||
# Generate the Mass matrix
|
||||
M = utils.sdiag(Av.T*utils.mkvc(model))
|
||||
A = - L - w**2 * M
|
||||
|
||||
mesh.ForModMat = A
|
||||
u = sp.linalg.spsolve(A,q);
|
||||
d = P*u
|
||||
return u, d
|
||||
|
||||
def HelmholtzJmatVec(v,model,u,mesh,w,mbc,P):
|
||||
|
||||
Cm = -w**2 * utils.sdiag(u)*mesh.aveN2CC.T
|
||||
Cu = mesh.ForModMat
|
||||
Cmv = Cm*v;
|
||||
lam = sp.linalg.spsolve(Cu,Cmv);
|
||||
return -P*lam
|
||||
|
||||
def HelmholtzJTmatVec(v,model,u,mesh,w,mbc,P):
|
||||
|
||||
Cm = -w**2 * utils.sdiag(u)*mesh.aveN2CC.T
|
||||
Cu = mesh.ForModMat
|
||||
Pv = -P.T*v
|
||||
z = sp.linalg.spsolve(Cu.T,Pv);
|
||||
return Cm.T*z
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# odel,mesh,w,mbc,q
|
||||
n1 = 128; n2 = 128
|
||||
h1 = np.ones(n1); h2 = np.ones(n2);
|
||||
P = sp.identity((n1+1)*(n2+1))
|
||||
|
||||
mesh = TensorMesh([h1,h2])
|
||||
model = np.ones(mesh.nC)
|
||||
w = 1
|
||||
mbc = 1
|
||||
q = np.zeros((mesh.nNx,mesh.nNy))
|
||||
q[n1/2,n2/2] = 1.0
|
||||
q = q.reshape(mesh.nN,order = 'F')
|
||||
|
||||
u, d = HelmholtzSol(model,mesh,w,mbc,q,P)
|
||||
u = u.reshape((mesh.nCx+1,mesh.nCy+1),order = 'F')
|
||||
|
||||
plt.imshow(u.real)
|
||||
plt.show()
|
||||
|
||||
dm = np.random.rand(mesh.nC)*1e-1+2
|
||||
u1, d1 = HelmholtzSol(model+dm,mesh,w,mbc,q,P)
|
||||
|
||||
dd = HelmholtzJmatVec(dm,model,u,mesh,w,mbc,P)
|
||||
|
||||
print np.linalg.norm(d1-d)
|
||||
print np.linalg.norm(d1-d-dd)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ from SimPEG.utils import ModelBuilder, sdiag, mkvc
|
||||
from SimPEG import Solver
|
||||
import numpy as np
|
||||
import scipy.sparse as sp
|
||||
import scipy.sparse.linalg as linalg
|
||||
|
||||
|
||||
class DCProblem(ModelTransforms.LogModel, Problem):
|
||||
|
||||
+43
-36
@@ -4,47 +4,54 @@ import unittest
|
||||
import HTMLTestRunner
|
||||
|
||||
# This code will run all tests in directory named test_*.py
|
||||
def main(html=False):
|
||||
TITLE = 'Test Results'
|
||||
test_file_strings = glob.glob('test_*.py')
|
||||
module_strings = [str[0:len(str)-3] for str in test_file_strings]
|
||||
suites = [unittest.defaultTestLoader.loadTestsFromName(str) for str
|
||||
in module_strings]
|
||||
testSuite = unittest.TestSuite(suites)
|
||||
|
||||
TITLE = 'Test Results'
|
||||
test_file_strings = glob.glob('test_*.py')
|
||||
module_strings = [str[0:len(str)-3] for str in test_file_strings]
|
||||
suites = [unittest.defaultTestLoader.loadTestsFromName(str) for str
|
||||
in module_strings]
|
||||
testSuite = unittest.TestSuite(suites)
|
||||
unittest.TextTestRunner(verbosity=2).run(testSuite)
|
||||
if not html:
|
||||
unittest.TextTestRunner(verbosity=2).run(testSuite)
|
||||
return
|
||||
|
||||
|
||||
outfile = open("report.html", "w")
|
||||
runner = HTMLTestRunner.HTMLTestRunner(
|
||||
stream=outfile,
|
||||
title=TITLE,
|
||||
description='SimPEG Test Report was automatically generated.'
|
||||
)
|
||||
outfile = open("report.html", "w")
|
||||
runner = HTMLTestRunner.HTMLTestRunner(
|
||||
stream=outfile,
|
||||
title=TITLE,
|
||||
description='SimPEG Test Report was automatically generated.',
|
||||
verbosity=2
|
||||
)
|
||||
|
||||
runner.run(testSuite)
|
||||
outfile.close()
|
||||
runner.run(testSuite)
|
||||
outfile.close()
|
||||
|
||||
reader = open("report.html", "r")
|
||||
writer = open("../../docs/api_TestResults.rst", "w")
|
||||
reader = open("report.html", "r")
|
||||
writer = open("../../docs/api_TestResults.rst", "w")
|
||||
|
||||
writer.write('.. _api_TestResults:\n\nTest Results\n============\n\n.. raw:: html\n\n')
|
||||
writer.write('.. _api_TestResults:\n\nTest Results\n============\n\n.. raw:: html\n\n')
|
||||
|
||||
go = False
|
||||
for line in reader:
|
||||
skip = False
|
||||
if line == '<style type="text/css" media="screen">\n':
|
||||
go = True
|
||||
elif line == "<div id='ending'> </div>\n":
|
||||
go = False
|
||||
elif line == '</head>\n':
|
||||
skip = True
|
||||
elif line == '<h1>'+TITLE+'</h1>\n':
|
||||
skip = True
|
||||
elif line == '<body>\n':
|
||||
skip = True
|
||||
if go and not skip:
|
||||
writer.write(' '+line)
|
||||
go = False
|
||||
for line in reader:
|
||||
skip = False
|
||||
if line == '<style type="text/css" media="screen">\n':
|
||||
go = True
|
||||
elif line == "<div id='ending'> </div>\n":
|
||||
go = False
|
||||
elif line == '</head>\n':
|
||||
skip = True
|
||||
elif line == '<h1>'+TITLE+'</h1>\n':
|
||||
skip = True
|
||||
elif line == '<body>\n':
|
||||
skip = True
|
||||
if go and not skip:
|
||||
writer.write(' '+line)
|
||||
|
||||
writer.close()
|
||||
reader.close()
|
||||
os.remove("report.html")
|
||||
writer.close()
|
||||
reader.close()
|
||||
os.remove("report.html")
|
||||
|
||||
if __name__ == '__main__':
|
||||
main(True)
|
||||
|
||||
Reference in New Issue
Block a user