From 6e21d3223086f883fc6410d2ef93a14fed13dbc4 Mon Sep 17 00:00:00 2001 From: rowanc1 Date: Tue, 29 Apr 2014 10:52:15 -0700 Subject: [PATCH] test Combinations of rxs and txs for J and Jt --- simpegEM/Tests/test_TDEM_b_DerivAdjoint.py | 5 +- simpegEM/Tests/test_TDEM_combos.py | 77 ++++++++++++++++++++++ 2 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 simpegEM/Tests/test_TDEM_combos.py diff --git a/simpegEM/Tests/test_TDEM_b_DerivAdjoint.py b/simpegEM/Tests/test_TDEM_b_DerivAdjoint.py index 071e0de5..36176944 100644 --- a/simpegEM/Tests/test_TDEM_b_DerivAdjoint.py +++ b/simpegEM/Tests/test_TDEM_b_DerivAdjoint.py @@ -22,9 +22,8 @@ class TDEM_bDerivTests(unittest.TestCase): [Maps.ExpMap, Maps.Vertical1DMap, activeMap]) rxOffset = 40. - rxTypes = 'bx,bz' - rxs = [EM.TDEM.RxTDEM(np.array([[rxOffset, 0., 0.]]), np.logspace(-4,-3, 20), rxType) for rxType in rxTypes.split(',')] - tx = EM.TDEM.TxTDEM(np.array([0., 0., 0.]), 'VMD_MVP', rxs) + rx = EM.TDEM.RxTDEM(np.array([[rxOffset, 0., 0.]]), np.logspace(-4,-3, 20), 'bz') + tx = EM.TDEM.TxTDEM(np.array([0., 0., 0.]), 'VMD_MVP', [rx]) survey = EM.TDEM.SurveyTDEM([tx]) diff --git a/simpegEM/Tests/test_TDEM_combos.py b/simpegEM/Tests/test_TDEM_combos.py new file mode 100644 index 00000000..f089d182 --- /dev/null +++ b/simpegEM/Tests/test_TDEM_combos.py @@ -0,0 +1,77 @@ +import unittest +from SimPEG import * +import simpegEM as EM + +plotIt = False + +def getProb(meshType='CYL',rxTypes='bx,bz',nTx=1): + cs = 5. + ncx = 20 + ncy = 6 + npad = 20 + hx = [(cs,ncx), (cs,npad,1.3)] + hy = [(cs,npad,-1.3), (cs,ncy), (cs,npad,1.3)] + mesh = Mesh.CylMesh([hx,1,hy], '00C') + + active = mesh.vectorCCz<0. + activeMap = Maps.ActiveCells(mesh, active, np.log(1e-8), nC=mesh.nCz) + mapping = Maps.ComboMap(mesh, [Maps.ExpMap, Maps.Vertical1DMap, activeMap]) + + rxOffset = 40. + + txs = [] + for ii in range(nTx): + rxs = [EM.TDEM.RxTDEM(np.array([[rxOffset, 0., 0.]]), np.logspace(-4,-3, 20 + ii), rxType) for rxType in rxTypes.split(',')] + txs += [EM.TDEM.TxTDEM(np.array([0., 0., 0.]), 'VMD_MVP', rxs)] + + survey = EM.TDEM.SurveyTDEM(txs) + + prb = EM.TDEM.ProblemTDEM_b(mesh, mapping=mapping) + # prb.timeSteps = [1e-5] + prb.timeSteps = [(1e-05, 10), (5e-05, 10), (2.5e-4, 10)] + # prb.timeSteps = [(1e-05, 100)] + + sigma = np.ones(mesh.nCz)*1e-8 + sigma[mesh.vectorCCz<0] = 1e-1 + sigma = np.log(sigma[active]) + + prb.pair(survey) + return prb, mesh, sigma + +def testJvec(prb, mesh, sigma): + prb.timeSteps = [(1e-05, 10), (0.0001, 10), (0.001, 10)] + # d_sig = 0.8*sigma #np.random.rand(mesh.nCz) + d_sig = 10*np.random.rand(prb.mapping.nP) + derChk = lambda m: [prb.survey.dpred(m), lambda mx: prb.Jvec(sigma, mx)] + return Tests.checkDerivative(derChk, sigma, plotIt=False, dx=d_sig, num=2, eps=1e-20) + +def testAdjoint(prb, mesh, sigma): + m = np.random.rand(prb.mapping.nP) + d = np.random.rand(prb.survey.nD) + + V1 = d.dot(prb.Jvec(sigma, m)) + V2 = m.dot(prb.Jtvec(sigma, d)) + print 'AdjointTest', V1, V2 + return np.abs(V1-V2)/np.abs(V1), 1e-6 + +class TDEM_bDerivTests(unittest.TestCase): + + def test_Jvec_bx(self): self.assertTrue(testJvec(*getProb(rxTypes='bx'))) + def test_Adjoint_bx(self): self.assertLess(*testAdjoint(*getProb(rxTypes='bx'))) + + def test_Jvec_bxbz(self): self.assertTrue(testJvec(*getProb(rxTypes='bx,bz'))) + def test_Adjoint_bxbz(self): self.assertLess(*testAdjoint(*getProb(rxTypes='bx,bz'))) + + def test_Jvec_bxbz_2tx(self): self.assertTrue(testJvec(*getProb(rxTypes='bx,bz',nTx=2))) + def test_Adjoint_bxbz_2tx(self): self.assertLess(*testAdjoint(*getProb(rxTypes='bx,bz',nTx=2))) + + def test_Jvec_bxbzbz(self): self.assertTrue(testJvec(*getProb(rxTypes='bx,bz,bz'))) + def test_Adjoint_bxbzbz(self): self.assertLess(*testAdjoint(*getProb(rxTypes='bx,bz,bz'))) + + # def test_Jvec_ey(self): self.assertTrue(testJvec(*getProb(rxTypes='ey'))) + # def test_Adjoint_ey(self): self.assertLess(*testAdjoint(*getProb(rxTypes='ey'))) + + + +if __name__ == '__main__': + unittest.main()