mirror of
https://github.com/wassname/simpeg.git
synced 2026-09-17 12:50:48 +08:00
Futurize 1, futurize 2, pasteurize.
This commit is contained in:
@@ -1,3 +1,9 @@
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
if __name__ == '__main__':
|
||||
import os
|
||||
import glob
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
if __name__ == '__main__':
|
||||
import os
|
||||
import glob
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import absolute_import
|
||||
from builtins import int
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
from builtins import range
|
||||
import unittest
|
||||
from SimPEG import *
|
||||
|
||||
@@ -56,7 +64,7 @@ class FieldsTest(unittest.TestCase):
|
||||
self.assertTrue(np.all(F[:, 'e'] == e))
|
||||
self.assertTrue(np.all(F[:, 'b'] == b))
|
||||
|
||||
for s in [0,0.0,np.r_[0],long(0)]:
|
||||
for s in [0,0.0,np.r_[0],int(0)]:
|
||||
F[:, 'b'] = s
|
||||
self.assertTrue(np.all(F[:, 'b'] == b*0))
|
||||
|
||||
@@ -220,7 +228,7 @@ class FieldsTest_Time(unittest.TestCase):
|
||||
self.assertTrue(np.all(F[:, 'e'] == e))
|
||||
self.assertTrue(np.all(F[:, 'b'] == b))
|
||||
|
||||
for s in [0,0.0,np.r_[0],long(0)]:
|
||||
for s in [0,0.0,np.r_[0],int(0)]:
|
||||
F[:, 'b'] = s
|
||||
self.assertTrue(np.all(F[:, 'b'] == b*0))
|
||||
|
||||
@@ -316,7 +324,7 @@ class FieldsTest_Time_Aliased(unittest.TestCase):
|
||||
F[:, 'b', :] = b
|
||||
self.assertTrue(np.all(F[:, 'e', 0] == F.mesh.edgeCurl.T * b[:,:,0] ))
|
||||
|
||||
e = range(nT)
|
||||
e = list(range(nT))
|
||||
for i in range(nT):
|
||||
e[i] = F.mesh.edgeCurl.T*b[:,:,i] + i
|
||||
e[i] = e[i][:,:,np.newaxis]
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
from past.utils import old_div
|
||||
import unittest
|
||||
from SimPEG import *
|
||||
from scipy.constants import mu_0
|
||||
@@ -12,7 +19,7 @@ class MyReciprocalPropMap(Maps.PropMap):
|
||||
sigma = Maps.Property("Electrical Conductivity", defaultInvProp=True, propertyLink=('rho', Maps.ReciprocalMap))
|
||||
rho = Maps.Property("Electrical Resistivity", propertyLink=('sigma', Maps.ReciprocalMap))
|
||||
mu = Maps.Property("Mu", defaultVal=mu_0, propertyLink=('mui', Maps.ReciprocalMap))
|
||||
mui = Maps.Property("Mu", defaultVal=1./mu_0, propertyLink=('mu', Maps.ReciprocalMap))
|
||||
mui = Maps.Property("Mu", defaultVal=old_div(1.,mu_0), propertyLink=('mu', Maps.ReciprocalMap))
|
||||
|
||||
|
||||
class TestPropMaps(unittest.TestCase):
|
||||
@@ -137,7 +144,7 @@ class TestPropMaps(unittest.TestCase):
|
||||
# print pm.sigma
|
||||
# print pm.sigmaMap
|
||||
assert np.all(pm.sigma == [1,2,3])
|
||||
assert np.all(pm.rho == 1./np.r_[1,2,3])
|
||||
assert np.all(pm.rho == old_div(1.,np.r_[1,2,3]))
|
||||
assert pm.sigmaMap is iMap
|
||||
assert pm.rhoMap is None
|
||||
assert pm.sigmaDeriv is not None
|
||||
@@ -155,7 +162,7 @@ class TestPropMaps(unittest.TestCase):
|
||||
assert 'mui' not in pm
|
||||
|
||||
assert pm.mu == mu_0
|
||||
assert pm.mui == 1.0/mu_0
|
||||
assert pm.mui == old_div(1.0,mu_0)
|
||||
assert pm.muMap is None
|
||||
assert pm.muDeriv is None
|
||||
assert pm.muiMap is None
|
||||
@@ -165,7 +172,7 @@ class TestPropMaps(unittest.TestCase):
|
||||
pm = PM(np.r_[1,2.,3])
|
||||
# print pm.sigma
|
||||
# print pm.sigmaMap
|
||||
assert np.all(pm.sigma == 1./np.r_[1,2,3])
|
||||
assert np.all(pm.sigma == old_div(1.,np.r_[1,2,3]))
|
||||
assert np.all(pm.rho == [1,2,3])
|
||||
assert pm.sigmaMap is None
|
||||
assert pm.rhoMap is iMap
|
||||
@@ -198,8 +205,8 @@ class TestPropMaps(unittest.TestCase):
|
||||
m = propmap(x0)
|
||||
|
||||
# test Sigma
|
||||
testme = lambda v: [1./(m.rhoMap*v), m.sigmaDeriv]
|
||||
print 'Testing Rho from Sigma'
|
||||
testme = lambda v: [old_div(1.,(m.rhoMap*v)), m.sigmaDeriv]
|
||||
print('Testing Rho from Sigma')
|
||||
Tests.checkDerivative(testme, x0, dx=0.01*x0, num=5, plotIt=False)
|
||||
|
||||
def test_linked_derivs_rho(self):
|
||||
@@ -212,8 +219,8 @@ class TestPropMaps(unittest.TestCase):
|
||||
m = propmap(x0)
|
||||
|
||||
# test Sigma
|
||||
testme = lambda v: [1./(m.sigmaMap*v), m.rhoDeriv]
|
||||
print 'Testing Rho from Sigma'
|
||||
testme = lambda v: [old_div(1.,(m.sigmaMap*v)), m.rhoDeriv]
|
||||
print('Testing Rho from Sigma')
|
||||
Tests.checkDerivative(testme, x0, dx=0.01*x0, num=5, plotIt=False)
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
from __future__ import division
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
from past.utils import old_div
|
||||
import unittest
|
||||
from SimPEG import *
|
||||
from SimPEG.Mesh import TensorMesh
|
||||
@@ -23,7 +30,7 @@ def dotest(MYSOLVER, multi=False, A=None, **solverOpts):
|
||||
G = -M.faceDiv.T
|
||||
Msig = M.getFaceInnerProduct()
|
||||
A = D*Msig*G
|
||||
A[-1,-1] *= 1/M.vol[-1] # remove the constant null space from the matrix
|
||||
A[-1,-1] *= old_div(1,M.vol[-1]) # remove the constant null space from the matrix
|
||||
else:
|
||||
M = Mesh.TensorMesh([A.shape[0]])
|
||||
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
import unittest
|
||||
from SimPEG import *
|
||||
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
import numpy as np
|
||||
import unittest
|
||||
from SimPEG import *
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import division
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
import unittest
|
||||
from SimPEG import Solver
|
||||
from SimPEG.Mesh import TensorMesh
|
||||
@@ -19,16 +25,16 @@ class TestOptimizers(unittest.TestCase):
|
||||
GN = Optimization.GaussNewton()
|
||||
xopt = GN.minimize(Rosenbrock,np.array([0,0]))
|
||||
x_true = np.array([1.,1.])
|
||||
print 'xopt: ', xopt
|
||||
print 'x_true: ', x_true
|
||||
print('xopt: ', xopt)
|
||||
print('x_true: ', x_true)
|
||||
self.assertTrue(np.linalg.norm(xopt-x_true,2) < TOL, True)
|
||||
|
||||
def test_GN_quadratic(self):
|
||||
GN = Optimization.GaussNewton()
|
||||
xopt = GN.minimize(getQuadratic(self.A,self.b),np.array([0,0]))
|
||||
x_true = np.array([5.,5.])
|
||||
print 'xopt: ', xopt
|
||||
print 'x_true: ', x_true
|
||||
print('xopt: ', xopt)
|
||||
print('x_true: ', x_true)
|
||||
self.assertTrue(np.linalg.norm(xopt-x_true,2) < TOL, True)
|
||||
|
||||
def test_ProjGradient_quadraticBounded(self):
|
||||
@@ -36,8 +42,8 @@ class TestOptimizers(unittest.TestCase):
|
||||
PG.lower, PG.upper = -2, 2
|
||||
xopt = PG.minimize(getQuadratic(self.A,self.b),np.array([0,0]))
|
||||
x_true = np.array([2.,2.])
|
||||
print 'xopt: ', xopt
|
||||
print 'x_true: ', x_true
|
||||
print('xopt: ', xopt)
|
||||
print('x_true: ', x_true)
|
||||
self.assertTrue(np.linalg.norm(xopt-x_true,2) < TOL, True)
|
||||
|
||||
def test_ProjGradient_quadratic1Bound(self):
|
||||
@@ -46,8 +52,8 @@ class TestOptimizers(unittest.TestCase):
|
||||
PG.lower, PG.upper = -2, 2
|
||||
xopt = PG.minimize(getQuadratic(self.A,myB),np.array([0,0]))
|
||||
x_true = np.array([2.,-1.])
|
||||
print 'xopt: ', xopt
|
||||
print 'x_true: ', x_true
|
||||
print('xopt: ', xopt)
|
||||
print('x_true: ', x_true)
|
||||
self.assertTrue(np.linalg.norm(xopt-x_true,2) < TOL, True)
|
||||
|
||||
def test_NewtonRoot(self):
|
||||
@@ -55,9 +61,9 @@ class TestOptimizers(unittest.TestCase):
|
||||
x = np.array([np.pi-0.3, np.pi+0.1, 0])
|
||||
xopt = Optimization.NewtonRoot(comments=False).root(fun,x)
|
||||
x_true = np.array([np.pi,np.pi,0])
|
||||
print 'Newton Root Finding'
|
||||
print 'xopt: ', xopt
|
||||
print 'x_true: ', x_true
|
||||
print('Newton Root Finding')
|
||||
print('xopt: ', xopt)
|
||||
print('x_true: ', x_true)
|
||||
self.assertTrue(np.linalg.norm(xopt-x_true,2) < TOL, True)
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
import unittest
|
||||
from SimPEG import *
|
||||
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
from past.utils import old_div
|
||||
import numpy as np
|
||||
import unittest
|
||||
from SimPEG import *
|
||||
@@ -12,7 +19,7 @@ class RegularizationTests(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
hx, hy, hz = np.random.rand(10), np.random.rand(9), np.random.rand(8)
|
||||
hx, hy, hz = hx/hx.sum(), hy/hy.sum(), hz/hz.sum()
|
||||
hx, hy, hz = old_div(hx,hx.sum()), old_div(hy,hy.sum()), old_div(hz,hz.sum())
|
||||
mesh1 = Mesh.TensorMesh([hx])
|
||||
mesh2 = Mesh.TensorMesh([hx, hy])
|
||||
mesh3 = Mesh.TensorMesh([hx, hy, hz])
|
||||
@@ -28,22 +35,22 @@ class RegularizationTests(unittest.TestCase):
|
||||
|
||||
for i, mesh in enumerate(self.meshlist):
|
||||
|
||||
print 'Testing %iD'%mesh.dim
|
||||
print('Testing %iD'%mesh.dim)
|
||||
|
||||
mapping = r.mapPair(mesh)
|
||||
reg = r(mesh, mapping=mapping)
|
||||
m = np.random.rand(mapping.nP)
|
||||
reg.mref = np.ones_like(m)*np.mean(m)
|
||||
|
||||
print 'Check: phi_m (mref) = %f' %reg.eval(reg.mref)
|
||||
print('Check: phi_m (mref) = %f' %reg.eval(reg.mref))
|
||||
passed = reg.eval(reg.mref) < TOL
|
||||
self.assertTrue(passed)
|
||||
|
||||
print 'Check:', R
|
||||
print('Check:', R)
|
||||
passed = Tests.checkDerivative(lambda m : [reg.eval(m), reg.evalDeriv(m)], m, plotIt=False)
|
||||
self.assertTrue(passed)
|
||||
|
||||
print 'Check 2 Deriv:', R
|
||||
print('Check 2 Deriv:', R)
|
||||
passed = Tests.checkDerivative(lambda m : [reg.evalDeriv(m), reg.eval2Deriv(m)], m, plotIt=False)
|
||||
self.assertTrue(passed)
|
||||
|
||||
@@ -56,7 +63,7 @@ class RegularizationTests(unittest.TestCase):
|
||||
|
||||
for i, mesh in enumerate(self.meshlist):
|
||||
|
||||
print 'Testing Active Cells %iD'%(mesh.dim)
|
||||
print('Testing Active Cells %iD'%(mesh.dim))
|
||||
|
||||
if mesh.dim == 1:
|
||||
indActive = Utils.mkvc(mesh.gridCC <= 0.8)
|
||||
@@ -70,15 +77,15 @@ class RegularizationTests(unittest.TestCase):
|
||||
m = np.random.rand(mesh.nC)[indAct]
|
||||
reg.mref = np.ones_like(m)*np.mean(m)
|
||||
|
||||
print 'Check: phi_m (mref) = %f' %reg.eval(reg.mref)
|
||||
print('Check: phi_m (mref) = %f' %reg.eval(reg.mref))
|
||||
passed = reg.eval(reg.mref) < TOL
|
||||
self.assertTrue(passed)
|
||||
|
||||
print 'Check:', R
|
||||
print('Check:', R)
|
||||
passed = Tests.checkDerivative(lambda m : [reg.eval(m), reg.evalDeriv(m)], m, plotIt=False)
|
||||
self.assertTrue(passed)
|
||||
|
||||
print 'Check 2 Deriv:', R
|
||||
print('Check 2 Deriv:', R)
|
||||
passed = Tests.checkDerivative(lambda m : [reg.evalDeriv(m), reg.eval2Deriv(m)], m, plotIt=False)
|
||||
self.assertTrue(passed)
|
||||
|
||||
@@ -87,7 +94,7 @@ class RegularizationTests(unittest.TestCase):
|
||||
|
||||
for i, mesh in enumerate(self.meshlist):
|
||||
|
||||
print 'Testing %iD'%mesh.dim
|
||||
print('Testing %iD'%mesh.dim)
|
||||
|
||||
# mapping = r.mapPair(mesh)
|
||||
# reg = r(mesh, mapping=mapping)
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
import os
|
||||
import glob
|
||||
import unittest
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
from past.utils import old_div
|
||||
import unittest
|
||||
from SimPEG import *
|
||||
import SimPEG.DCIP as DC
|
||||
@@ -14,7 +21,7 @@ class DCProblemTests(unittest.TestCase):
|
||||
cs = surveySize/nElecs/4
|
||||
|
||||
mesh = Mesh.TensorMesh([
|
||||
[(cs,10, -1.3),(cs,surveySize/cs),(cs,10, 1.3)],
|
||||
[(cs,10, -1.3),(cs,old_div(surveySize,cs)),(cs,10, 1.3)],
|
||||
[(cs,3, -1.3),(cs,3,1.3)],
|
||||
# [(cs,5, -1.3),(cs,10)]
|
||||
],'CN')
|
||||
@@ -55,7 +62,7 @@ class DCProblemTests(unittest.TestCase):
|
||||
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
|
||||
print('Adjoint Test', np.abs(wtJv - vtJtw), passed)
|
||||
self.assertTrue(passed)
|
||||
|
||||
def test_dataObj(self):
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
from __future__ import division
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import absolute_import
|
||||
from builtins import int
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
from past.utils import old_div
|
||||
import unittest
|
||||
import SimPEG.DCIP as DC
|
||||
from SimPEG import *
|
||||
@@ -7,10 +15,10 @@ class IPforwardTests(unittest.TestCase):
|
||||
def test_IPforward(self):
|
||||
|
||||
cs = 12.5
|
||||
nc = 200/cs+1
|
||||
nc = old_div(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))]
|
||||
hy = [(cs,7, -1.3),(cs,int(old_div(nc,2)+1)),(cs,7, 1.3)]
|
||||
hz = [(cs,7, -1.3),(cs,int(old_div(nc,2)+1))]
|
||||
mesh = Mesh.TensorMesh([hx, hy, hz], 'CCN')
|
||||
sighalf = 1e-2
|
||||
sigma = np.ones(mesh.nC)*sighalf
|
||||
@@ -37,7 +45,7 @@ class IPforwardTests(unittest.TestCase):
|
||||
try:
|
||||
from pymatsolver import MumpsSolver
|
||||
solver = MumpsSolver
|
||||
except ImportError, e:
|
||||
except ImportError as e:
|
||||
solver = SolverLU
|
||||
|
||||
problem.Solver = solver
|
||||
@@ -56,7 +64,7 @@ class IPforwardTests(unittest.TestCase):
|
||||
|
||||
phiIP_approx = surveyIP.dpred(eta)
|
||||
|
||||
err = np.linalg.norm(phiIP_true-phiIP_approx) / np.linalg.norm(phiIP_true)
|
||||
err = old_div(np.linalg.norm(phiIP_true-phiIP_approx), np.linalg.norm(phiIP_true))
|
||||
|
||||
self.assertTrue(err < 0.02)
|
||||
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import absolute_import
|
||||
from builtins import int
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
from past.utils import old_div
|
||||
import unittest
|
||||
from SimPEG import *
|
||||
import SimPEG.DCIP as DC
|
||||
@@ -7,10 +15,10 @@ class IPProblemTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
|
||||
cs = 12.5
|
||||
nc = 500/cs+1
|
||||
nc = old_div(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))]
|
||||
hy = [(cs,0, -1.3),(cs,int(old_div(nc,2)+1)),(cs,0, 1.3)]
|
||||
hz = [(cs,0, -1.3),(cs,int(old_div(nc,2)+1))]
|
||||
mesh = Mesh.TensorMesh([hx, hy, hz], 'CCN')
|
||||
sighalf = 1e-2
|
||||
sigma = np.ones(mesh.nC)*sighalf
|
||||
@@ -35,7 +43,7 @@ class IPProblemTests(unittest.TestCase):
|
||||
try:
|
||||
from pymatsolver import MumpsSolver
|
||||
problem.Solver = MumpsSolver
|
||||
except ImportError, e:
|
||||
except ImportError as e:
|
||||
problem.Solver = SolverLU
|
||||
|
||||
mSynth = eta
|
||||
@@ -69,7 +77,7 @@ class IPProblemTests(unittest.TestCase):
|
||||
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
|
||||
print('Adjoint Test', np.abs(wtJv - vtJtw), passed)
|
||||
self.assertTrue(passed)
|
||||
|
||||
def test_dataObj(self):
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
import subprocess
|
||||
import unittest
|
||||
import os
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
if __name__ == '__main__':
|
||||
import os
|
||||
import glob
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
from past.utils import old_div
|
||||
import unittest
|
||||
from SimPEG import *
|
||||
from SimPEG import EM
|
||||
@@ -39,7 +46,7 @@ class FDEM_analyticTests(unittest.TestCase):
|
||||
try:
|
||||
from pymatsolver import MumpsSolver
|
||||
prb.Solver = MumpsSolver
|
||||
except ImportError, e:
|
||||
except ImportError as e:
|
||||
prb.Solver = SolverLU
|
||||
|
||||
sig = 1e-1
|
||||
@@ -54,7 +61,7 @@ class FDEM_analyticTests(unittest.TestCase):
|
||||
self.sig = sig
|
||||
|
||||
def test_Transect(self):
|
||||
print 'Testing Transect for analytic'
|
||||
print('Testing Transect for analytic')
|
||||
|
||||
u = self.prb.fields(self.m)
|
||||
|
||||
@@ -85,17 +92,17 @@ class FDEM_analyticTests(unittest.TestCase):
|
||||
|
||||
|
||||
def test_CylMeshEBDipoles(self):
|
||||
print 'Testing CylMesh Electric and Magnetic Dipoles in a wholespace- Analytic: J-formulation'
|
||||
print('Testing CylMesh Electric and Magnetic Dipoles in a wholespace- Analytic: J-formulation')
|
||||
sigmaback = 1.
|
||||
mur = 2.
|
||||
freq = 1.
|
||||
skdpth = 500./np.sqrt(sigmaback*freq)
|
||||
skdpth = old_div(500.,np.sqrt(sigmaback*freq))
|
||||
|
||||
csx, ncx, npadx = 5, 50, 25
|
||||
csz, ncz, npadz = 5, 50, 25
|
||||
hx = Utils.meshTensor([(csx,ncx), (csx,npadx,1.3)])
|
||||
hz = Utils.meshTensor([(csz,npadz,-1.3), (csz,ncz), (csz,npadz,1.3)])
|
||||
mesh = Mesh.CylMesh([hx,1,hz], [0.,0.,-hz.sum()/2]) # define the cylindrical mesh
|
||||
mesh = Mesh.CylMesh([hx,1,hz], [0.,0.,old_div(-hz.sum(),2)]) # define the cylindrical mesh
|
||||
|
||||
if plotIt:
|
||||
mesh.plotGrid()
|
||||
@@ -113,8 +120,8 @@ class FDEM_analyticTests(unittest.TestCase):
|
||||
s_ind = Utils.closestPoints(mesh,src_loc,'Fz') + mesh.nFx
|
||||
|
||||
de = np.zeros(mesh.nF,dtype=complex)
|
||||
de[s_ind] = 1./csz
|
||||
de_p = [EM.FDEM.Src.RawVec_e([],freq,de/mesh.area)]
|
||||
de[s_ind] = old_div(1.,csz)
|
||||
de_p = [EM.FDEM.Src.RawVec_e([],freq,old_div(de,mesh.area))]
|
||||
|
||||
dm_p = [EM.FDEM.Src.MagDipole([],freq,src_loc)]
|
||||
|
||||
@@ -151,7 +158,7 @@ class FDEM_analyticTests(unittest.TestCase):
|
||||
jn = fieldsBackE[de_p,'j']
|
||||
bn = fieldsBackM[dm_p,'b']
|
||||
|
||||
Rho = Utils.sdiag(1./SigmaBack)
|
||||
Rho = Utils.sdiag(old_div(1.,SigmaBack))
|
||||
Rho = sp.block_diag([Rho,Rho])
|
||||
|
||||
en = Rho*mesh.aveF2CCV*jn
|
||||
@@ -167,12 +174,12 @@ class FDEM_analyticTests(unittest.TestCase):
|
||||
bxa, bya, bza = EM.Analytics.FDEM.MagneticDipoleWholeSpace(XYZ, src_loc, sigmaback, freq,orientation='Z',mu= mur*mu_0)
|
||||
bxa, bya, bza = Utils.mkvc(bxa,2), Utils.mkvc(bya,2), Utils.mkvc(bza,2)
|
||||
|
||||
print ' comp, anayltic, numeric, num - ana, (num - ana)/ana'
|
||||
print ' ex:', np.linalg.norm(exa), np.linalg.norm(ex), np.linalg.norm(exa-ex), np.linalg.norm(exa-ex)/np.linalg.norm(exa)
|
||||
print ' ez:', np.linalg.norm(eza), np.linalg.norm(ez), np.linalg.norm(eza-ez), np.linalg.norm(eza-ez)/np.linalg.norm(eza)
|
||||
print(' comp, anayltic, numeric, num - ana, (num - ana)/ana')
|
||||
print(' ex:', np.linalg.norm(exa), np.linalg.norm(ex), np.linalg.norm(exa-ex), old_div(np.linalg.norm(exa-ex),np.linalg.norm(exa)))
|
||||
print(' ez:', np.linalg.norm(eza), np.linalg.norm(ez), np.linalg.norm(eza-ez), old_div(np.linalg.norm(eza-ez),np.linalg.norm(eza)))
|
||||
|
||||
print ' bx:', np.linalg.norm(bxa), np.linalg.norm(bx), np.linalg.norm(bxa-bx), np.linalg.norm(bxa-bx)/np.linalg.norm(bxa)
|
||||
print ' bz:', np.linalg.norm(bza), np.linalg.norm(bz), np.linalg.norm(bza-bz), np.linalg.norm(bza-bz)/np.linalg.norm(bza)
|
||||
print(' bx:', np.linalg.norm(bxa), np.linalg.norm(bx), np.linalg.norm(bxa-bx), old_div(np.linalg.norm(bxa-bx),np.linalg.norm(bxa)))
|
||||
print(' bz:', np.linalg.norm(bza), np.linalg.norm(bz), np.linalg.norm(bza-bz), old_div(np.linalg.norm(bza-bz),np.linalg.norm(bza)))
|
||||
|
||||
if plotIt:
|
||||
# Edipole
|
||||
@@ -231,11 +238,11 @@ class FDEM_analyticTests(unittest.TestCase):
|
||||
|
||||
plt.tight_layout()
|
||||
|
||||
self.assertTrue(np.linalg.norm(exa-ex)/np.linalg.norm(exa) < tol_EBdipole)
|
||||
self.assertTrue(np.linalg.norm(eza-ez)/np.linalg.norm(eza) < tol_EBdipole)
|
||||
self.assertTrue(old_div(np.linalg.norm(exa-ex),np.linalg.norm(exa)) < tol_EBdipole)
|
||||
self.assertTrue(old_div(np.linalg.norm(eza-ez),np.linalg.norm(eza)) < tol_EBdipole)
|
||||
|
||||
self.assertTrue(np.linalg.norm(bxa-bx)/np.linalg.norm(bxa) < tol_EBdipole)
|
||||
self.assertTrue(np.linalg.norm(bza-bz)/np.linalg.norm(bza) < tol_EBdipole)
|
||||
self.assertTrue(old_div(np.linalg.norm(bxa-bx),np.linalg.norm(bxa)) < tol_EBdipole)
|
||||
self.assertTrue(old_div(np.linalg.norm(bza-bz),np.linalg.norm(bza)) < tol_EBdipole)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
from SimPEG import Tests, Utils, np
|
||||
import SimPEG.EM.Analytics.FDEMcasing as Casing
|
||||
import unittest
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
import unittest
|
||||
from SimPEG import *
|
||||
from SimPEG import EM
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
import unittest
|
||||
from SimPEG import *
|
||||
from SimPEG import EM
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
import unittest
|
||||
from SimPEG import *
|
||||
from SimPEG import EM
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
if __name__ == '__main__':
|
||||
import os
|
||||
import glob
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import division
|
||||
from __future__ import absolute_import
|
||||
from builtins import int
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
import unittest
|
||||
from SimPEG import *
|
||||
from SimPEG import EM
|
||||
@@ -21,7 +28,7 @@ SrcList = ['RawVec', 'MagDipole'] #or 'MAgDipole_Bfield', 'CircularLoop', 'RawVe
|
||||
|
||||
def adjointTest(fdemType, comp):
|
||||
prb = getFDEMProblem(fdemType, comp, SrcList, freq)
|
||||
print 'Adjoint %s formulation - %s' % (fdemType, comp)
|
||||
print('Adjoint %s formulation - %s' % (fdemType, comp))
|
||||
|
||||
m = np.log(np.ones(prb.mapping.nP)*CONDUCTIVITY)
|
||||
mu = np.ones(prb.mesh.nC)*MU
|
||||
@@ -41,7 +48,7 @@ def adjointTest(fdemType, comp):
|
||||
vJw = v.dot(prb.Jvec(m, w, u))
|
||||
wJtv = w.dot(prb.Jtvec(m, v, u))
|
||||
tol = np.max([TOL*(10**int(np.log10(np.abs(vJw)))),FLR])
|
||||
print vJw, wJtv, vJw - wJtv, tol, np.abs(vJw - wJtv) < tol
|
||||
print(vJw, wJtv, vJw - wJtv, tol, np.abs(vJw - wJtv) < tol)
|
||||
return np.abs(vJw - wJtv) < tol
|
||||
|
||||
class FDEM_AdjointTests(unittest.TestCase):
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import division
|
||||
from __future__ import absolute_import
|
||||
from builtins import int
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
import unittest
|
||||
from SimPEG import *
|
||||
from SimPEG import EM
|
||||
@@ -21,7 +28,7 @@ SrcList = ['RawVec', 'MagDipole'] #or 'MAgDipole_Bfield', 'CircularLoop', 'RawVe
|
||||
|
||||
def adjointTest(fdemType, comp):
|
||||
prb = getFDEMProblem(fdemType, comp, SrcList, freq)
|
||||
print 'Adjoint %s formulation - %s' % (fdemType, comp)
|
||||
print('Adjoint %s formulation - %s' % (fdemType, comp))
|
||||
|
||||
m = np.log(np.ones(prb.mapping.nP)*CONDUCTIVITY)
|
||||
mu = np.ones(prb.mesh.nC)*MU
|
||||
@@ -39,7 +46,7 @@ def adjointTest(fdemType, comp):
|
||||
vJw = v.dot(prb.Jvec(m, w, u))
|
||||
wJtv = w.dot(prb.Jtvec(m, v, u))
|
||||
tol = np.max([TOL*(10**int(np.log10(np.abs(vJw)))),FLR])
|
||||
print vJw, wJtv, vJw - wJtv, tol, np.abs(vJw - wJtv) < tol
|
||||
print(vJw, wJtv, vJw - wJtv, tol, np.abs(vJw - wJtv) < tol)
|
||||
return np.abs(vJw - wJtv) < tol
|
||||
|
||||
class FDEM_AdjointTests(unittest.TestCase):
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
if __name__ == '__main__':
|
||||
import os
|
||||
import glob
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import division
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
import unittest
|
||||
from SimPEG import *
|
||||
from SimPEG import EM
|
||||
@@ -26,7 +32,7 @@ SrcType = ['MagDipole', 'RawVec'] #or 'MAgDipole_Bfield', 'CircularLoop', 'RawVe
|
||||
def derivTest(fdemType, comp):
|
||||
|
||||
prb = getFDEMProblem(fdemType, comp, SrcType, freq)
|
||||
print '%s formulation - %s' % (fdemType, comp)
|
||||
print('%s formulation - %s' % (fdemType, comp))
|
||||
x0 = np.log(np.ones(prb.mapping.nP)*CONDUCTIVITY)
|
||||
mu = np.log(np.ones(prb.mesh.nC)*MU)
|
||||
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
import os
|
||||
import glob
|
||||
import unittest
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
from past.utils import old_div
|
||||
import unittest
|
||||
from SimPEG import Mesh, Utils, EM, Maps, np
|
||||
import SimPEG.EM.Static.DC as DC
|
||||
@@ -32,7 +39,7 @@ class DCProblemAnalyticTests(unittest.TestCase):
|
||||
try:
|
||||
from pymatsolver import MumpsSolver
|
||||
self.Solver = MumpsSolver
|
||||
except ImportError, e:
|
||||
except ImportError as e:
|
||||
self.Solver = SolverLU
|
||||
|
||||
def test_Problem3D_N(self):
|
||||
@@ -41,13 +48,13 @@ class DCProblemAnalyticTests(unittest.TestCase):
|
||||
problem.Solver = self.Solver
|
||||
problem.pair(self.survey)
|
||||
data = self.survey.dpred(self.sigma)
|
||||
err= np.linalg.norm((data-self.data_anal)/self.data_anal)**2 / self.data_anal.size
|
||||
err= old_div(np.linalg.norm(old_div((data-self.data_anal),self.data_anal))**2, self.data_anal.size)
|
||||
if err < 0.05:
|
||||
passed = True
|
||||
print ">> DC analytic test for Problem3D_N is passed"
|
||||
print(">> DC analytic test for Problem3D_N is passed")
|
||||
else:
|
||||
passed = False
|
||||
print ">> DC analytic test for Problem3D_N is failed"
|
||||
print(">> DC analytic test for Problem3D_N is failed")
|
||||
self.assertTrue(passed)
|
||||
|
||||
def test_Problem3D_CC(self):
|
||||
@@ -55,13 +62,13 @@ class DCProblemAnalyticTests(unittest.TestCase):
|
||||
problem.Solver = self.Solver
|
||||
problem.pair(self.survey)
|
||||
data = self.survey.dpred(self.sigma)
|
||||
err= np.linalg.norm((data-self.data_anal)/self.data_anal)**2 / self.data_anal.size
|
||||
err= old_div(np.linalg.norm(old_div((data-self.data_anal),self.data_anal))**2, self.data_anal.size)
|
||||
if err < 0.05:
|
||||
passed = True
|
||||
print ">> DC analytic test for Problem3D_CC is passed"
|
||||
print(">> DC analytic test for Problem3D_CC is passed")
|
||||
else:
|
||||
passed = False
|
||||
print ">> DC analytic test for Problem3D_CC is failed"
|
||||
print(">> DC analytic test for Problem3D_CC is failed")
|
||||
self.assertTrue(passed)
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import division
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
import unittest
|
||||
from SimPEG import *
|
||||
import SimPEG.EM.Static.DC as DC
|
||||
@@ -55,7 +61,7 @@ class DCProblem_2DTestsCC(unittest.TestCase):
|
||||
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
|
||||
print('Adjoint Test', np.abs(wtJv - vtJtw), passed)
|
||||
self.assertTrue(passed)
|
||||
|
||||
def test_dataObj(self):
|
||||
@@ -115,7 +121,7 @@ class DCProblemTestsN(unittest.TestCase):
|
||||
wtJv = w.dot(self.p.Jvec(self.m0, v))
|
||||
vtJtw = v.dot(self.p.Jtvec(self.m0, w))
|
||||
passed = np.abs(wtJv - vtJtw) < 1e-8
|
||||
print 'Adjoint Test', np.abs(wtJv - vtJtw), passed
|
||||
print('Adjoint Test', np.abs(wtJv - vtJtw), passed)
|
||||
self.assertTrue(passed)
|
||||
|
||||
def test_dataObj(self):
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
from past.utils import old_div
|
||||
import unittest
|
||||
from SimPEG import Mesh, Utils, EM, Maps, np
|
||||
import SimPEG.EM.Static.DC as DC
|
||||
@@ -35,7 +42,7 @@ class DCProblemAnalyticTests(unittest.TestCase):
|
||||
try:
|
||||
from pymatsolver import MumpsSolver
|
||||
self.Solver = MumpsSolver
|
||||
except ImportError, e:
|
||||
except ImportError as e:
|
||||
self.Solver = SolverLU
|
||||
|
||||
def test_Problem3D_N(self):
|
||||
@@ -43,13 +50,13 @@ class DCProblemAnalyticTests(unittest.TestCase):
|
||||
problem.Solver = self.Solver
|
||||
problem.pair(self.survey)
|
||||
data = self.survey.dpred(self.sigma)
|
||||
err= np.linalg.norm(data-self.data_anal)/np.linalg.norm(self.data_anal)
|
||||
err= old_div(np.linalg.norm(data-self.data_anal),np.linalg.norm(self.data_anal))
|
||||
if err < 0.2:
|
||||
passed = True
|
||||
print ">> DC analytic test for Problem3D_N is passed"
|
||||
print(">> DC analytic test for Problem3D_N is passed")
|
||||
else:
|
||||
passed = False
|
||||
print ">> DC analytic test for Problem3D_N is failed"
|
||||
print(">> DC analytic test for Problem3D_N is failed")
|
||||
self.assertTrue(passed)
|
||||
|
||||
def test_Problem3D_CC(self):
|
||||
@@ -57,13 +64,13 @@ class DCProblemAnalyticTests(unittest.TestCase):
|
||||
problem.Solver = self.Solver
|
||||
problem.pair(self.survey)
|
||||
data = self.survey.dpred(self.sigma)
|
||||
err= np.linalg.norm(data-self.data_anal)/np.linalg.norm(self.data_anal)
|
||||
err= old_div(np.linalg.norm(data-self.data_anal),np.linalg.norm(self.data_anal))
|
||||
if err < 0.2:
|
||||
passed = True
|
||||
print ">> DC analytic test for Problem3D_CC is passed"
|
||||
print(">> DC analytic test for Problem3D_CC is passed")
|
||||
else:
|
||||
passed = False
|
||||
print ">> DC analytic test for Problem3D_CC is failed"
|
||||
print(">> DC analytic test for Problem3D_CC is failed")
|
||||
self.assertTrue(passed)
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
from past.utils import old_div
|
||||
import unittest
|
||||
from SimPEG import *
|
||||
import SimPEG.EM.Static.DC as DC
|
||||
@@ -14,7 +21,7 @@ class DCProblemTestsCC(unittest.TestCase):
|
||||
cs = surveySize/nElecs/4
|
||||
|
||||
mesh = Mesh.TensorMesh([
|
||||
[(cs,10, -1.3),(cs,surveySize/cs),(cs,10, 1.3)],
|
||||
[(cs,10, -1.3),(cs,old_div(surveySize,cs)),(cs,10, 1.3)],
|
||||
[(cs,3, -1.3),(cs,3,1.3)],
|
||||
# [(cs,5, -1.3),(cs,10)]
|
||||
],'CN')
|
||||
@@ -55,7 +62,7 @@ class DCProblemTestsCC(unittest.TestCase):
|
||||
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
|
||||
print('Adjoint Test', np.abs(wtJv - vtJtw), passed)
|
||||
self.assertTrue(passed)
|
||||
|
||||
def test_dataObj(self):
|
||||
@@ -74,7 +81,7 @@ class DCProblemTestsN(unittest.TestCase):
|
||||
cs = surveySize/nElecs/4
|
||||
|
||||
mesh = Mesh.TensorMesh([
|
||||
[(cs,10, -1.3),(cs,surveySize/cs),(cs,10, 1.3)],
|
||||
[(cs,10, -1.3),(cs,old_div(surveySize,cs)),(cs,10, 1.3)],
|
||||
[(cs,3, -1.3),(cs,3,1.3)],
|
||||
# [(cs,5, -1.3),(cs,10)]
|
||||
],'CN')
|
||||
@@ -115,7 +122,7 @@ class DCProblemTestsN(unittest.TestCase):
|
||||
wtJv = w.dot(self.p.Jvec(self.m0, v))
|
||||
vtJtw = v.dot(self.p.Jtvec(self.m0, w))
|
||||
passed = np.abs(wtJv - vtJtw) < 1e-8
|
||||
print 'Adjoint Test', np.abs(wtJv - vtJtw), passed
|
||||
print('Adjoint Test', np.abs(wtJv - vtJtw), passed)
|
||||
self.assertTrue(passed)
|
||||
|
||||
def test_dataObj(self):
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
from past.utils import old_div
|
||||
import unittest
|
||||
from SimPEG import Mesh, Utils, EM, Maps, np
|
||||
import SimPEG.EM.Static.DC as DC
|
||||
@@ -42,7 +49,7 @@ class IPProblemAnalyticTests(unittest.TestCase):
|
||||
try:
|
||||
from pymatsolver import MumpsSolver
|
||||
self.Solver = MumpsSolver
|
||||
except ImportError, e:
|
||||
except ImportError as e:
|
||||
self.Solver = SolverLU
|
||||
|
||||
def test_Problem3D_N(self):
|
||||
@@ -59,13 +66,13 @@ class IPProblemAnalyticTests(unittest.TestCase):
|
||||
problemIP.pair(surveyIP)
|
||||
data_full = data0 - datainf
|
||||
data = surveyIP.dpred(self.eta)
|
||||
err= np.linalg.norm((data-data_full)/data_full)**2 / data_full.size
|
||||
err= old_div(np.linalg.norm(old_div((data-data_full),data_full))**2, data_full.size)
|
||||
if err < 0.05:
|
||||
passed = True
|
||||
print ">> IP forward test for Problem3D_N is passed"
|
||||
print(">> IP forward test for Problem3D_N is passed")
|
||||
else:
|
||||
passed = False
|
||||
print ">> IP forward test for Problem3D_N is failed"
|
||||
print(">> IP forward test for Problem3D_N is failed")
|
||||
self.assertTrue(passed)
|
||||
|
||||
def test_Problem3D_CC(self):
|
||||
@@ -76,19 +83,19 @@ class IPProblemAnalyticTests(unittest.TestCase):
|
||||
data0 = self.surveyDC.dpred(self.sigma0)
|
||||
finf = problemDC.fields(self.sigmaInf)
|
||||
datainf = self.surveyDC.dpred(self.sigmaInf, f=finf)
|
||||
problemIP = IP.Problem3D_CC(self.mesh, rho=1./self.sigmaInf, Ainv=problemDC.Ainv, f=finf)
|
||||
problemIP = IP.Problem3D_CC(self.mesh, rho=old_div(1.,self.sigmaInf), Ainv=problemDC.Ainv, f=finf)
|
||||
problemIP.Solver = self.Solver
|
||||
surveyIP = IP.Survey([self.src])
|
||||
problemIP.pair(surveyIP)
|
||||
data_full = data0 - datainf
|
||||
data = surveyIP.dpred(self.eta)
|
||||
err= np.linalg.norm((data-data_full)/data_full)**2 / data_full.size
|
||||
err= old_div(np.linalg.norm(old_div((data-data_full),data_full))**2, data_full.size)
|
||||
if err < 0.05:
|
||||
passed = True
|
||||
print ">> IP forward test for Problem3D_CC is passed"
|
||||
print(">> IP forward test for Problem3D_CC is passed")
|
||||
else:
|
||||
passed = False
|
||||
print ">> IP forward test for Problem3D_CC is failed"
|
||||
print(">> IP forward test for Problem3D_CC is failed")
|
||||
self.assertTrue(passed)
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
from past.utils import old_div
|
||||
import unittest
|
||||
from SimPEG import *
|
||||
import SimPEG.EM.Static.DC as DC
|
||||
@@ -15,7 +22,7 @@ class IPProblemTestsCC(unittest.TestCase):
|
||||
cs = surveySize/nElecs/4
|
||||
|
||||
mesh = Mesh.TensorMesh([
|
||||
[(cs,10, -1.3),(cs,surveySize/cs),(cs,10, 1.3)],
|
||||
[(cs,10, -1.3),(cs,old_div(surveySize,cs)),(cs,10, 1.3)],
|
||||
[(cs,3, -1.3),(cs,3,1.3)],
|
||||
# [(cs,5, -1.3),(cs,10)]
|
||||
],'CN')
|
||||
@@ -23,7 +30,7 @@ class IPProblemTestsCC(unittest.TestCase):
|
||||
srcList = DC.Utils.WennerSrcList(nElecs, aSpacing, in2D=True)
|
||||
survey = IP.Survey(srcList)
|
||||
sigma = np.ones(mesh.nC)
|
||||
problem = IP.Problem3D_CC(mesh, rho=1./sigma)
|
||||
problem = IP.Problem3D_CC(mesh, rho=old_div(1.,sigma))
|
||||
problem.pair(survey)
|
||||
mSynth = np.ones(mesh.nC)*0.1
|
||||
survey.makeSyntheticData(mSynth)
|
||||
@@ -55,7 +62,7 @@ class IPProblemTestsCC(unittest.TestCase):
|
||||
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
|
||||
print('Adjoint Test', np.abs(wtJv - vtJtw), passed)
|
||||
self.assertTrue(passed)
|
||||
|
||||
def test_dataObj(self):
|
||||
@@ -74,7 +81,7 @@ class IPProblemTestsN(unittest.TestCase):
|
||||
cs = surveySize/nElecs/4
|
||||
|
||||
mesh = Mesh.TensorMesh([
|
||||
[(cs,10, -1.3),(cs,surveySize/cs),(cs,10, 1.3)],
|
||||
[(cs,10, -1.3),(cs,old_div(surveySize,cs)),(cs,10, 1.3)],
|
||||
[(cs,3, -1.3),(cs,3,1.3)],
|
||||
# [(cs,5, -1.3),(cs,10)]
|
||||
],'CN')
|
||||
@@ -114,7 +121,7 @@ class IPProblemTestsN(unittest.TestCase):
|
||||
wtJv = w.dot(self.p.Jvec(self.m0, v))
|
||||
vtJtw = v.dot(self.p.Jtvec(self.m0, w))
|
||||
passed = np.abs(wtJv - vtJtw) < 1e-8
|
||||
print 'Adjoint Test', np.abs(wtJv - vtJtw), passed
|
||||
print('Adjoint Test', np.abs(wtJv - vtJtw), passed)
|
||||
self.assertTrue(passed)
|
||||
|
||||
def test_dataObj(self):
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import absolute_import
|
||||
from builtins import int
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
from past.utils import old_div
|
||||
import unittest
|
||||
from SimPEG import *
|
||||
import SimPEG
|
||||
@@ -37,10 +45,10 @@ class IPProblemTestsCC(unittest.TestCase):
|
||||
src = SIP.Src.Dipole([rx], Aloc, Bloc)
|
||||
survey = SIP.Survey([src])
|
||||
colemap = [("eta", Maps.IdentityMap(mesh)), ("taui", Maps.IdentityMap(mesh))]
|
||||
problem = SIP.Problem3D_CC(mesh, rho=1./sigma, mapping=colemap)
|
||||
problem = SIP.Problem3D_CC(mesh, rho=old_div(1.,sigma), mapping=colemap)
|
||||
problem.Solver = MumpsSolver
|
||||
problem.pair(survey)
|
||||
mSynth = np.r_[eta, 1./tau]
|
||||
mSynth = np.r_[eta, old_div(1.,tau)]
|
||||
survey.makeSyntheticData(mSynth)
|
||||
# Now set up the problem to do some minimization
|
||||
dmis = DataMisfit.l2_DataMisfit(survey)
|
||||
@@ -70,7 +78,7 @@ class IPProblemTestsCC(unittest.TestCase):
|
||||
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
|
||||
print('Adjoint Test', np.abs(wtJv - vtJtw), passed)
|
||||
self.assertTrue(passed)
|
||||
|
||||
def test_dataObj(self):
|
||||
@@ -112,7 +120,7 @@ class IPProblemTestsN(unittest.TestCase):
|
||||
problem = SIP.Problem3D_N(mesh, sigma=sigma, mapping=colemap)
|
||||
problem.Solver = MumpsSolver
|
||||
problem.pair(survey)
|
||||
mSynth = np.r_[eta, 1./tau]
|
||||
mSynth = np.r_[eta, old_div(1.,tau)]
|
||||
survey.makeSyntheticData(mSynth)
|
||||
# Now set up the problem to do some minimization
|
||||
dmis = DataMisfit.l2_DataMisfit(survey)
|
||||
@@ -142,7 +150,7 @@ class IPProblemTestsN(unittest.TestCase):
|
||||
wtJv = w.dot(self.p.Jvec(self.m0, v))
|
||||
vtJtw = v.dot(self.p.Jtvec(self.m0, w))
|
||||
passed = np.abs(wtJv - vtJtw) < 1e-8
|
||||
print 'Adjoint Test', np.abs(wtJv - vtJtw), passed
|
||||
print('Adjoint Test', np.abs(wtJv - vtJtw), passed)
|
||||
self.assertTrue(passed)
|
||||
|
||||
def test_dataObj(self):
|
||||
@@ -189,7 +197,7 @@ class IPProblemTestsN_air(unittest.TestCase):
|
||||
problem = SIP.Problem3D_N(mesh, sigma=sigma, mapping=colemap)
|
||||
problem.Solver = MumpsSolver
|
||||
problem.pair(survey)
|
||||
mSynth = np.r_[eta[~airind], 1./tau[~airind]]
|
||||
mSynth = np.r_[eta[~airind], old_div(1.,tau[~airind])]
|
||||
survey.makeSyntheticData(mSynth)
|
||||
# Now set up the problem to do some minimization
|
||||
dmis = DataMisfit.l2_DataMisfit(survey)
|
||||
@@ -220,7 +228,7 @@ class IPProblemTestsN_air(unittest.TestCase):
|
||||
wtJv = w.dot(self.p.Jvec(self.m0, v))
|
||||
vtJtw = v.dot(self.p.Jtvec(self.m0, w))
|
||||
passed = np.abs(wtJv - vtJtw) < 1e-8
|
||||
print 'Adjoint Test', np.abs(wtJv - vtJtw), passed
|
||||
print('Adjoint Test', np.abs(wtJv - vtJtw), passed)
|
||||
self.assertTrue(passed)
|
||||
|
||||
def test_dataObj(self):
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
if __name__ == '__main__':
|
||||
import os
|
||||
import glob
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
from builtins import range
|
||||
from past.utils import old_div
|
||||
import unittest
|
||||
from SimPEG import *
|
||||
from SimPEG import EM
|
||||
@@ -35,7 +43,7 @@ class TDEM_bDerivTests(unittest.TestCase):
|
||||
try:
|
||||
from pymatsolver import MumpsSolver
|
||||
self.prb.Solver = MumpsSolver
|
||||
except ImportError, e:
|
||||
except ImportError as e:
|
||||
self.prb.Solver = SolverLU
|
||||
|
||||
self.sigma = np.ones(mesh.nCz)*1e-8
|
||||
@@ -58,7 +66,7 @@ class TDEM_bDerivTests(unittest.TestCase):
|
||||
|
||||
V1 = Ahu[:,'b',1]
|
||||
V2 = 1./prb.timeSteps[0]*prb.MfMui*u[:,'b',0]
|
||||
self.assertLess(np.linalg.norm(V1-V2)/np.linalg.norm(V2), 1.e-6)
|
||||
self.assertLess(old_div(np.linalg.norm(V1-V2),np.linalg.norm(V2)), 1.e-6)
|
||||
|
||||
V1 = Ahu[:,'e',1]
|
||||
return np.linalg.norm(V1) < 1.e-6
|
||||
@@ -70,12 +78,12 @@ class TDEM_bDerivTests(unittest.TestCase):
|
||||
V1 = Ahu[:,'b',i]
|
||||
V2 = 1.0/dt*prb.MfMui*u[:,'b', i-1]
|
||||
# print np.linalg.norm(V1), np.linalg.norm(V2)
|
||||
self.assertLess(np.linalg.norm(V1)/np.linalg.norm(V2), 1.e-6)
|
||||
self.assertLess(old_div(np.linalg.norm(V1),np.linalg.norm(V2)), 1.e-6)
|
||||
|
||||
V1 = Ahu[:,'e',i]
|
||||
V2 = prb.MeSigma*u[:,'e',i]
|
||||
# print np.linalg.norm(V1), np.linalg.norm(V2)
|
||||
return np.linalg.norm(V1)/np.linalg.norm(V2), 1.e-6
|
||||
return old_div(np.linalg.norm(V1),np.linalg.norm(V2)), 1.e-6
|
||||
|
||||
def test_AhVecVSMat_OneTS(self):
|
||||
|
||||
@@ -95,7 +103,7 @@ class TDEM_bDerivTests(unittest.TestCase):
|
||||
u1 = A*f.tovec()
|
||||
u2 = prb._AhVec(sigma,f).tovec()
|
||||
|
||||
self.assertTrue(np.linalg.norm(u1-u2)/np.linalg.norm(u1)<1e-12)
|
||||
self.assertTrue(old_div(np.linalg.norm(u1-u2),np.linalg.norm(u1))<1e-12)
|
||||
|
||||
def test_solveAhVSMat_OneTS(self):
|
||||
prb = self.prb
|
||||
@@ -155,7 +163,7 @@ class TDEM_bDerivTests(unittest.TestCase):
|
||||
h = 0.01
|
||||
|
||||
derChk = lambda m: [self.prb._AhVec(m, f).tovec(), lambda mx: self.prb.Gvec(sigma, mx, u=f).tovec()]
|
||||
print '\ntest_DerivG'
|
||||
print('\ntest_DerivG')
|
||||
passed = Tests.checkDerivative(derChk, sigma, plotIt=False, dx=dm, num=4, eps=1e-20)
|
||||
return passed
|
||||
|
||||
@@ -170,8 +178,8 @@ class TDEM_bDerivTests(unittest.TestCase):
|
||||
f = prb.fields(sigma)
|
||||
|
||||
derChk = lambda m: [self.prb.fields(m).tovec(), lambda mx: -prb.solveAh(sigma, prb.Gvec(sigma, mx, u=f)).tovec()]
|
||||
print '\n'
|
||||
print 'test_Deriv_dUdM'
|
||||
print('\n')
|
||||
print('test_Deriv_dUdM')
|
||||
Tests.checkDerivative(derChk, sigma, plotIt=False, dx=dm, num=4, eps=1e-20)
|
||||
|
||||
def test_Deriv_J(self):
|
||||
@@ -186,8 +194,8 @@ class TDEM_bDerivTests(unittest.TestCase):
|
||||
|
||||
|
||||
derChk = lambda m: [prb.survey.dpred(m), lambda mx: prb.Jvec(sigma, mx)]
|
||||
print '\n'
|
||||
print 'test_Deriv_J'
|
||||
print('\n')
|
||||
print('test_Deriv_J')
|
||||
Tests.checkDerivative(derChk, sigma, plotIt=False, dx=d_sig, num=4, eps=1e-20)
|
||||
|
||||
def test_projectAdjoint(self):
|
||||
@@ -207,7 +215,7 @@ class TDEM_bDerivTests(unittest.TestCase):
|
||||
V1 = d_vec.dot(survey.evalDeriv(None, v=f).tovec())
|
||||
V2 = f.tovec().dot(survey.evalDeriv(None, v=d, adjoint=True).tovec())
|
||||
|
||||
self.assertTrue((V1-V2)/np.abs(V1) < tol)
|
||||
self.assertTrue(old_div((V1-V2),np.abs(V1)) < tol)
|
||||
|
||||
def test_adjointAhVsAht(self):
|
||||
prb = self.prb
|
||||
@@ -226,7 +234,7 @@ class TDEM_bDerivTests(unittest.TestCase):
|
||||
|
||||
V1 = f2.tovec().dot(prb._AhVec(sigma, f1).tovec())
|
||||
V2 = f1.tovec().dot(prb._AhtVec(sigma, f2).tovec())
|
||||
self.assertTrue(np.abs(V1-V2)/np.abs(V1) < tol)
|
||||
self.assertTrue(old_div(np.abs(V1-V2),np.abs(V1)) < tol)
|
||||
|
||||
# def test_solveAhtVsAhtVec(self):
|
||||
# prb = self.prb
|
||||
@@ -291,7 +299,7 @@ class TDEM_bDerivTests(unittest.TestCase):
|
||||
|
||||
V1 = m.dot(prb.Gtvec(sigma, v, u))
|
||||
V2 = v.tovec().dot(prb.Gvec(sigma, m, u).tovec())
|
||||
self.assertTrue(np.abs(V1-V2)/np.abs(V1) < tol)
|
||||
self.assertTrue(old_div(np.abs(V1-V2),np.abs(V1)) < tol)
|
||||
|
||||
def test_adjointJvecVsJtvec(self):
|
||||
mesh = self.mesh
|
||||
@@ -303,8 +311,8 @@ class TDEM_bDerivTests(unittest.TestCase):
|
||||
|
||||
V1 = d.dot(prb.Jvec(sigma, m))
|
||||
V2 = m.dot(prb.Jtvec(sigma, d))
|
||||
passed = np.abs(V1-V2)/np.abs(V1) < tol
|
||||
print 'AdjointTest', V1, V2, passed
|
||||
passed = old_div(np.abs(V1-V2),np.abs(V1)) < tol
|
||||
print('AdjointTest', V1, V2, passed)
|
||||
self.assertTrue(passed)
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
from builtins import range
|
||||
from past.utils import old_div
|
||||
import unittest
|
||||
from SimPEG import *
|
||||
from SimPEG import EM
|
||||
@@ -36,7 +44,7 @@ class TDEM_bDerivTests(unittest.TestCase):
|
||||
try:
|
||||
from pymatsolver import MumpsSolver
|
||||
self.prb.Solver = MumpsSolver
|
||||
except ImportError, e:
|
||||
except ImportError as e:
|
||||
self.prb.Solver = SolverLU
|
||||
|
||||
self.sigma = np.ones(mesh.nCz)*1e-8
|
||||
@@ -59,7 +67,7 @@ class TDEM_bDerivTests(unittest.TestCase):
|
||||
h = 0.01
|
||||
|
||||
derChk = lambda m: [self.prb._AhVec(m, f).tovec(), lambda mx: self.prb.Gvec(sigma, mx, u=f).tovec()]
|
||||
print '\ntest_DerivG'
|
||||
print('\ntest_DerivG')
|
||||
Tests.checkDerivative(derChk, sigma, plotIt=False, dx=dm, num=4, eps=1e-20)
|
||||
|
||||
def test_Deriv_dUdM(self):
|
||||
@@ -73,8 +81,8 @@ class TDEM_bDerivTests(unittest.TestCase):
|
||||
f = prb.fields(sigma)
|
||||
|
||||
derChk = lambda m: [self.prb.fields(m).tovec(), lambda mx: -prb.solveAh(sigma, prb.Gvec(sigma, mx, u=f)).tovec()]
|
||||
print '\n'
|
||||
print 'test_Deriv_dUdM'
|
||||
print('\n')
|
||||
print('test_Deriv_dUdM')
|
||||
Tests.checkDerivative(derChk, sigma, plotIt=False, dx=dm, num=4, eps=1e-20)
|
||||
|
||||
def test_Deriv_J(self):
|
||||
@@ -89,8 +97,8 @@ class TDEM_bDerivTests(unittest.TestCase):
|
||||
|
||||
|
||||
derChk = lambda m: [prb.survey.dpred(m), lambda mx: prb.Jvec(sigma, mx)]
|
||||
print '\n'
|
||||
print 'test_Deriv_J'
|
||||
print('\n')
|
||||
print('test_Deriv_J')
|
||||
Tests.checkDerivative(derChk, sigma, plotIt=False, dx=d_sig, num=4, eps=1e-20)
|
||||
|
||||
def test_projectAdjoint(self):
|
||||
@@ -111,7 +119,7 @@ class TDEM_bDerivTests(unittest.TestCase):
|
||||
V1 = d_vec.dot(survey.evalDeriv(None, v=f).tovec())
|
||||
V2 = np.sum((f.tovec())*(survey.evalDeriv(None, v=d, adjoint=True).tovec()))
|
||||
|
||||
self.assertTrue((V1-V2)/np.abs(V1) < 1e-6)
|
||||
self.assertTrue(old_div((V1-V2),np.abs(V1)) < 1e-6)
|
||||
|
||||
def test_adjointGvecVsGtvec(self):
|
||||
mesh = self.mesh
|
||||
@@ -132,7 +140,7 @@ class TDEM_bDerivTests(unittest.TestCase):
|
||||
|
||||
V1 = m.dot(prb.Gtvec(sigma, v, u))
|
||||
V2 = np.sum(v.tovec()*prb.Gvec(sigma, m, u).tovec())
|
||||
self.assertTrue(np.abs(V1-V2)/np.abs(V1) <1e-6)
|
||||
self.assertTrue(old_div(np.abs(V1-V2),np.abs(V1)) <1e-6)
|
||||
|
||||
def test_adjointJvecVsJtvec(self):
|
||||
mesh = self.mesh
|
||||
@@ -144,8 +152,8 @@ class TDEM_bDerivTests(unittest.TestCase):
|
||||
|
||||
V1 = d.dot(prb.Jvec(sigma, m))
|
||||
V2 = m.dot(prb.Jtvec(sigma, d))
|
||||
print 'AdjointTest', V1, V2
|
||||
self.assertTrue(np.abs(V1-V2)/np.abs(V1) < 1e-6)
|
||||
print('AdjointTest', V1, V2)
|
||||
self.assertTrue(old_div(np.abs(V1-V2),np.abs(V1)) < 1e-6)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
from builtins import range
|
||||
from past.utils import old_div
|
||||
import unittest
|
||||
from SimPEG import *
|
||||
from SimPEG import EM
|
||||
@@ -34,7 +42,7 @@ def getProb(meshType='CYL',rxTypes='bx,bz',nSrc=1):
|
||||
try:
|
||||
from pymatsolver import MumpsSolver
|
||||
prb.Solver = MumpsSolver
|
||||
except ImportError, e:
|
||||
except ImportError as e:
|
||||
prb.Solver = SolverLU
|
||||
|
||||
sigma = np.ones(mesh.nCz)*1e-8
|
||||
@@ -57,8 +65,8 @@ def dotestAdjoint(prb, mesh, sigma):
|
||||
|
||||
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
|
||||
print('AdjointTest', V1, V2)
|
||||
return old_div(np.abs(V1-V2),np.abs(V1)), 1e-6
|
||||
|
||||
class TDEM_bDerivTests(unittest.TestCase):
|
||||
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
from past.utils import old_div
|
||||
import unittest
|
||||
from SimPEG import *
|
||||
from SimPEG import EM
|
||||
@@ -6,7 +13,7 @@ import matplotlib.pyplot as plt
|
||||
|
||||
try:
|
||||
from pymatsolver import MumpsSolver
|
||||
except ImportError, e:
|
||||
except ImportError as e:
|
||||
MumpsSolver = SolverLU
|
||||
|
||||
|
||||
@@ -49,8 +56,8 @@ def halfSpaceProblemAnaDiff(meshType, sig_half=1e-2, rxOffset=50., bounds=None,
|
||||
bz_calc = survey.dpred(sigma)
|
||||
|
||||
ind = np.logical_and(rx.times > bounds[0],rx.times < bounds[1])
|
||||
log10diff = np.linalg.norm(np.log10(np.abs(bz_calc[ind])) - np.log10(np.abs(bz_ana[ind])))/np.linalg.norm(np.log10(np.abs(bz_ana[ind])))
|
||||
print 'Difference: ', log10diff
|
||||
log10diff = old_div(np.linalg.norm(np.log10(np.abs(bz_calc[ind])) - np.log10(np.abs(bz_ana[ind]))),np.linalg.norm(np.log10(np.abs(bz_ana[ind]))))
|
||||
print('Difference: ', log10diff)
|
||||
|
||||
if showIt == True:
|
||||
plt.loglog(rx.times[bz_calc>0], bz_calc[bz_calc>0], 'r', rx.times[bz_calc<0], -bz_calc[bz_calc<0], 'r--')
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
if __name__ == '__main__':
|
||||
import os
|
||||
import glob
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import division
|
||||
from __future__ import absolute_import
|
||||
from builtins import dict
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
import unittest
|
||||
import sys
|
||||
import os
|
||||
@@ -6,7 +13,7 @@ import numpy as np
|
||||
|
||||
class compareInitFiles(unittest.TestCase):
|
||||
def test_compareInitFiles(self):
|
||||
print 'Checking that __init__.py up-to-date in SimPEG/Examples'
|
||||
print('Checking that __init__.py up-to-date in SimPEG/Examples')
|
||||
fName = os.path.abspath(__file__)
|
||||
ExamplesDir = os.path.sep.join(fName.split(os.path.sep)[:-3] + ['SimPEG', 'Examples'])
|
||||
|
||||
@@ -17,7 +24,7 @@ class compareInitFiles(unittest.TestCase):
|
||||
|
||||
setdiff = set(pyfiles) - set(Examples.__examples__)
|
||||
|
||||
print ' Any missing files? ', setdiff
|
||||
print(' Any missing files? ', setdiff)
|
||||
|
||||
didpass = (setdiff == set())
|
||||
|
||||
@@ -25,7 +32,7 @@ class compareInitFiles(unittest.TestCase):
|
||||
|
||||
def get(test):
|
||||
def test_func(self):
|
||||
print '\nTesting %s.run(plotIt=False)\n'%test
|
||||
print('\nTesting %s.run(plotIt=False)\n'%test)
|
||||
getattr(Examples, test).run(plotIt=False)
|
||||
self.assertTrue(True)
|
||||
return test_func
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
if __name__ == '__main__':
|
||||
import os
|
||||
import glob
|
||||
|
||||
+19
-12
@@ -1,3 +1,10 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import division
|
||||
from __future__ import absolute_import
|
||||
from builtins import int
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
import unittest
|
||||
from SimPEG import *
|
||||
from SimPEG.Tests import OrderTest, checkDerivative
|
||||
@@ -6,7 +13,7 @@ from SimPEG.FLOW import Richards
|
||||
try:
|
||||
from pymatsolver import MumpsSolver
|
||||
Solver = MumpsSolver
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
pass
|
||||
|
||||
|
||||
@@ -120,14 +127,14 @@ class RichardsTests1D(unittest.TestCase):
|
||||
zJv = z.dot(self.prob.Jtvec(self.Ks,v,f=Hs))
|
||||
tol = TOL*(10**int(np.log10(np.abs(zJv))))
|
||||
passed = np.abs(vJz - zJv) < tol
|
||||
print 'Richards Adjoint Test - PressureHead'
|
||||
print '%4.4e === %4.4e, diff=%4.4e < %4.e'%(vJz, zJv,np.abs(vJz - zJv),tol)
|
||||
print('Richards Adjoint Test - PressureHead')
|
||||
print('%4.4e === %4.4e, diff=%4.4e < %4.e'%(vJz, zJv,np.abs(vJz - zJv),tol))
|
||||
self.assertTrue(passed,True)
|
||||
|
||||
def test_Sensitivity(self):
|
||||
mTrue = self.Ks*np.ones(self.M.nC)
|
||||
derChk = lambda m: [self.survey.dpred(m), lambda v: self.prob.Jvec(m, v)]
|
||||
print 'Testing Richards Derivative'
|
||||
print('Testing Richards Derivative')
|
||||
passed = checkDerivative(derChk, mTrue, num=4, plotIt=False)
|
||||
self.assertTrue(passed,True)
|
||||
|
||||
@@ -136,7 +143,7 @@ class RichardsTests1D(unittest.TestCase):
|
||||
mTrue = self.Ks*np.ones(self.M.nC)
|
||||
J = self.prob.Jfull(mTrue)
|
||||
derChk = lambda m: [self.survey.dpred(m), J]
|
||||
print 'Testing Richards Derivative FULL'
|
||||
print('Testing Richards Derivative FULL')
|
||||
passed = checkDerivative(derChk, mTrue, num=4, plotIt=False)
|
||||
self.assertTrue(passed,True)
|
||||
|
||||
@@ -192,14 +199,14 @@ class RichardsTests2D(unittest.TestCase):
|
||||
zJv = z.dot(self.prob.Jtvec(self.Ks,v,f=Hs))
|
||||
tol = TOL*(10**int(np.log10(np.abs(zJv))))
|
||||
passed = np.abs(vJz - zJv) < tol
|
||||
print '2D: Richards Adjoint Test - PressureHead'
|
||||
print '%4.4e === %4.4e, diff=%4.4e < %4.e'%(vJz, zJv,np.abs(vJz - zJv),tol)
|
||||
print('2D: Richards Adjoint Test - PressureHead')
|
||||
print('%4.4e === %4.4e, diff=%4.4e < %4.e'%(vJz, zJv,np.abs(vJz - zJv),tol))
|
||||
self.assertTrue(passed,True)
|
||||
|
||||
def test_Sensitivity(self):
|
||||
mTrue = self.Ks*np.ones(self.M.nC)
|
||||
derChk = lambda m: [self.survey.dpred(m), lambda v: self.prob.Jvec(m, v)]
|
||||
print '2D: Testing Richards Derivative'
|
||||
print('2D: Testing Richards Derivative')
|
||||
passed = checkDerivative(derChk, mTrue, num=3, plotIt=False)
|
||||
self.assertTrue(passed,True)
|
||||
|
||||
@@ -207,7 +214,7 @@ class RichardsTests2D(unittest.TestCase):
|
||||
mTrue = self.Ks*np.ones(self.M.nC)
|
||||
J = self.prob.Jfull(mTrue)
|
||||
derChk = lambda m: [self.survey.dpred(m), J]
|
||||
print '2D: Testing Richards Derivative FULL'
|
||||
print('2D: Testing Richards Derivative FULL')
|
||||
passed = checkDerivative(derChk, mTrue, num=4, plotIt=False)
|
||||
self.assertTrue(passed,True)
|
||||
|
||||
@@ -264,14 +271,14 @@ class RichardsTests3D(unittest.TestCase):
|
||||
zJv = z.dot(self.prob.Jtvec(self.Ks,v,f=Hs))
|
||||
tol = TOL*(10**int(np.log10(np.abs(zJv))))
|
||||
passed = np.abs(vJz - zJv) < tol
|
||||
print '3D: Richards Adjoint Test - PressureHead'
|
||||
print '%4.4e === %4.4e, diff=%4.4e < %4.e'%(vJz, zJv,np.abs(vJz - zJv),tol)
|
||||
print('3D: Richards Adjoint Test - PressureHead')
|
||||
print('%4.4e === %4.4e, diff=%4.4e < %4.e'%(vJz, zJv,np.abs(vJz - zJv),tol))
|
||||
self.assertTrue(passed,True)
|
||||
|
||||
def test_Sensitivity(self):
|
||||
mTrue = self.Ks*np.ones(self.M.nC)
|
||||
derChk = lambda m: [self.survey.dpred(m), lambda v: self.prob.Jvec(m, v)]
|
||||
print '3D: Testing Richards Derivative'
|
||||
print('3D: Testing Richards Derivative')
|
||||
passed = checkDerivative(derChk, mTrue, num=4, plotIt=False)
|
||||
self.assertTrue(passed,True)
|
||||
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
if __name__ == '__main__':
|
||||
import os
|
||||
import glob
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
import numpy as np
|
||||
import unittest
|
||||
from SimPEG.Mesh import TensorMesh, CurvilinearMesh
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import division
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
import numpy as np
|
||||
import unittest, os
|
||||
import SimPEG as simpeg
|
||||
@@ -35,7 +41,7 @@ class TestTensorMeshIO(unittest.TestCase):
|
||||
vec2UBC = mesh.readModelUBC('arange2.txt')
|
||||
assert np.sum(vec + 1 - vec2UBC) == 0
|
||||
|
||||
print 'IO of UBC tensor mesh files is working'
|
||||
print('IO of UBC tensor mesh files is working')
|
||||
os.remove('temp.msh')
|
||||
os.remove('arange.txt')
|
||||
os.remove('arange2.txt')
|
||||
@@ -54,7 +60,7 @@ class TestTensorMeshIO(unittest.TestCase):
|
||||
vecVTK = models['arange.txt']
|
||||
assert np.sum(vec - vecVTK) == 0
|
||||
|
||||
print 'IO of VTR tensor mesh files is working'
|
||||
print('IO of VTR tensor mesh files is working')
|
||||
os.remove('temp.vtr')
|
||||
|
||||
|
||||
@@ -83,7 +89,7 @@ class TestOcTreeMeshIO(unittest.TestCase):
|
||||
assert np.sum(mesh.gridCC - meshUBC.gridCC) == 0
|
||||
assert np.sum(vec - vecUBC) == 0
|
||||
assert np.all(np.array(mesh.h) - np.array(meshUBC.h) == 0)
|
||||
print 'IO of UBC octree files is working'
|
||||
print('IO of UBC octree files is working')
|
||||
os.remove('temp.msh')
|
||||
os.remove('arange.txt')
|
||||
|
||||
@@ -91,7 +97,7 @@ class TestOcTreeMeshIO(unittest.TestCase):
|
||||
mesh = self.mesh
|
||||
vec = np.arange(mesh.nC)
|
||||
mesh.writeVTK('temp.vtu',{'arange':vec})
|
||||
print 'Writing of VTU files is working'
|
||||
print('Writing of VTU files is working')
|
||||
os.remove('temp.vtu')
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
from past.utils import old_div
|
||||
import numpy as np
|
||||
import scipy.sparse as sp
|
||||
import unittest
|
||||
@@ -37,15 +44,15 @@ def getxBCyBC_CC(mesh, alpha, beta, gamma):
|
||||
# h_xm, h_xp = mesh.gridCC[fCCxm], mesh.gridCC[fCCxp]
|
||||
h_xm, h_xp = mesh.hx[0], mesh.hx[-1]
|
||||
|
||||
a_xm = gamma_xm/(0.5*alpha_xm-beta_xm/h_xm)
|
||||
b_xm = (0.5*alpha_xm+beta_xm/h_xm)/(0.5*alpha_xm-beta_xm/h_xm)
|
||||
a_xp = gamma_xp/(0.5*alpha_xp-beta_xp/h_xp)
|
||||
b_xp = (0.5*alpha_xp+beta_xp/h_xp)/(0.5*alpha_xp-beta_xp/h_xp)
|
||||
a_xm = old_div(gamma_xm,(0.5*alpha_xm-old_div(beta_xm,h_xm)))
|
||||
b_xm = old_div((0.5*alpha_xm+old_div(beta_xm,h_xm)),(0.5*alpha_xm-old_div(beta_xm,h_xm)))
|
||||
a_xp = old_div(gamma_xp,(0.5*alpha_xp-old_div(beta_xp,h_xp)))
|
||||
b_xp = old_div((0.5*alpha_xp+old_div(beta_xp,h_xp)),(0.5*alpha_xp-old_div(beta_xp,h_xp)))
|
||||
|
||||
xBC_xm = 0.5*a_xm
|
||||
xBC_xp = 0.5*a_xp/b_xp
|
||||
yBC_xm = 0.5*(1.-b_xm)
|
||||
yBC_xp = 0.5*(1.-1./b_xp)
|
||||
yBC_xp = 0.5*(1.-old_div(1.,b_xp))
|
||||
|
||||
xBC = np.r_[xBC_xm, xBC_xp]
|
||||
yBC = np.r_[yBC_xm, yBC_xp]
|
||||
@@ -68,24 +75,24 @@ def getxBCyBC_CC(mesh, alpha, beta, gamma):
|
||||
h_xm, h_xp = mesh.hx[0]*np.ones_like(alpha_xm), mesh.hx[-1]*np.ones_like(alpha_xp)
|
||||
h_ym, h_yp = mesh.hy[0]*np.ones_like(alpha_ym), mesh.hy[-1]*np.ones_like(alpha_yp)
|
||||
|
||||
a_xm = gamma_xm/(0.5*alpha_xm-beta_xm/h_xm)
|
||||
b_xm = (0.5*alpha_xm+beta_xm/h_xm)/(0.5*alpha_xm-beta_xm/h_xm)
|
||||
a_xp = gamma_xp/(0.5*alpha_xp-beta_xp/h_xp)
|
||||
b_xp = (0.5*alpha_xp+beta_xp/h_xp)/(0.5*alpha_xp-beta_xp/h_xp)
|
||||
a_xm = old_div(gamma_xm,(0.5*alpha_xm-old_div(beta_xm,h_xm)))
|
||||
b_xm = old_div((0.5*alpha_xm+old_div(beta_xm,h_xm)),(0.5*alpha_xm-old_div(beta_xm,h_xm)))
|
||||
a_xp = old_div(gamma_xp,(0.5*alpha_xp-old_div(beta_xp,h_xp)))
|
||||
b_xp = old_div((0.5*alpha_xp+old_div(beta_xp,h_xp)),(0.5*alpha_xp-old_div(beta_xp,h_xp)))
|
||||
|
||||
a_ym = gamma_ym/(0.5*alpha_ym-beta_ym/h_ym)
|
||||
b_ym = (0.5*alpha_ym+beta_ym/h_ym)/(0.5*alpha_ym-beta_ym/h_ym)
|
||||
a_yp = gamma_yp/(0.5*alpha_yp-beta_yp/h_yp)
|
||||
b_yp = (0.5*alpha_yp+beta_yp/h_yp)/(0.5*alpha_yp-beta_yp/h_yp)
|
||||
a_ym = old_div(gamma_ym,(0.5*alpha_ym-old_div(beta_ym,h_ym)))
|
||||
b_ym = old_div((0.5*alpha_ym+old_div(beta_ym,h_ym)),(0.5*alpha_ym-old_div(beta_ym,h_ym)))
|
||||
a_yp = old_div(gamma_yp,(0.5*alpha_yp-old_div(beta_yp,h_yp)))
|
||||
b_yp = old_div((0.5*alpha_yp+old_div(beta_yp,h_yp)),(0.5*alpha_yp-old_div(beta_yp,h_yp)))
|
||||
|
||||
xBC_xm = 0.5*a_xm
|
||||
xBC_xp = 0.5*a_xp/b_xp
|
||||
yBC_xm = 0.5*(1.-b_xm)
|
||||
yBC_xp = 0.5*(1.-1./b_xp)
|
||||
yBC_xp = 0.5*(1.-old_div(1.,b_xp))
|
||||
xBC_ym = 0.5*a_ym
|
||||
xBC_yp = 0.5*a_yp/b_yp
|
||||
yBC_ym = 0.5*(1.-b_ym)
|
||||
yBC_yp = 0.5*(1.-1./b_yp)
|
||||
yBC_yp = 0.5*(1.-old_div(1.,b_yp))
|
||||
|
||||
sortindsfx = np.argsort(np.r_[np.arange(mesh.nFx)[fxm], np.arange(mesh.nFx)[fxp]])
|
||||
sortindsfy = np.argsort(np.r_[np.arange(mesh.nFy)[fym], np.arange(mesh.nFy)[fyp]])
|
||||
@@ -120,33 +127,33 @@ def getxBCyBC_CC(mesh, alpha, beta, gamma):
|
||||
h_ym, h_yp = mesh.hy[0]*np.ones_like(alpha_ym), mesh.hy[-1]*np.ones_like(alpha_yp)
|
||||
h_zm, h_zp = mesh.hz[0]*np.ones_like(alpha_zm), mesh.hz[-1]*np.ones_like(alpha_zp)
|
||||
|
||||
a_xm = gamma_xm/(0.5*alpha_xm-beta_xm/h_xm)
|
||||
b_xm = (0.5*alpha_xm+beta_xm/h_xm)/(0.5*alpha_xm-beta_xm/h_xm)
|
||||
a_xp = gamma_xp/(0.5*alpha_xp-beta_xp/h_xp)
|
||||
b_xp = (0.5*alpha_xp+beta_xp/h_xp)/(0.5*alpha_xp-beta_xp/h_xp)
|
||||
a_xm = old_div(gamma_xm,(0.5*alpha_xm-old_div(beta_xm,h_xm)))
|
||||
b_xm = old_div((0.5*alpha_xm+old_div(beta_xm,h_xm)),(0.5*alpha_xm-old_div(beta_xm,h_xm)))
|
||||
a_xp = old_div(gamma_xp,(0.5*alpha_xp-old_div(beta_xp,h_xp)))
|
||||
b_xp = old_div((0.5*alpha_xp+old_div(beta_xp,h_xp)),(0.5*alpha_xp-old_div(beta_xp,h_xp)))
|
||||
|
||||
a_ym = gamma_ym/(0.5*alpha_ym-beta_ym/h_ym)
|
||||
b_ym = (0.5*alpha_ym+beta_ym/h_ym)/(0.5*alpha_ym-beta_ym/h_ym)
|
||||
a_yp = gamma_yp/(0.5*alpha_yp-beta_yp/h_yp)
|
||||
b_yp = (0.5*alpha_yp+beta_yp/h_yp)/(0.5*alpha_yp-beta_yp/h_yp)
|
||||
a_ym = old_div(gamma_ym,(0.5*alpha_ym-old_div(beta_ym,h_ym)))
|
||||
b_ym = old_div((0.5*alpha_ym+old_div(beta_ym,h_ym)),(0.5*alpha_ym-old_div(beta_ym,h_ym)))
|
||||
a_yp = old_div(gamma_yp,(0.5*alpha_yp-old_div(beta_yp,h_yp)))
|
||||
b_yp = old_div((0.5*alpha_yp+old_div(beta_yp,h_yp)),(0.5*alpha_yp-old_div(beta_yp,h_yp)))
|
||||
|
||||
a_zm = gamma_zm/(0.5*alpha_zm-beta_zm/h_zm)
|
||||
b_zm = (0.5*alpha_zm+beta_zm/h_zm)/(0.5*alpha_zm-beta_zm/h_zm)
|
||||
a_zp = gamma_zp/(0.5*alpha_zp-beta_zp/h_zp)
|
||||
b_zp = (0.5*alpha_zp+beta_zp/h_zp)/(0.5*alpha_zp-beta_zp/h_zp)
|
||||
a_zm = old_div(gamma_zm,(0.5*alpha_zm-old_div(beta_zm,h_zm)))
|
||||
b_zm = old_div((0.5*alpha_zm+old_div(beta_zm,h_zm)),(0.5*alpha_zm-old_div(beta_zm,h_zm)))
|
||||
a_zp = old_div(gamma_zp,(0.5*alpha_zp-old_div(beta_zp,h_zp)))
|
||||
b_zp = old_div((0.5*alpha_zp+old_div(beta_zp,h_zp)),(0.5*alpha_zp-old_div(beta_zp,h_zp)))
|
||||
|
||||
xBC_xm = 0.5*a_xm
|
||||
xBC_xp = 0.5*a_xp/b_xp
|
||||
yBC_xm = 0.5*(1.-b_xm)
|
||||
yBC_xp = 0.5*(1.-1./b_xp)
|
||||
yBC_xp = 0.5*(1.-old_div(1.,b_xp))
|
||||
xBC_ym = 0.5*a_ym
|
||||
xBC_yp = 0.5*a_yp/b_yp
|
||||
yBC_ym = 0.5*(1.-b_ym)
|
||||
yBC_yp = 0.5*(1.-1./b_yp)
|
||||
yBC_yp = 0.5*(1.-old_div(1.,b_yp))
|
||||
xBC_zm = 0.5*a_zm
|
||||
xBC_zp = 0.5*a_zp/b_zp
|
||||
yBC_zm = 0.5*(1.-b_zm)
|
||||
yBC_zp = 0.5*(1.-1./b_zp)
|
||||
yBC_zp = 0.5*(1.-old_div(1.,b_zp))
|
||||
|
||||
sortindsfx = np.argsort(np.r_[np.arange(mesh.nFx)[fxm], np.arange(mesh.nFx)[fxp]])
|
||||
sortindsfy = np.argsort(np.r_[np.arange(mesh.nFy)[fym], np.arange(mesh.nFy)[fyp]])
|
||||
@@ -201,8 +208,8 @@ class Test1D_InhomogeneousMixed(Tests.OrderTest):
|
||||
|
||||
|
||||
sigma = np.ones(self.M.nC)
|
||||
Mfrho = self.M.getFaceInnerProduct(1./sigma)
|
||||
MfrhoI = self.M.getFaceInnerProduct(1./sigma, invMat=True)
|
||||
Mfrho = self.M.getFaceInnerProduct(old_div(1.,sigma))
|
||||
MfrhoI = self.M.getFaceInnerProduct(old_div(1.,sigma), invMat=True)
|
||||
V = Utils.sdiag(self.M.vol)
|
||||
Div = V*self.M.faceDiv
|
||||
P_BC, B = self.M.getBCProjWF_simple()
|
||||
@@ -224,7 +231,7 @@ class Test1D_InhomogeneousMixed(Tests.OrderTest):
|
||||
|
||||
|
||||
def test_order(self):
|
||||
print "==== Testing Mixed boudary conduction for CC-problem ===="
|
||||
print("==== Testing Mixed boudary conduction for CC-problem ====")
|
||||
self.name = "1D"
|
||||
self.myTest = 'xc'
|
||||
self.orderTest()
|
||||
@@ -284,8 +291,8 @@ class Test2D_InhomogeneousMixed(Tests.OrderTest):
|
||||
|
||||
|
||||
sigma = np.ones(self.M.nC)
|
||||
Mfrho = self.M.getFaceInnerProduct(1./sigma)
|
||||
MfrhoI = self.M.getFaceInnerProduct(1./sigma, invMat=True)
|
||||
Mfrho = self.M.getFaceInnerProduct(old_div(1.,sigma))
|
||||
MfrhoI = self.M.getFaceInnerProduct(old_div(1.,sigma), invMat=True)
|
||||
V = Utils.sdiag(self.M.vol)
|
||||
Div = V*self.M.faceDiv
|
||||
P_BC, B = self.M.getBCProjWF_simple()
|
||||
@@ -305,7 +312,7 @@ class Test2D_InhomogeneousMixed(Tests.OrderTest):
|
||||
|
||||
|
||||
def test_order(self):
|
||||
print "==== Testing Mixed boudary conduction for CC-problem ===="
|
||||
print("==== Testing Mixed boudary conduction for CC-problem ====")
|
||||
self.name = "2D"
|
||||
self.myTest = 'xc'
|
||||
self.orderTest()
|
||||
@@ -378,8 +385,8 @@ class Test3D_InhomogeneousMixed(Tests.OrderTest):
|
||||
|
||||
|
||||
sigma = np.ones(self.M.nC)
|
||||
Mfrho = self.M.getFaceInnerProduct(1./sigma)
|
||||
MfrhoI = self.M.getFaceInnerProduct(1./sigma, invMat=True)
|
||||
Mfrho = self.M.getFaceInnerProduct(old_div(1.,sigma))
|
||||
MfrhoI = self.M.getFaceInnerProduct(old_div(1.,sigma), invMat=True)
|
||||
V = Utils.sdiag(self.M.vol)
|
||||
Div = V*self.M.faceDiv
|
||||
P_BC, B = self.M.getBCProjWF_simple()
|
||||
@@ -400,7 +407,7 @@ class Test3D_InhomogeneousMixed(Tests.OrderTest):
|
||||
|
||||
|
||||
def test_order(self):
|
||||
print "==== Testing Mixed boudary conduction for CC-problem ===="
|
||||
print("==== Testing Mixed boudary conduction for CC-problem ====")
|
||||
self.name = "3D"
|
||||
self.myTest = 'xc'
|
||||
self.orderTest()
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
import numpy as np
|
||||
import unittest
|
||||
from SimPEG import Utils, Tests
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
from past.utils import old_div
|
||||
from SimPEG import Mesh, Tests
|
||||
from SimPEG.Mesh.TreeMesh import CellLookUpException
|
||||
import numpy as np
|
||||
@@ -12,13 +19,13 @@ class TestSimpleQuadTree(unittest.TestCase):
|
||||
nc = 8
|
||||
h1 = np.random.rand(nc)*nc*0.5 + nc*0.5
|
||||
h2 = np.random.rand(nc)*nc*0.5 + nc*0.5
|
||||
h = [hi/np.sum(hi) for hi in [h1, h2]] # normalize
|
||||
h = [old_div(hi,np.sum(hi)) for hi in [h1, h2]] # normalize
|
||||
M = Mesh.TreeMesh(h)
|
||||
M._refineCell([0,0,0])
|
||||
M._refineCell([0,0,1])
|
||||
M.number()
|
||||
# M.plotGrid(showIt=True)
|
||||
print M
|
||||
print(M)
|
||||
assert M.nhFx == 2
|
||||
assert M.nFx == 9
|
||||
|
||||
@@ -60,7 +67,7 @@ class TestSimpleQuadTree(unittest.TestCase):
|
||||
nc = 8
|
||||
h1 = np.random.rand(nc)*nc*0.5 + nc*0.5
|
||||
h2 = np.random.rand(nc)*nc*0.5 + nc*0.5
|
||||
h = [hi/np.sum(hi) for hi in [h1, h2]] # normalize
|
||||
h = [old_div(hi,np.sum(hi)) for hi in [h1, h2]] # normalize
|
||||
M = Mesh.TreeMesh(h)
|
||||
M._refineCell([0,0,0])
|
||||
M._refineCell([0,0,1])
|
||||
@@ -138,7 +145,7 @@ class TestOcTree(unittest.TestCase):
|
||||
h1 = np.random.rand(nc)*nc*0.5 + nc*0.5
|
||||
h2 = np.random.rand(nc)*nc*0.5 + nc*0.5
|
||||
h3 = np.random.rand(nc)*nc*0.5 + nc*0.5
|
||||
h = [hi/np.sum(hi) for hi in [h1, h2, h3]] # normalize
|
||||
h = [old_div(hi,np.sum(hi)) for hi in [h1, h2, h3]] # normalize
|
||||
M = Mesh.TreeMesh(h, levels=3)
|
||||
M._refineCell([0,0,0,0])
|
||||
M._refineCell([0,0,0,1])
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
from __future__ import division
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
from past.utils import old_div
|
||||
import numpy as np
|
||||
import unittest
|
||||
from SimPEG import Utils, Tests
|
||||
@@ -183,14 +190,14 @@ class TestTreeInnerProducts(Tests.OrderTest):
|
||||
Gc = self.M.gridCC
|
||||
if self.sigmaTest == 1:
|
||||
sigma = np.c_[call(sigma1, Gc)]
|
||||
analytic = 647./360 # Found using sympy.
|
||||
analytic = old_div(647.,360) # Found using sympy.
|
||||
elif self.sigmaTest == 3:
|
||||
sigma = np.r_[call(sigma1, Gc), call(sigma2, Gc), call(sigma3, Gc)]
|
||||
analytic = 37./12 # Found using sympy.
|
||||
analytic = old_div(37.,12) # Found using sympy.
|
||||
elif self.sigmaTest == 6:
|
||||
sigma = np.c_[call(sigma1, Gc), call(sigma2, Gc), call(sigma3, Gc),
|
||||
call(sigma4, Gc), call(sigma5, Gc), call(sigma6, Gc)]
|
||||
analytic = 69881./21600 # Found using sympy.
|
||||
analytic = old_div(69881.,21600) # Found using sympy.
|
||||
|
||||
if self.location == 'edges':
|
||||
cart = lambda g: np.c_[call(ex, g), call(ey, g), call(ez, g)]
|
||||
@@ -328,13 +335,13 @@ class TestTreeInnerProducts2D(Tests.OrderTest):
|
||||
Gc = self.M.gridCC
|
||||
if self.sigmaTest == 1:
|
||||
sigma = np.c_[call(sigma1, Gc)]
|
||||
analytic = 144877./360 # Found using sympy. z=5
|
||||
analytic = old_div(144877.,360) # Found using sympy. z=5
|
||||
elif self.sigmaTest == 2:
|
||||
sigma = np.c_[call(sigma1, Gc), call(sigma2, Gc)]
|
||||
analytic = 189959./120 # Found using sympy. z=5
|
||||
analytic = old_div(189959.,120) # Found using sympy. z=5
|
||||
elif self.sigmaTest == 3:
|
||||
sigma = np.r_[call(sigma1, Gc), call(sigma2, Gc), call(sigma3, Gc)]
|
||||
analytic = 781427./360 # Found using sympy. z=5
|
||||
analytic = old_div(781427.,360) # Found using sympy. z=5
|
||||
|
||||
if self.location == 'edges':
|
||||
cart = lambda g: np.c_[call(ex, g), call(ey, g)]
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
import unittest
|
||||
import sys
|
||||
from SimPEG.Mesh.BaseMesh import BaseRectangularMesh
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import division
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
import numpy as np
|
||||
import scipy.sparse as sp
|
||||
import unittest
|
||||
@@ -55,12 +61,12 @@ class Test1D_InhomogeneousDirichlet(Tests.OrderTest):
|
||||
#TODO: fix the null space
|
||||
solver = SolverCG(A, maxiter=1000)
|
||||
xc = solver * (rhs)
|
||||
print 'ACCURACY', np.linalg.norm(Utils.mkvc(A*xc) - rhs)
|
||||
print('ACCURACY', np.linalg.norm(Utils.mkvc(A*xc) - rhs))
|
||||
err = np.linalg.norm((xc-xc_ana), np.inf)
|
||||
elif self.myTest == 'xcJ':
|
||||
#TODO: fix the null space
|
||||
xc = Solver(A) * (rhs)
|
||||
print np.linalg.norm(Utils.mkvc(A*xc) - rhs)
|
||||
print(np.linalg.norm(Utils.mkvc(A*xc) - rhs))
|
||||
j = McI*(G*xc + P*phi_bc)
|
||||
err = np.linalg.norm((j-j_ana), np.inf)
|
||||
|
||||
@@ -218,16 +224,16 @@ class Test1D_InhomogeneousNeumann(Tests.OrderTest):
|
||||
xc, info = sp.linalg.minres(A, rhs, tol = 1e-6)
|
||||
err = np.linalg.norm((xc-xc_ana), np.inf)
|
||||
if info > 0:
|
||||
print 'Solve does not work well'
|
||||
print 'ACCURACY', np.linalg.norm(Utils.mkvc(A*xc) - rhs)
|
||||
print('Solve does not work well')
|
||||
print('ACCURACY', np.linalg.norm(Utils.mkvc(A*xc) - rhs))
|
||||
elif self.myTest == 'xcJ':
|
||||
#TODO: fix the null space
|
||||
xc, info = sp.linalg.minres(A, rhs, tol = 1e-6)
|
||||
j = McI*(G*xc + P*phi_bc)
|
||||
err = np.linalg.norm((Pin*j-Pin*j_ana), np.inf)
|
||||
if info > 0:
|
||||
print 'Solve does not work well'
|
||||
print 'ACCURACY', np.linalg.norm(Utils.mkvc(A*xc) - rhs)
|
||||
print('Solve does not work well')
|
||||
print('ACCURACY', np.linalg.norm(Utils.mkvc(A*xc) - rhs))
|
||||
return err
|
||||
|
||||
def test_orderJ(self):
|
||||
@@ -305,16 +311,16 @@ class Test2D_InhomogeneousNeumann(Tests.OrderTest):
|
||||
xc, info = sp.linalg.minres(A, rhs, tol = 1e-6)
|
||||
err = np.linalg.norm((xc-xc_ana), np.inf)
|
||||
if info > 0:
|
||||
print 'Solve does not work well'
|
||||
print 'ACCURACY', np.linalg.norm(Utils.mkvc(A*xc) - rhs)
|
||||
print('Solve does not work well')
|
||||
print('ACCURACY', np.linalg.norm(Utils.mkvc(A*xc) - rhs))
|
||||
elif self.myTest == 'xcJ':
|
||||
#TODO: fix the null space
|
||||
xc, info = sp.linalg.minres(A, rhs, tol = 1e-6)
|
||||
j = McI*(G*xc + P*phi_bc)
|
||||
err = np.linalg.norm((Pin*j-Pin*j_ana), np.inf)
|
||||
if info > 0:
|
||||
print 'Solve does not work well'
|
||||
print 'ACCURACY', np.linalg.norm(Utils.mkvc(A*xc) - rhs)
|
||||
print('Solve does not work well')
|
||||
print('ACCURACY', np.linalg.norm(Utils.mkvc(A*xc) - rhs))
|
||||
return err
|
||||
|
||||
def test_orderJ(self):
|
||||
@@ -382,16 +388,16 @@ class Test1D_InhomogeneousMixed(Tests.OrderTest):
|
||||
xc, info = sp.linalg.minres(A, rhs, tol = 1e-6)
|
||||
err = np.linalg.norm((xc-xc_ana), np.inf)
|
||||
if info > 0:
|
||||
print 'Solve does not work well'
|
||||
print 'ACCURACY', np.linalg.norm(Utils.mkvc(A*xc) - rhs)
|
||||
print('Solve does not work well')
|
||||
print('ACCURACY', np.linalg.norm(Utils.mkvc(A*xc) - rhs))
|
||||
elif self.myTest == 'xcJ':
|
||||
#TODO: fix the null space
|
||||
xc, info = sp.linalg.minres(A, rhs, tol = 1e-6)
|
||||
j = McI*(G*xc + P*phi_bc)
|
||||
err = np.linalg.norm((Pin*j-Pin*j_ana), np.inf)
|
||||
if info > 0:
|
||||
print 'Solve does not work well'
|
||||
print 'ACCURACY', np.linalg.norm(Utils.mkvc(A*xc) - rhs)
|
||||
print('Solve does not work well')
|
||||
print('ACCURACY', np.linalg.norm(Utils.mkvc(A*xc) - rhs))
|
||||
return err
|
||||
|
||||
def test_orderJ(self):
|
||||
@@ -469,16 +475,16 @@ class Test2D_InhomogeneousMixed(Tests.OrderTest):
|
||||
xc, info = sp.linalg.minres(A, rhs, tol = 1e-6)
|
||||
err = np.linalg.norm((xc-xc_ana), np.inf)
|
||||
if info > 0:
|
||||
print 'Solve does not work well'
|
||||
print 'ACCURACY', np.linalg.norm(Utils.mkvc(A*xc) - rhs)
|
||||
print('Solve does not work well')
|
||||
print('ACCURACY', np.linalg.norm(Utils.mkvc(A*xc) - rhs))
|
||||
elif self.myTest == 'xcJ':
|
||||
#TODO: fix the null space
|
||||
xc, info = sp.linalg.minres(A, rhs, tol = 1e-6)
|
||||
j = McI*(G*xc + P*phi_bc)
|
||||
err = np.linalg.norm((Pin*j-Pin*j_ana), np.inf)
|
||||
if info > 0:
|
||||
print 'Solve does not work well'
|
||||
print 'ACCURACY', np.linalg.norm(Utils.mkvc(A*xc) - rhs)
|
||||
print('Solve does not work well')
|
||||
print('ACCURACY', np.linalg.norm(Utils.mkvc(A*xc) - rhs))
|
||||
return err
|
||||
|
||||
def test_orderJ(self):
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
from __future__ import division
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
from past.utils import old_div
|
||||
import unittest
|
||||
import sys
|
||||
from SimPEG import *
|
||||
@@ -135,7 +142,7 @@ class TestCyl2DMesh(unittest.TestCase):
|
||||
def test_getInterpMatCartMesh_Cells(self):
|
||||
|
||||
Mr = Mesh.TensorMesh([100,100,2], x0='CC0')
|
||||
Mc = Mesh.CylMesh([np.ones(10)/5,1,10],x0='0C0',cartesianOrigin=[-0.2,-0.2,0])
|
||||
Mc = Mesh.CylMesh([old_div(np.ones(10),5),1,10],x0='0C0',cartesianOrigin=[-0.2,-0.2,0])
|
||||
|
||||
mc = np.arange(Mc.nC)
|
||||
xr = np.linspace(0,0.4,50)
|
||||
@@ -149,7 +156,7 @@ class TestCyl2DMesh(unittest.TestCase):
|
||||
def test_getInterpMatCartMesh_Cells2Nodes(self):
|
||||
|
||||
Mr = Mesh.TensorMesh([100,100,2], x0='CC0')
|
||||
Mc = Mesh.CylMesh([np.ones(10)/5,1,10],x0='0C0',cartesianOrigin=[-0.2,-0.2,0])
|
||||
Mc = Mesh.CylMesh([old_div(np.ones(10),5),1,10],x0='0C0',cartesianOrigin=[-0.2,-0.2,0])
|
||||
|
||||
mc = np.arange(Mc.nC)
|
||||
xr = np.linspace(0,0.4,50)
|
||||
@@ -163,7 +170,7 @@ class TestCyl2DMesh(unittest.TestCase):
|
||||
def test_getInterpMatCartMesh_Faces(self):
|
||||
|
||||
Mr = Mesh.TensorMesh([100,100,2], x0='CC0')
|
||||
Mc = Mesh.CylMesh([np.ones(10)/5,1,10],x0='0C0',cartesianOrigin=[-0.2,-0.2,0])
|
||||
Mc = Mesh.CylMesh([old_div(np.ones(10),5),1,10],x0='0C0',cartesianOrigin=[-0.2,-0.2,0])
|
||||
|
||||
Pf = Mc.getInterpolationMatCartMesh(Mr, 'F')
|
||||
mf = np.ones(Mc.nF)
|
||||
@@ -194,7 +201,7 @@ class TestCyl2DMesh(unittest.TestCase):
|
||||
def test_getInterpMatCartMesh_Faces2Edges(self):
|
||||
|
||||
Mr = Mesh.TensorMesh([100,100,2], x0='CC0')
|
||||
Mc = Mesh.CylMesh([np.ones(10)/5,1,10],x0='0C0',cartesianOrigin=[-0.2,-0.2,0])
|
||||
Mc = Mesh.CylMesh([old_div(np.ones(10),5),1,10],x0='0C0',cartesianOrigin=[-0.2,-0.2,0])
|
||||
|
||||
Pf2e = Mc.getInterpolationMatCartMesh(Mr, 'F', locTypeTo='E')
|
||||
mf = np.ones(Mc.nF)
|
||||
@@ -225,7 +232,7 @@ class TestCyl2DMesh(unittest.TestCase):
|
||||
def test_getInterpMatCartMesh_Edges(self):
|
||||
|
||||
Mr = Mesh.TensorMesh([100,100,2], x0='CC0')
|
||||
Mc = Mesh.CylMesh([np.ones(10)/5,1,10],x0='0C0',cartesianOrigin=[-0.2,-0.2,0])
|
||||
Mc = Mesh.CylMesh([old_div(np.ones(10),5),1,10],x0='0C0',cartesianOrigin=[-0.2,-0.2,0])
|
||||
|
||||
Pe = Mc.getInterpolationMatCartMesh(Mr, 'E')
|
||||
me = np.ones(Mc.nE)
|
||||
@@ -256,7 +263,7 @@ class TestCyl2DMesh(unittest.TestCase):
|
||||
def test_getInterpMatCartMesh_Edges2Faces(self):
|
||||
|
||||
Mr = Mesh.TensorMesh([100,100,2], x0='CC0')
|
||||
Mc = Mesh.CylMesh([np.ones(10)/5,1,10],x0='0C0',cartesianOrigin=[-0.2,-0.2,0])
|
||||
Mc = Mesh.CylMesh([old_div(np.ones(10),5),1,10],x0='0C0',cartesianOrigin=[-0.2,-0.2,0])
|
||||
|
||||
Pe2f = Mc.getInterpolationMatCartMesh(Mr, 'E', locTypeTo='F')
|
||||
me = np.ones(Mc.nE)
|
||||
@@ -302,7 +309,7 @@ class TestFaceDiv2D(Tests.OrderTest):
|
||||
funR = lambda r, z: np.sin(2.*np.pi*r)
|
||||
funZ = lambda r, z: np.sin(2.*np.pi*z)
|
||||
|
||||
sol = lambda r, t, z: (2*np.pi*r*np.cos(2*np.pi*r) + np.sin(2*np.pi*r))/r + 2*np.pi*np.cos(2*np.pi*z)
|
||||
sol = lambda r, t, z: old_div((2*np.pi*r*np.cos(2*np.pi*r) + np.sin(2*np.pi*r)),r) + 2*np.pi*np.cos(2*np.pi*z)
|
||||
|
||||
Fc = cylF2(self.M, funR, funZ)
|
||||
Fc = np.c_[Fc[:,0],np.zeros(self.M.nF),Fc[:,1]]
|
||||
@@ -339,7 +346,7 @@ class TestEdgeCurl2D(Tests.OrderTest):
|
||||
funT = lambda r, t, z: np.sin(2.*np.pi*z)
|
||||
|
||||
solR = lambda r, z: -2.0*np.pi*np.cos(2.0*np.pi*z)
|
||||
solZ = lambda r, z: np.sin(2.0*np.pi*z)/r
|
||||
solZ = lambda r, z: old_div(np.sin(2.0*np.pi*z),r)
|
||||
|
||||
E = call3(funT, self.M.gridEy)
|
||||
|
||||
@@ -466,7 +473,7 @@ class TestCyl3DMesh(unittest.TestCase):
|
||||
def test_vectorsN(self):
|
||||
v = np.r_[0, 1, 2, 2.5]
|
||||
self.assertTrue(np.linalg.norm((v-self.mesh.vectorNx)) == 0)
|
||||
v = np.r_[np.pi/2, 1.5*np.pi]
|
||||
v = np.r_[old_div(np.pi,2), 1.5*np.pi]
|
||||
self.assertTrue(np.linalg.norm((v-self.mesh.vectorNy)) == 0)
|
||||
v = np.r_[0, 2, 3]
|
||||
self.assertTrue(np.linalg.norm((v-self.mesh.vectorNz)) == 0)
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
from __future__ import division
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
from past.utils import old_div
|
||||
import numpy as np
|
||||
import unittest
|
||||
from SimPEG import Utils, Tests
|
||||
@@ -28,14 +35,14 @@ class TestInnerProducts(Tests.OrderTest):
|
||||
Gc = self.M.gridCC
|
||||
if self.sigmaTest == 1:
|
||||
sigma = np.c_[call(sigma1, Gc)]
|
||||
analytic = 647./360 # Found using sympy.
|
||||
analytic = old_div(647.,360) # Found using sympy.
|
||||
elif self.sigmaTest == 3:
|
||||
sigma = np.r_[call(sigma1, Gc), call(sigma2, Gc), call(sigma3, Gc)]
|
||||
analytic = 37./12 # Found using sympy.
|
||||
analytic = old_div(37.,12) # Found using sympy.
|
||||
elif self.sigmaTest == 6:
|
||||
sigma = np.c_[call(sigma1, Gc), call(sigma2, Gc), call(sigma3, Gc),
|
||||
call(sigma4, Gc), call(sigma5, Gc), call(sigma6, Gc)]
|
||||
analytic = 69881./21600 # Found using sympy.
|
||||
analytic = old_div(69881.,21600) # Found using sympy.
|
||||
|
||||
if self.location == 'edges':
|
||||
cart = lambda g: np.c_[call(ex, g), call(ey, g), call(ez, g)]
|
||||
@@ -173,13 +180,13 @@ class TestInnerProducts2D(Tests.OrderTest):
|
||||
Gc = self.M.gridCC
|
||||
if self.sigmaTest == 1:
|
||||
sigma = np.c_[call(sigma1, Gc)]
|
||||
analytic = 144877./360 # Found using sympy. z=5
|
||||
analytic = old_div(144877.,360) # Found using sympy. z=5
|
||||
elif self.sigmaTest == 2:
|
||||
sigma = np.c_[call(sigma1, Gc), call(sigma2, Gc)]
|
||||
analytic = 189959./120 # Found using sympy. z=5
|
||||
analytic = old_div(189959.,120) # Found using sympy. z=5
|
||||
elif self.sigmaTest == 3:
|
||||
sigma = np.r_[call(sigma1, Gc), call(sigma2, Gc), call(sigma3, Gc)]
|
||||
analytic = 781427./360 # Found using sympy. z=5
|
||||
analytic = old_div(781427.,360) # Found using sympy. z=5
|
||||
|
||||
if self.location == 'edges':
|
||||
cart = lambda g: np.c_[call(ex, g), call(ey, g)]
|
||||
@@ -312,12 +319,12 @@ class TestInnerProducts1D(Tests.OrderTest):
|
||||
|
||||
Gc = self.M.gridCC
|
||||
sigma = call(sigma1, Gc)
|
||||
analytic = 128011./5 # Found using sympy. y=12, z=5
|
||||
analytic = old_div(128011.,5) # Found using sympy. y=12, z=5
|
||||
|
||||
if self.location == 'faces':
|
||||
F = call(ex, self.M.gridFx)
|
||||
if self.invProp:
|
||||
A = self.M.getFaceInnerProduct(1/sigma, invProp=True)
|
||||
A = self.M.getFaceInnerProduct(old_div(1,sigma), invProp=True)
|
||||
else:
|
||||
A = self.M.getFaceInnerProduct(sigma)
|
||||
numeric = F.T.dot(A.dot(F))
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import division
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
import numpy as np
|
||||
import unittest
|
||||
from SimPEG import *
|
||||
@@ -21,7 +27,7 @@ class TestInnerProductsDerivs(unittest.TestCase):
|
||||
M = mesh.getFaceInnerProduct(sig, invProp=invProp, invMat=invMat)
|
||||
Md = mesh.getFaceInnerProductDeriv(sig, invProp=invProp, invMat=invMat, doFast=fast)
|
||||
return M*v, Md(v)
|
||||
print meshType, 'Face', h, rep, fast, ('harmonic' if invProp and invMat else 'standard')
|
||||
print(meshType, 'Face', h, rep, fast, ('harmonic' if invProp and invMat else 'standard'))
|
||||
return Tests.checkDerivative(fun, sig, num=5, plotIt=False)
|
||||
|
||||
def doTestEdge(self, h, rep, fast, meshType, invProp=False, invMat=False):
|
||||
@@ -40,7 +46,7 @@ class TestInnerProductsDerivs(unittest.TestCase):
|
||||
M = mesh.getEdgeInnerProduct(sig, invProp=invProp, invMat=invMat)
|
||||
Md = mesh.getEdgeInnerProductDeriv(sig, invProp=invProp, invMat=invMat, doFast=fast)
|
||||
return M*v, Md(v)
|
||||
print meshType, 'Edge', h, rep, fast, ('harmonic' if invProp and invMat else 'standard')
|
||||
print(meshType, 'Edge', h, rep, fast, ('harmonic' if invProp and invMat else 'standard'))
|
||||
return Tests.checkDerivative(fun, sig, num=5, plotIt=False)
|
||||
|
||||
def test_FaceIP_1D_float(self):
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
import numpy as np
|
||||
import unittest
|
||||
from SimPEG.Utils import mkvc
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
import numpy as np
|
||||
import unittest
|
||||
from SimPEG.Tests import OrderTest
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import division
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
import numpy as np
|
||||
import unittest
|
||||
from SimPEG.Mesh import TensorMesh
|
||||
@@ -61,9 +67,9 @@ class BasicTensorMeshTests(unittest.TestCase):
|
||||
self.assertTrue(M.nC == 1)
|
||||
|
||||
def test_printing(self):
|
||||
print TensorMesh([10])
|
||||
print TensorMesh([10,10])
|
||||
print TensorMesh([10,10,10])
|
||||
print(TensorMesh([10]))
|
||||
print(TensorMesh([10,10]))
|
||||
print(TensorMesh([10,10,10]))
|
||||
|
||||
def test_centering(self):
|
||||
M1d = TensorMesh([10], 'C')
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
import os
|
||||
import glob
|
||||
import unittest
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
from __future__ import division
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
from past.utils import old_div
|
||||
import unittest
|
||||
from SimPEG import *
|
||||
from SimPEG import MT
|
||||
@@ -5,8 +12,8 @@ from SimPEG import MT
|
||||
TOL = 1e-6
|
||||
|
||||
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)
|
||||
app_res = (old_div((old_div(1.,(8e-7*np.pi**2))),freq))*np.abs(z)**2
|
||||
app_phs = np.arctan2(-z.imag,z.real)*(old_div(180,np.pi))
|
||||
return app_res, app_phs
|
||||
|
||||
def appResNorm(sigmaHalf):
|
||||
@@ -21,13 +28,13 @@ def appResNorm(sigmaHalf):
|
||||
Z = []
|
||||
for freq in freqs:
|
||||
Ed, Eu, Hd, Hu = MT.Utils.getEHfields(m1d,sigma,freq,np.array([200]))
|
||||
Z.append((Ed + Eu)/(Hd + Hu))
|
||||
Z.append(old_div((Ed + Eu),(Hd + Hu)))
|
||||
|
||||
Zarr = np.concatenate(Z)
|
||||
|
||||
app_r, app_p = appResPhs(freqs,Zarr)
|
||||
|
||||
return np.linalg.norm(np.abs(app_r - np.ones(nFreq)/sigmaHalf)) / np.log10(sigmaHalf)
|
||||
return old_div(np.linalg.norm(np.abs(app_r - old_div(np.ones(nFreq),sigmaHalf))), np.log10(sigmaHalf))
|
||||
|
||||
|
||||
class TestAnalytics(unittest.TestCase):
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
from __future__ import division
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
from past.utils import old_div
|
||||
import unittest
|
||||
import SimPEG as simpeg
|
||||
from SimPEG import MT
|
||||
@@ -44,8 +51,8 @@ def setupSurvey(sigmaHalf,tD=True):
|
||||
def getAppResPhs(MTdata):
|
||||
# Make impedance
|
||||
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)
|
||||
app_res = (old_div((old_div(1.,(8e-7*np.pi**2))),freq))*np.abs(z)**2
|
||||
app_phs = np.arctan2(z.imag,z.real)*(old_div(180,np.pi))
|
||||
return app_res, app_phs
|
||||
zList = []
|
||||
for src in MTdata.survey.srcList:
|
||||
@@ -75,7 +82,7 @@ def appRes_TotalFieldNorm(sigmaHalf):
|
||||
# Calculate the app res and phs
|
||||
app_r = np.array(getAppResPhs(data))[:,0]
|
||||
|
||||
return np.linalg.norm(np.abs(app_r - np.ones(survey.nFreq)/sigmaHalf)*sigmaHalf)
|
||||
return np.linalg.norm(np.abs(app_r - old_div(np.ones(survey.nFreq),sigmaHalf))*sigmaHalf)
|
||||
|
||||
def appPhs_TotalFieldNorm(sigmaHalf):
|
||||
|
||||
@@ -93,7 +100,7 @@ def appPhs_TotalFieldNorm(sigmaHalf):
|
||||
# Calculate the app phs
|
||||
app_p = np.array(getAppResPhs(data))[:,1]
|
||||
|
||||
return np.linalg.norm(np.abs(app_p - np.ones(survey.nFreq)*45)/ 45)
|
||||
return np.linalg.norm(old_div(np.abs(app_p - np.ones(survey.nFreq)*45), 45))
|
||||
|
||||
def appRes_psFieldNorm(sigmaHalf):
|
||||
|
||||
@@ -111,7 +118,7 @@ def appRes_psFieldNorm(sigmaHalf):
|
||||
# Calculate the app res and phs
|
||||
app_r = np.array(getAppResPhs(data))[:,0]
|
||||
|
||||
return np.linalg.norm(np.abs(app_r - np.ones(survey.nFreq)/sigmaHalf)*sigmaHalf)
|
||||
return np.linalg.norm(np.abs(app_r - old_div(np.ones(survey.nFreq),sigmaHalf))*sigmaHalf)
|
||||
|
||||
def appPhs_psFieldNorm(sigmaHalf):
|
||||
|
||||
@@ -129,7 +136,7 @@ def appPhs_psFieldNorm(sigmaHalf):
|
||||
# Calculate the app phs
|
||||
app_p = np.array(getAppResPhs(data))[:,1]
|
||||
|
||||
return np.linalg.norm(np.abs(app_p - np.ones(survey.nFreq)*45)/ 45)
|
||||
return np.linalg.norm(old_div(np.abs(app_p - np.ones(survey.nFreq)*45), 45))
|
||||
|
||||
class TestAnalytics(unittest.TestCase):
|
||||
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
from __future__ import division
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
from past.utils import old_div
|
||||
import unittest
|
||||
import SimPEG as simpeg
|
||||
from SimPEG import MT
|
||||
@@ -50,8 +57,8 @@ def setupSurvey(sigmaHalf,tD=True):
|
||||
def getAppResPhs(MTdata):
|
||||
# Make impedance
|
||||
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)
|
||||
app_res = (old_div((old_div(1.,(8e-7*np.pi**2))),freq))*np.abs(z)**2
|
||||
app_phs = np.arctan2(z.imag,z.real)*(old_div(180,np.pi))
|
||||
return app_res, app_phs
|
||||
zList = []
|
||||
for src in MTdata.survey.srcList:
|
||||
@@ -76,7 +83,7 @@ def calculateAnalyticSolution(srcList,mesh,model):
|
||||
# Scale the solution
|
||||
# anaE = (anaEtemp/anaEtemp[-1])#.conj()
|
||||
# anaH = (anaHtemp/anaEtemp[-1])#.conj()
|
||||
anaZ = anaE/anaH
|
||||
anaZ = old_div(anaE,anaH)
|
||||
for rx in src.rxList:
|
||||
data1D[src,rx] = getattr(anaZ, rx.projComp)
|
||||
return data1D
|
||||
@@ -94,7 +101,7 @@ def dataMis_AnalyticTotalDomain(sigmaHalf):
|
||||
# dataTDObj = MT.DataMT.DataMT(surveyTD, surveyTD.dpred(sigma))
|
||||
dataTD = surveyTD.dpred(sigma)
|
||||
dataAna = simpeg.mkvc(dataAnaObj)
|
||||
return np.all((dataTD - dataAna)/dataAna < 2.)
|
||||
return np.all(old_div((dataTD - dataAna),dataAna) < 2.)
|
||||
# surveyTD.dtrue = -simpeg.mkvc(dataAna,2)
|
||||
# surveyTD.dobs = -simpeg.mkvc(dataAna,2)
|
||||
# surveyTD.Wd = np.ones(surveyTD.dtrue.shape) #/(np.abs(surveyTD.dtrue)*0.01)
|
||||
@@ -117,7 +124,7 @@ def dataMis_AnalyticPrimarySecondary(sigmaHalf):
|
||||
|
||||
dataPS = surveyPS.dpred(sigmaPS)
|
||||
dataAna = simpeg.mkvc(dataAnaObj)
|
||||
return np.all((dataPS - dataAna)/dataAna < 2.)
|
||||
return np.all(old_div((dataPS - dataAna),dataAna) < 2.)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import absolute_import
|
||||
from builtins import int
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
from builtins import str
|
||||
from past.utils import old_div
|
||||
# Test functions
|
||||
from glob import glob
|
||||
import numpy as np, sys, os, time, scipy, subprocess
|
||||
@@ -146,8 +155,8 @@ def setupSimpegMTfwd_eForm_ps(inputSetup,comp='Imp',singleFreq=False,expMap=True
|
||||
def getAppResPhs(MTdata):
|
||||
# Make impedance
|
||||
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)
|
||||
app_res = (old_div((old_div(1.,(8e-7*np.pi**2))),freq))*np.abs(z)**2
|
||||
app_phs = np.arctan2(z.imag,z.real)*(old_div(180,np.pi))
|
||||
return app_res, app_phs
|
||||
recData = MTdata.toRecArray('Complex')
|
||||
return appResPhs(recData['freq'],recData['zxy']), appResPhs(recData['freq'],recData['zyx'])
|
||||
@@ -155,7 +164,7 @@ def getAppResPhs(MTdata):
|
||||
def JvecAdjointTest(inputSetup,comp='All',freq=False):
|
||||
(M, freqs, sig, sigBG, rx_loc) = inputSetup
|
||||
survey, problem = setupSimpegMTfwd_eForm_ps(inputSetup,comp='All',singleFreq=freq)
|
||||
print 'Adjoint test of eForm primary/secondary for {:s} comp at {:s}\n'.format(comp,str(survey.freqs))
|
||||
print('Adjoint test of eForm primary/secondary for {:s} comp at {:s}\n'.format(comp,str(survey.freqs)))
|
||||
|
||||
m = sig
|
||||
u = problem.fields(m)
|
||||
@@ -167,15 +176,15 @@ def JvecAdjointTest(inputSetup,comp='All',freq=False):
|
||||
vJw = v.ravel().dot(problem.Jvec(m, w, u))
|
||||
wJtv = w.ravel().dot(problem.Jtvec(m, v, u))
|
||||
tol = np.max([TOL*(10**int(np.log10(np.abs(vJw)))),FLR])
|
||||
print ' vJw wJtv vJw - wJtv tol abs(vJw - wJtv) < tol'
|
||||
print vJw, wJtv, vJw - wJtv, tol, np.abs(vJw - wJtv) < tol
|
||||
print(' vJw wJtv vJw - wJtv tol abs(vJw - wJtv) < tol')
|
||||
print(vJw, wJtv, vJw - wJtv, tol, np.abs(vJw - wJtv) < tol)
|
||||
return np.abs(vJw - wJtv) < tol
|
||||
|
||||
# Test the Jvec derivative
|
||||
def DerivJvecTest(inputSetup,comp='All',freq=False,expMap=True):
|
||||
(M, freqs, sig, sigBG, rx_loc) = inputSetup
|
||||
survey, problem = setupSimpegMTfwd_eForm_ps(inputSetup,comp=comp,singleFreq=freq,expMap=expMap)
|
||||
print 'Derivative test of Jvec for eForm primary/secondary for {:s} comp at {:s}\n'.format(comp,survey.freqs)
|
||||
print('Derivative test of Jvec for eForm primary/secondary for {:s} comp at {:s}\n'.format(comp,survey.freqs))
|
||||
# problem.mapping = simpeg.Maps.ExpMap(problem.mesh)
|
||||
# problem.sigmaPrimary = np.log(sigBG)
|
||||
x0 = np.log(sigBG)
|
||||
@@ -192,7 +201,7 @@ def DerivJvecTest(inputSetup,comp='All',freq=False,expMap=True):
|
||||
def DerivProjfieldsTest(inputSetup,comp='All',freq=False):
|
||||
|
||||
survey, problem = setupSimpegMTfwd_eForm_ps(inputSetup,comp,freq)
|
||||
print 'Derivative test of data projection for eFormulation primary/secondary\n\n'
|
||||
print('Derivative test of data projection for eFormulation primary/secondary\n\n')
|
||||
# problem.mapping = simpeg.Maps.ExpMap(problem.mesh)
|
||||
# Initate things for the derivs Test
|
||||
src = survey.srcList[0]
|
||||
@@ -203,13 +212,13 @@ def DerivProjfieldsTest(inputSetup,comp='All',freq=False):
|
||||
u0 = np.vstack((simpeg.mkvc(u0x,2),simpeg.mkvc(u0y,2)))
|
||||
f0 = problem.fieldsPair(survey.mesh,survey)
|
||||
# u0 = np.hstack((simpeg.mkvc(u0_px,2),simpeg.mkvc(u0_py,2)))
|
||||
f0[src,'e_pxSolution'] = u0[:len(u0)/2]#u0x
|
||||
f0[src,'e_pySolution'] = u0[len(u0)/2::]#u0y
|
||||
f0[src,'e_pxSolution'] = u0[:old_div(len(u0),2)]#u0x
|
||||
f0[src,'e_pySolution'] = u0[old_div(len(u0),2)::]#u0y
|
||||
|
||||
def fun(u):
|
||||
f = problem.fieldsPair(survey.mesh,survey)
|
||||
f[src,'e_pxSolution'] = u[:len(u)/2]
|
||||
f[src,'e_pySolution'] = u[len(u)/2::]
|
||||
f[src,'e_pxSolution'] = u[:old_div(len(u),2)]
|
||||
f[src,'e_pySolution'] = u[old_div(len(u),2)::]
|
||||
return rx.eval(src,survey.mesh,f), lambda t: rx.evalDeriv(src,survey.mesh,f0,simpeg.mkvc(t,2))
|
||||
|
||||
return simpeg.Tests.checkDerivative(fun, u0, num=3, plotIt=False, eps=FLR)
|
||||
@@ -221,15 +230,15 @@ def appResPhsHalfspace_eFrom_ps_Norm(sigmaHalf,appR=True,expMap=False):
|
||||
label = 'phase'
|
||||
# Make the survey and the problem
|
||||
survey, problem = setupSimpegMTfwd_eForm_ps(halfSpace(sigmaHalf),expMap=expMap)
|
||||
print 'Apperent {:s} test of eFormulation primary/secondary at {:g}\n\n'.format(label,sigmaHalf)
|
||||
print('Apperent {:s} test of eFormulation primary/secondary at {:g}\n\n'.format(label,sigmaHalf))
|
||||
|
||||
data = problem.dataPair(survey,survey.dpred(problem.curModel))
|
||||
# Calculate the app phs
|
||||
app_rpxy, app_rpyx = np.array(getAppResPhs(data))
|
||||
if appR:
|
||||
return np.all(np.abs(app_rpxy[0,:] - 1./sigmaHalf) * sigmaHalf < .4)
|
||||
return np.all(np.abs(app_rpxy[0,:] - old_div(1.,sigmaHalf)) * sigmaHalf < .4)
|
||||
else:
|
||||
return np.all(np.abs(app_rpxy[1,:] + 135) / 135 < .4)
|
||||
return np.all(old_div(np.abs(app_rpxy[1,:] + 135), 135) < .4)
|
||||
|
||||
class TestAnalytics(unittest.TestCase):
|
||||
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
if __name__ == '__main__':
|
||||
import os
|
||||
import glob
|
||||
|
||||
+22
-15
@@ -1,3 +1,10 @@
|
||||
from __future__ import division
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
from past.utils import old_div
|
||||
import unittest
|
||||
from SimPEG.Utils import Zero, Identity, sdiag, mkvc
|
||||
from SimPEG import np, sp
|
||||
@@ -19,7 +26,7 @@ class Tests(unittest.TestCase):
|
||||
assert z - 3 -z == -3
|
||||
assert 3*z == 0
|
||||
assert z*3 == 0
|
||||
assert z/3 == 0
|
||||
assert old_div(z,3) == 0
|
||||
|
||||
a = 1
|
||||
a += z
|
||||
@@ -27,7 +34,7 @@ class Tests(unittest.TestCase):
|
||||
a = 1
|
||||
a += z
|
||||
assert a == 1
|
||||
self.assertRaises(ZeroDivisionError, lambda:3/z)
|
||||
self.assertRaises(ZeroDivisionError, lambda:old_div(3,z))
|
||||
|
||||
assert mkvc(z) == 0
|
||||
assert sdiag(z)*a == 0
|
||||
@@ -68,12 +75,12 @@ class Tests(unittest.TestCase):
|
||||
assert 3 - -o == 4
|
||||
assert 3 - o == 2
|
||||
|
||||
assert o/2 == 0
|
||||
assert o/2. == 0.5
|
||||
assert -o/2 == -1
|
||||
assert -o/2. == -0.5
|
||||
assert 2/o == 2
|
||||
assert 2/-o == -2
|
||||
assert old_div(o,2) == 0
|
||||
assert old_div(o,2.) == 0.5
|
||||
assert old_div(-o,2) == -1
|
||||
assert old_div(-o,2.) == -0.5
|
||||
assert old_div(2,o) == 2
|
||||
assert old_div(2,-o) == -2
|
||||
|
||||
|
||||
def test_mat_one(self):
|
||||
@@ -87,9 +94,9 @@ class Tests(unittest.TestCase):
|
||||
check(o * S, [[2,0],[0,3]])
|
||||
check(S * -o, [[-2,0],[0,-3]])
|
||||
check(-o * S, [[-2,0],[0,-3]])
|
||||
check(S/o, [[2,0],[0,3]])
|
||||
check(S/-o, [[-2,0],[0,-3]])
|
||||
self.assertRaises(NotImplementedError, lambda:o/S)
|
||||
check(old_div(S,o), [[2,0],[0,3]])
|
||||
check(old_div(S,-o), [[-2,0],[0,-3]])
|
||||
self.assertRaises(NotImplementedError, lambda:old_div(o,S))
|
||||
|
||||
check(S + o, [[3,0],[0,4]])
|
||||
check(o + S, [[3,0],[0,4]])
|
||||
@@ -114,10 +121,10 @@ class Tests(unittest.TestCase):
|
||||
assert np.all(1+n == o+n)
|
||||
assert np.all(n-1 == n-o)
|
||||
assert np.all(1-n == o-n)
|
||||
assert np.all(n/1 == n/o)
|
||||
assert np.all(n/-1 == n/-o)
|
||||
assert np.all(1/n == o/n)
|
||||
assert np.all(-1/n == -o/n)
|
||||
assert np.all(old_div(n,1) == old_div(n,o))
|
||||
assert np.all(old_div(n,-1) == old_div(n,-o))
|
||||
assert np.all(old_div(1,n) == old_div(o,n))
|
||||
assert np.all(old_div(-1,n) == old_div(-o,n))
|
||||
assert np.all(n*1 == n*o)
|
||||
assert np.all(n*-1 == n*-o)
|
||||
assert np.all(1*n == o*n)
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
from __future__ import division
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import absolute_import
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
from past.utils import old_div
|
||||
import unittest, os
|
||||
import numpy as np
|
||||
from SimPEG import Utils
|
||||
@@ -9,11 +16,11 @@ class coorUtilsTest(unittest.TestCase):
|
||||
def test_rotationMatrixFromNormals(self):
|
||||
np.random.seed(0)
|
||||
v0 = np.random.rand(3)
|
||||
v0 *= 1./np.linalg.norm(v0)
|
||||
v0 *= old_div(1.,np.linalg.norm(v0))
|
||||
|
||||
np.random.seed(5)
|
||||
v1 = np.random.rand(3)
|
||||
v1 *= 1./np.linalg.norm(v1)
|
||||
v1 *= old_div(1.,np.linalg.norm(v1))
|
||||
|
||||
Rf = Utils.coordutils.rotationMatrixFromNormals(v0,v1)
|
||||
Ri = Utils.coordutils.rotationMatrixFromNormals(v1,v0)
|
||||
@@ -24,11 +31,11 @@ class coorUtilsTest(unittest.TestCase):
|
||||
def test_rotatePointsFromNormals(self):
|
||||
np.random.seed(10)
|
||||
v0 = np.random.rand(3)
|
||||
v0*= 1./np.linalg.norm(v0)
|
||||
v0*= old_div(1.,np.linalg.norm(v0))
|
||||
|
||||
np.random.seed(15)
|
||||
v1 = np.random.rand(3)
|
||||
v1*= 1./np.linalg.norm(v1)
|
||||
v1*= old_div(1.,np.linalg.norm(v1))
|
||||
|
||||
v2 = Utils.mkvc(Utils.coordutils.rotatePointsFromNormals(Utils.mkvc(v0,2).T,v0,v1))
|
||||
|
||||
@@ -37,11 +44,11 @@ class coorUtilsTest(unittest.TestCase):
|
||||
def test_rotateMatrixFromNormals(self):
|
||||
np.random.seed(20)
|
||||
n0 = np.random.rand(3)
|
||||
n0 *= 1./np.linalg.norm(n0)
|
||||
n0 *= old_div(1.,np.linalg.norm(n0))
|
||||
|
||||
np.random.seed(25)
|
||||
n1 = np.random.rand(3)
|
||||
n1 *= 1./np.linalg.norm(n1)
|
||||
n1 *= old_div(1.,np.linalg.norm(n1))
|
||||
|
||||
np.random.seed(30)
|
||||
scale = np.random.rand(100,1)
|
||||
@@ -49,7 +56,7 @@ class coorUtilsTest(unittest.TestCase):
|
||||
XYZ1 = scale * n1
|
||||
|
||||
XYZ2 = Utils.coordutils.rotatePointsFromNormals(XYZ0,n0,n1)
|
||||
self.assertTrue(np.linalg.norm(Utils.mkvc(XYZ1) - Utils.mkvc(XYZ2))/np.linalg.norm(Utils.mkvc(XYZ1)) < tol)
|
||||
self.assertTrue(old_div(np.linalg.norm(Utils.mkvc(XYZ1) - Utils.mkvc(XYZ2)),np.linalg.norm(Utils.mkvc(XYZ1))) < tol)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import absolute_import
|
||||
from builtins import int
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
from builtins import range
|
||||
from builtins import object
|
||||
import unittest
|
||||
from SimPEG.Utils import *
|
||||
from SimPEG import Mesh, np, sp
|
||||
@@ -220,7 +229,7 @@ class TestSequenceFunctions(unittest.TestCase):
|
||||
def test_isScalar(self):
|
||||
self.assertTrue(isScalar(1.))
|
||||
self.assertTrue(isScalar(1))
|
||||
self.assertTrue(isScalar(long(1)))
|
||||
self.assertTrue(isScalar(int(1)))
|
||||
self.assertTrue(isScalar(np.r_[1.]))
|
||||
self.assertTrue(isScalar(np.r_[1]))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user