mirror of
https://github.com/wassname/simpeg.git
synced 2026-09-09 11:34:26 +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()
|
||||
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')
|
||||
|
||||
Reference in New Issue
Block a user