mirror of
https://github.com/wassname/simpeg.git
synced 2026-06-27 19:48:52 +08:00
switch coverage and delete old tests.
This commit is contained in:
+1
-1
@@ -18,7 +18,7 @@ env:
|
||||
- TEST_DIR="tests/mesh tests/base tests/utils"
|
||||
- TEST_DIR=tests/em/fdem/inverse/derivs
|
||||
- TEST_DIR=tests/em/tdem
|
||||
- TEST_DIR=tests/dcip
|
||||
- TEST_DIR=tests/em/static
|
||||
- TEST_DIR=tests/flow
|
||||
- TEST_DIR=tests/mt
|
||||
- TEST_DIR=tests/examples
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
import os
|
||||
import glob
|
||||
import unittest
|
||||
|
||||
if __name__ == '__main__':
|
||||
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)
|
||||
@@ -1,77 +0,0 @@
|
||||
import unittest
|
||||
from SimPEG import *
|
||||
import SimPEG.DCIP as DC
|
||||
|
||||
|
||||
class DCProblemTests(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
||||
aSpacing=2.5
|
||||
nElecs=10
|
||||
|
||||
surveySize = nElecs*aSpacing - aSpacing
|
||||
cs = surveySize/nElecs/4
|
||||
|
||||
mesh = Mesh.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')
|
||||
|
||||
srcList = DC.Utils.WennerSrcList(nElecs, aSpacing, in2D=True)
|
||||
survey = DC.SurveyDC(srcList)
|
||||
problem = DC.ProblemDC_CC(mesh)
|
||||
problem.pair(survey)
|
||||
|
||||
mSynth = np.ones(mesh.nC)
|
||||
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=1e4)
|
||||
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 test_misfit(self):
|
||||
derChk = lambda m: [self.survey.dpred(m), lambda mx: self.p.Jvec(self.m0, mx)]
|
||||
passed = Tests.checkDerivative(derChk, self.m0, plotIt=False)
|
||||
self.assertTrue(passed)
|
||||
|
||||
def test_adjoint(self):
|
||||
# Adjoint Test
|
||||
u = np.random.rand(self.mesh.nC*self.survey.nSrc)
|
||||
v = np.random.rand(self.mesh.nC)
|
||||
w = np.random.rand(self.survey.dobs.shape[0])
|
||||
wtJv = w.dot(self.p.Jvec(self.m0, v))
|
||||
vtJtw = v.dot(self.p.Jtvec(self.m0, w))
|
||||
passed = np.abs(wtJv - vtJtw) < 1e-10
|
||||
print 'Adjoint Test', np.abs(wtJv - vtJtw), passed
|
||||
self.assertTrue(passed)
|
||||
|
||||
def test_dataObj(self):
|
||||
derChk = lambda m: [self.dmis.eval(m), self.dmis.evalDeriv(m)]
|
||||
passed = Tests.checkDerivative(derChk, self.m0, plotIt=False)
|
||||
self.assertTrue(passed)
|
||||
|
||||
|
||||
def test_massMatrices(self):
|
||||
Gu = np.random.rand(self.mesh.nF)
|
||||
def derChk(m):
|
||||
self.p.curModel = m
|
||||
return [self.p.Msig * Gu, self.p.dMdsig(Gu)]
|
||||
passed = Tests.checkDerivative(derChk, self.m0, plotIt=False)
|
||||
self.assertTrue(passed)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -1,65 +0,0 @@
|
||||
import unittest
|
||||
import SimPEG.DCIP as DC
|
||||
from SimPEG import *
|
||||
|
||||
class IPforwardTests(unittest.TestCase):
|
||||
|
||||
def test_IPforward(self):
|
||||
|
||||
cs = 12.5
|
||||
nc = 200/cs+1
|
||||
hx = [(cs,7, -1.3),(cs,nc),(cs,7, 1.3)]
|
||||
hy = [(cs,7, -1.3),(cs,int(nc/2+1)),(cs,7, 1.3)]
|
||||
hz = [(cs,7, -1.3),(cs,int(nc/2+1))]
|
||||
mesh = Mesh.TensorMesh([hx, hy, hz], 'CCN')
|
||||
sighalf = 1e-2
|
||||
sigma = np.ones(mesh.nC)*sighalf
|
||||
p0 = np.r_[-50., 50., -50.]
|
||||
p1 = np.r_[ 50.,-50., -150.]
|
||||
blk_ind = Utils.ModelBuilder.getIndicesBlock(p0, p1, mesh.gridCC)
|
||||
sigma[blk_ind] = 1e-3
|
||||
eta = np.zeros_like(sigma)
|
||||
eta[blk_ind] = 0.1
|
||||
sigmaInf = sigma.copy()
|
||||
sigma0 = sigma*(1-eta)
|
||||
|
||||
nElecs = 11
|
||||
x_temp = np.linspace(-100, 100, nElecs)
|
||||
aSpacing = x_temp[1]-x_temp[0]
|
||||
y_temp = 0.
|
||||
xyz = Utils.ndgrid(x_temp, np.r_[y_temp], np.r_[0.])
|
||||
srcList = DC.Utils.WennerSrcList(nElecs,aSpacing)
|
||||
survey = DC.SurveyDC(srcList)
|
||||
|
||||
imap = Maps.IdentityMap(mesh)
|
||||
problem = DC.ProblemDC_CC(mesh, mapping=imap)
|
||||
|
||||
try:
|
||||
from pymatsolver import MumpsSolver
|
||||
solver = MumpsSolver
|
||||
except ImportError, e:
|
||||
solver = SolverLU
|
||||
|
||||
problem.Solver = solver
|
||||
problem.pair(survey)
|
||||
|
||||
phi0 = survey.dpred(sigma0)
|
||||
phiInf = survey.dpred(sigmaInf)
|
||||
|
||||
phiIP_true = phi0-phiInf
|
||||
|
||||
surveyIP = DC.SurveyIP(srcList)
|
||||
problemIP = DC.ProblemIP(mesh, sigma=sigma)
|
||||
problemIP.pair(surveyIP)
|
||||
|
||||
problemIP.Solver = solver
|
||||
|
||||
phiIP_approx = surveyIP.dpred(eta)
|
||||
|
||||
err = np.linalg.norm(phiIP_true-phiIP_approx) / np.linalg.norm(phiIP_true)
|
||||
|
||||
self.assertTrue(err < 0.02)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -1,82 +0,0 @@
|
||||
import unittest
|
||||
from SimPEG import *
|
||||
import SimPEG.DCIP as DC
|
||||
|
||||
class IPProblemTests(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
||||
cs = 12.5
|
||||
nc = 500/cs+1
|
||||
hx = [(cs,0, -1.3),(cs,nc),(cs,0, 1.3)]
|
||||
hy = [(cs,0, -1.3),(cs,int(nc/2+1)),(cs,0, 1.3)]
|
||||
hz = [(cs,0, -1.3),(cs,int(nc/2+1))]
|
||||
mesh = Mesh.TensorMesh([hx, hy, hz], 'CCN')
|
||||
sighalf = 1e-2
|
||||
sigma = np.ones(mesh.nC)*sighalf
|
||||
p0 = np.r_[-50., 50., -50.]
|
||||
p1 = np.r_[ 50.,-50., -150.]
|
||||
blk_ind = Utils.ModelBuilder.getIndicesBlock(p0, p1, mesh.gridCC)
|
||||
sigma[blk_ind] = 1e-3
|
||||
eta = np.zeros_like(sigma)
|
||||
eta[blk_ind] = 0.1
|
||||
|
||||
nElecs = 5
|
||||
x_temp = np.linspace(-250, 250, nElecs)
|
||||
aSpacing = x_temp[1]-x_temp[0]
|
||||
y_temp = 0.
|
||||
xyz = Utils.ndgrid(x_temp, np.r_[y_temp], np.r_[0.])
|
||||
srcList = DC.Utils.WennerSrcList(nElecs,aSpacing)
|
||||
survey = DC.SurveyIP(srcList)
|
||||
imap = Maps.IdentityMap(mesh)
|
||||
problem = DC.ProblemIP(mesh, sigma=sigma, mapping= imap)
|
||||
problem.pair(survey)
|
||||
|
||||
try:
|
||||
from pymatsolver import MumpsSolver
|
||||
problem.Solver = MumpsSolver
|
||||
except ImportError, e:
|
||||
problem.Solver = SolverLU
|
||||
|
||||
mSynth = eta
|
||||
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=1e4)
|
||||
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 test_misfit(self):
|
||||
derChk = lambda m: [self.survey.dpred(m), lambda mx: self.p.Jvec(self.m0, mx)]
|
||||
passed = Tests.checkDerivative(derChk, self.m0*0, plotIt=False)
|
||||
self.assertTrue(passed)
|
||||
|
||||
def test_adjoint(self):
|
||||
# Adjoint Test
|
||||
u = np.random.rand(self.mesh.nC*self.survey.nSrc)
|
||||
v = np.random.rand(self.mesh.nC)
|
||||
w = np.random.rand(self.survey.dobs.shape[0])
|
||||
wtJv = w.dot(self.p.Jvec(self.m0, v))
|
||||
vtJtw = v.dot(self.p.Jtvec(self.m0, w))
|
||||
passed = np.abs(wtJv - vtJtw) < 1e-10
|
||||
print 'Adjoint Test', np.abs(wtJv - vtJtw), passed
|
||||
self.assertTrue(passed)
|
||||
|
||||
def test_dataObj(self):
|
||||
derChk = lambda m: [self.dmis.eval(m), self.dmis.evalDeriv(m)]
|
||||
passed = Tests.checkDerivative(derChk, self.m0, plotIt=False)
|
||||
self.assertTrue(passed)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user