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,11 @@
|
||||
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 builtins import range
|
||||
from builtins import object
|
||||
import numpy as np
|
||||
from SimPEG import Utils
|
||||
|
||||
|
||||
@@ -1,17 +1,26 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import unicode_literals
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
from builtins import range
|
||||
from past.utils import old_div
|
||||
from SimPEG import Utils, np
|
||||
from BaseMesh import BaseRectangularMesh
|
||||
from DiffOperators import DiffOperators
|
||||
from InnerProducts import InnerProducts
|
||||
from View import CurvView
|
||||
from .BaseMesh import BaseRectangularMesh
|
||||
from .DiffOperators import DiffOperators
|
||||
from .InnerProducts import InnerProducts
|
||||
from .View import CurvView
|
||||
from future.utils import with_metaclass
|
||||
|
||||
# Some helper functions.
|
||||
length2D = lambda x: (x[:, 0]**2 + x[:, 1]**2)**0.5
|
||||
length3D = lambda x: (x[:, 0]**2 + x[:, 1]**2 + x[:, 2]**2)**0.5
|
||||
normalize2D = lambda x: x/np.kron(np.ones((1, 2)), Utils.mkvc(length2D(x), 2))
|
||||
normalize3D = lambda x: x/np.kron(np.ones((1, 3)), Utils.mkvc(length3D(x), 2))
|
||||
normalize2D = lambda x: old_div(x,np.kron(np.ones((1, 2)), Utils.mkvc(length2D(x), 2)))
|
||||
normalize3D = lambda x: old_div(x,np.kron(np.ones((1, 3)), Utils.mkvc(length3D(x), 2)))
|
||||
|
||||
|
||||
class CurvilinearMesh(BaseRectangularMesh, DiffOperators, InnerProducts, CurvView):
|
||||
class CurvilinearMesh(with_metaclass(Utils.SimPEGMetaClass, type('NewBase', (BaseRectangularMesh, DiffOperators, InnerProducts, CurvView), {}))):
|
||||
"""
|
||||
CurvilinearMesh is a mesh class that deals with curvilinear meshes.
|
||||
|
||||
@@ -26,8 +35,6 @@ class CurvilinearMesh(BaseRectangularMesh, DiffOperators, InnerProducts, CurvVie
|
||||
M.plotGrid(showIt=True)
|
||||
"""
|
||||
|
||||
__metaclass__ = Utils.SimPEGMetaClass
|
||||
|
||||
_meshType = 'Curv'
|
||||
|
||||
def __init__(self, nodes):
|
||||
@@ -220,7 +227,7 @@ class CurvilinearMesh(BaseRectangularMesh, DiffOperators, InnerProducts, CurvVie
|
||||
Utils.volTetra(self.gridN, C, H, D, A) + # cutted edge bottom
|
||||
Utils.volTetra(self.gridN, C, G, H, F)) # cutted edge bottom
|
||||
|
||||
self._vol = (vol1 + vol2)/2
|
||||
self._vol = old_div((vol1 + vol2),2)
|
||||
return self._vol
|
||||
return locals()
|
||||
_vol = None
|
||||
@@ -282,9 +289,9 @@ class CurvilinearMesh(BaseRectangularMesh, DiffOperators, InnerProducts, CurvVie
|
||||
if self.dim == 2:
|
||||
return normalize2D(np.r_[self._normals[0], self._normals[1]])
|
||||
elif self.dim == 3:
|
||||
normal1 = (self._normals[0][0] + self._normals[0][1] + self._normals[0][2] + self._normals[0][3])/4
|
||||
normal2 = (self._normals[1][0] + self._normals[1][1] + self._normals[1][2] + self._normals[1][3])/4
|
||||
normal3 = (self._normals[2][0] + self._normals[2][1] + self._normals[2][2] + self._normals[2][3])/4
|
||||
normal1 = old_div((self._normals[0][0] + self._normals[0][1] + self._normals[0][2] + self._normals[0][3]),4)
|
||||
normal2 = old_div((self._normals[1][0] + self._normals[1][1] + self._normals[1][2] + self._normals[1][3]),4)
|
||||
normal3 = old_div((self._normals[2][0] + self._normals[2][1] + self._normals[2][2] + self._normals[2][3]),4)
|
||||
return normalize3D(np.r_[normal1, normal2, normal3])
|
||||
return locals()
|
||||
_normals = None
|
||||
@@ -302,7 +309,7 @@ class CurvilinearMesh(BaseRectangularMesh, DiffOperators, InnerProducts, CurvVie
|
||||
A, B = Utils.indexCube('AB', self.vnC+1, np.array([self.nNx, self.nCy]))
|
||||
edge2 = xy[B, :] - xy[A, :]
|
||||
self._edge = np.r_[Utils.mkvc(length2D(edge1)), Utils.mkvc(length2D(edge2))]
|
||||
self._tangents = np.r_[edge1, edge2]/np.c_[self._edge, self._edge]
|
||||
self._tangents = old_div(np.r_[edge1, edge2],np.c_[self._edge, self._edge])
|
||||
elif(self.dim == 3):
|
||||
xyz = self.gridN
|
||||
A, D = Utils.indexCube('AD', self.vnC+1, np.array([self.nCx, self.nNy, self.nNz]))
|
||||
@@ -312,7 +319,7 @@ class CurvilinearMesh(BaseRectangularMesh, DiffOperators, InnerProducts, CurvVie
|
||||
A, E = Utils.indexCube('AE', self.vnC+1, np.array([self.nNx, self.nNy, self.nCz]))
|
||||
edge3 = xyz[E, :] - xyz[A, :]
|
||||
self._edge = np.r_[Utils.mkvc(length3D(edge1)), Utils.mkvc(length3D(edge2)), Utils.mkvc(length3D(edge3))]
|
||||
self._tangents = np.r_[edge1, edge2, edge3]/np.c_[self._edge, self._edge, self._edge]
|
||||
self._tangents = old_div(np.r_[edge1, edge2, edge3],np.c_[self._edge, self._edge, self._edge])
|
||||
return self._edge
|
||||
return locals()
|
||||
_edge = None
|
||||
@@ -333,10 +340,10 @@ class CurvilinearMesh(BaseRectangularMesh, DiffOperators, InnerProducts, CurvVie
|
||||
|
||||
if __name__ == '__main__':
|
||||
nc = 5
|
||||
h1 = np.cumsum(np.r_[0, np.ones(nc)/(nc)])
|
||||
h1 = np.cumsum(np.r_[0, old_div(np.ones(nc),(nc))])
|
||||
nc = 7
|
||||
h2 = np.cumsum(np.r_[0, np.ones(nc)/(nc)])
|
||||
h3 = np.cumsum(np.r_[0, np.ones(nc)/(nc)])
|
||||
h2 = np.cumsum(np.r_[0, old_div(np.ones(nc),(nc))])
|
||||
h3 = np.cumsum(np.r_[0, old_div(np.ones(nc),(nc))])
|
||||
dee3 = True
|
||||
if dee3:
|
||||
X, Y, Z = Utils.ndgrid(h1, h2, h3, vector=False)
|
||||
@@ -345,4 +352,4 @@ if __name__ == '__main__':
|
||||
X, Y = Utils.ndgrid(h1, h2, vector=False)
|
||||
M = CurvilinearMesh([X, Y])
|
||||
|
||||
print M.r(M.normals, 'F', 'Fx', 'V')
|
||||
print(M.r(M.normals, 'F', 'Fx', 'V'))
|
||||
|
||||
+16
-9
@@ -1,10 +1,17 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import unicode_literals
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
from past.utils import old_div
|
||||
import numpy as np
|
||||
import scipy.sparse as sp
|
||||
from scipy.constants import pi
|
||||
from SimPEG.Utils import mkvc, ndgrid, sdiag, kron3, speye, spzeros, ddx, av, avExtrap
|
||||
from TensorMesh import BaseTensorMesh, BaseRectangularMesh
|
||||
from InnerProducts import InnerProducts
|
||||
from View import CylView
|
||||
from .TensorMesh import BaseTensorMesh, BaseRectangularMesh
|
||||
from .InnerProducts import InnerProducts
|
||||
from .View import CylView
|
||||
|
||||
|
||||
class CylMesh(BaseTensorMesh, BaseRectangularMesh, InnerProducts, CylView):
|
||||
@@ -31,7 +38,7 @@ class CylMesh(BaseTensorMesh, BaseRectangularMesh, InnerProducts, CylView):
|
||||
BaseTensorMesh.__init__(self, h, x0)
|
||||
assert self.hy.sum() == 2*np.pi, "The 2nd dimension must sum to 2*pi"
|
||||
if self.dim == 2:
|
||||
print 'Warning, a disk mesh has not been tested thoroughly.'
|
||||
print('Warning, a disk mesh has not been tested thoroughly.')
|
||||
cartesianOrigin = np.zeros(self.dim) if cartesianOrigin is None else cartesianOrigin
|
||||
assert len(cartesianOrigin) == self.dim, "cartesianOrigin must be the same length as the dimension of the mesh."
|
||||
self.cartesianOrigin = np.array(cartesianOrigin, dtype=float)
|
||||
@@ -193,7 +200,7 @@ class CylMesh(BaseTensorMesh, BaseRectangularMesh, InnerProducts, CylView):
|
||||
D1 = kron3(speye(self.nCz), speye(self.nCy), ddx(self.nCx)[:,1:])
|
||||
S = self.r(self.area, 'F', 'Fx', 'V')
|
||||
V = self.vol
|
||||
self._faceDivx = sdiag(1/V)*D1*sdiag(S)
|
||||
self._faceDivx = sdiag(old_div(1,V))*D1*sdiag(S)
|
||||
return self._faceDivx
|
||||
|
||||
@property
|
||||
@@ -205,7 +212,7 @@ class CylMesh(BaseTensorMesh, BaseRectangularMesh, InnerProducts, CylView):
|
||||
D2 = kron3(speye(self.nCz), ddx(self.nCy), speye(self.nCx))
|
||||
S = self.r(self.area, 'F', 'Fy', 'V')
|
||||
V = self.vol
|
||||
self._faceDivy = sdiag(1/V)*D2*sdiag(S)
|
||||
self._faceDivy = sdiag(old_div(1,V))*D2*sdiag(S)
|
||||
return self._faceDivy
|
||||
|
||||
@property
|
||||
@@ -215,7 +222,7 @@ class CylMesh(BaseTensorMesh, BaseRectangularMesh, InnerProducts, CylView):
|
||||
D3 = kron3(ddx(self.nCz), speye(self.nCy), speye(self.nCx))
|
||||
S = self.r(self.area, 'F', 'Fz', 'V')
|
||||
V = self.vol
|
||||
self._faceDivz = sdiag(1/V)*D3*sdiag(S)
|
||||
self._faceDivz = sdiag(old_div(1,V))*D3*sdiag(S)
|
||||
return self._faceDivz
|
||||
|
||||
|
||||
@@ -254,7 +261,7 @@ class CylMesh(BaseTensorMesh, BaseRectangularMesh, InnerProducts, CylView):
|
||||
A = self.area
|
||||
E = self.edge
|
||||
#Edge curl operator
|
||||
self._edgeCurl = sdiag(1/A)*sp.vstack((Dz, Dr))*sdiag(E)
|
||||
self._edgeCurl = sdiag(old_div(1,A))*sp.vstack((Dz, Dr))*sdiag(E)
|
||||
return self._edgeCurl
|
||||
|
||||
# @property
|
||||
@@ -355,7 +362,7 @@ class CylMesh(BaseTensorMesh, BaseRectangularMesh, InnerProducts, CylView):
|
||||
|
||||
grid = getattr(Mrect, 'grid' + locTypeTo)
|
||||
# This is unit circle stuff, 0 to 2*pi, starting at x-axis, rotating counter clockwise in an x-y slice
|
||||
theta = - np.arctan2(grid[:,0] - self.cartesianOrigin[0], grid[:,1] - self.cartesianOrigin[1]) + np.pi/2
|
||||
theta = - np.arctan2(grid[:,0] - self.cartesianOrigin[0], grid[:,1] - self.cartesianOrigin[1]) + old_div(np.pi,2)
|
||||
theta[theta < 0] += np.pi*2.0
|
||||
r = ((grid[:,0] - self.cartesianOrigin[0])**2 + (grid[:,1] - self.cartesianOrigin[1])**2)**0.5
|
||||
|
||||
|
||||
@@ -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 object
|
||||
from past.utils import old_div
|
||||
import numpy as np
|
||||
from scipy import sparse as sp
|
||||
from SimPEG.Utils import mkvc, sdiag, speye, kron3, spzeros, ddx, av, avExtrap
|
||||
@@ -145,7 +153,7 @@ class DiffOperators(object):
|
||||
# Compute areas of cell faces & volumes
|
||||
S = self.area
|
||||
V = self.vol
|
||||
self._faceDiv = sdiag(1/V)*D*sdiag(S)
|
||||
self._faceDiv = sdiag(old_div(1,V))*D*sdiag(S)
|
||||
|
||||
return self._faceDiv
|
||||
return locals()
|
||||
@@ -169,7 +177,7 @@ class DiffOperators(object):
|
||||
# Compute areas of cell faces & volumes
|
||||
S = self.r(self.area, 'F', 'Fx', 'V')
|
||||
V = self.vol
|
||||
self._faceDivx = sdiag(1/V)*D1*sdiag(S)
|
||||
self._faceDivx = sdiag(old_div(1,V))*D1*sdiag(S)
|
||||
|
||||
return self._faceDivx
|
||||
return locals()
|
||||
@@ -192,7 +200,7 @@ class DiffOperators(object):
|
||||
# Compute areas of cell faces & volumes
|
||||
S = self.r(self.area, 'F', 'Fy', 'V')
|
||||
V = self.vol
|
||||
self._faceDivy = sdiag(1/V)*D2*sdiag(S)
|
||||
self._faceDivy = sdiag(old_div(1,V))*D2*sdiag(S)
|
||||
|
||||
return self._faceDivy
|
||||
return locals()
|
||||
@@ -212,7 +220,7 @@ class DiffOperators(object):
|
||||
# Compute areas of cell faces & volumes
|
||||
S = self.r(self.area, 'F', 'Fz', 'V')
|
||||
V = self.vol
|
||||
self._faceDivz = sdiag(1/V)*D3*sdiag(S)
|
||||
self._faceDivz = sdiag(old_div(1,V))*D3*sdiag(S)
|
||||
|
||||
return self._faceDivz
|
||||
return locals()
|
||||
@@ -240,7 +248,7 @@ class DiffOperators(object):
|
||||
G = sp.vstack((D1, D2, D3), format="csr")
|
||||
# Compute lengths of cell edges
|
||||
L = self.edge
|
||||
self._nodalGrad = sdiag(1/L)*G
|
||||
self._nodalGrad = sdiag(old_div(1,L))*G
|
||||
return self._nodalGrad
|
||||
return locals()
|
||||
_nodalGrad = None
|
||||
@@ -251,23 +259,23 @@ class DiffOperators(object):
|
||||
|
||||
def fget(self):
|
||||
if(self._nodalLaplacian is None):
|
||||
print 'Warning: Laplacian has not been tested rigorously.'
|
||||
print('Warning: Laplacian has not been tested rigorously.')
|
||||
# The number of cell centers in each direction
|
||||
n = self.vnC
|
||||
# Compute divergence operator on faces
|
||||
if(self.dim == 1):
|
||||
D1 = sdiag(1./self.hx) * ddx(mesh.nCx)
|
||||
D1 = sdiag(old_div(1.,self.hx)) * ddx(mesh.nCx)
|
||||
L = - D1.T*D1
|
||||
elif(self.dim == 2):
|
||||
D1 = sdiag(1./self.hx) * ddx(n[0])
|
||||
D2 = sdiag(1./self.hy) * ddx(n[1])
|
||||
D1 = sdiag(old_div(1.,self.hx)) * ddx(n[0])
|
||||
D2 = sdiag(old_div(1.,self.hy)) * ddx(n[1])
|
||||
L1 = sp.kron(speye(n[1]+1), - D1.T * D1)
|
||||
L2 = sp.kron(- D2.T * D2, speye(n[0]+1))
|
||||
L = L1 + L2
|
||||
elif(self.dim == 3):
|
||||
D1 = sdiag(1./self.hx) * ddx(n[0])
|
||||
D2 = sdiag(1./self.hy) * ddx(n[1])
|
||||
D3 = sdiag(1./self.hz) * ddx(n[2])
|
||||
D1 = sdiag(old_div(1.,self.hx)) * ddx(n[0])
|
||||
D2 = sdiag(old_div(1.,self.hy)) * ddx(n[1])
|
||||
D3 = sdiag(old_div(1.,self.hz)) * ddx(n[2])
|
||||
L1 = kron3(speye(n[2]+1), speye(n[1]+1), - D1.T * D1)
|
||||
L2 = kron3(speye(n[2]+1), - D2.T * D2, speye(n[0]+1))
|
||||
L3 = kron3(- D3.T * D3, speye(n[1]+1), speye(n[0]+1))
|
||||
@@ -332,7 +340,7 @@ class DiffOperators(object):
|
||||
# Compute areas of cell faces & volumes
|
||||
S = self.area
|
||||
V = self.aveCC2F*self.vol # Average volume between adjacent cells
|
||||
self._cellGrad = sdiag(S/V)*G
|
||||
self._cellGrad = sdiag(old_div(S,V))*G
|
||||
return self._cellGrad
|
||||
return locals()
|
||||
_cellGrad = None
|
||||
@@ -359,7 +367,7 @@ class DiffOperators(object):
|
||||
# Compute areas of cell faces & volumes
|
||||
S = self.area
|
||||
V = self.aveCC2F*self.vol # Average volume between adjacent cells
|
||||
self._cellGradBC = sdiag(S/V)*G
|
||||
self._cellGradBC = sdiag(old_div(S,V))*G
|
||||
return self._cellGradBC
|
||||
return locals()
|
||||
_cellGradBC = None
|
||||
@@ -385,7 +393,7 @@ class DiffOperators(object):
|
||||
G1 = self._cellGradxStencil()
|
||||
# Compute areas of cell faces & volumes
|
||||
V = self.aveCC2F*self.vol
|
||||
L = self.r(self.area/V, 'F','Fx', 'V')
|
||||
L = self.r(old_div(self.area,V), 'F','Fx', 'V')
|
||||
self._cellGradx = sdiag(L)*G1
|
||||
return self._cellGradx
|
||||
return locals()
|
||||
@@ -409,7 +417,7 @@ class DiffOperators(object):
|
||||
G2 = self._cellGradyStencil()
|
||||
# Compute areas of cell faces & volumes
|
||||
V = self.aveCC2F*self.vol
|
||||
L = self.r(self.area/V, 'F','Fy', 'V')
|
||||
L = self.r(old_div(self.area,V), 'F','Fy', 'V')
|
||||
self._cellGrady = sdiag(L)*G2
|
||||
return self._cellGrady
|
||||
return locals()
|
||||
@@ -430,7 +438,7 @@ class DiffOperators(object):
|
||||
G3 = self._cellGradzStencil()
|
||||
# Compute areas of cell faces & volumes
|
||||
V = self.aveCC2F*self.vol
|
||||
L = self.r(self.area/V, 'F','Fz', 'V')
|
||||
L = self.r(old_div(self.area,V), 'F','Fz', 'V')
|
||||
self._cellGradz = sdiag(L)*G3
|
||||
return self._cellGradz
|
||||
return locals()
|
||||
@@ -457,7 +465,7 @@ class DiffOperators(object):
|
||||
D21 = sp.kron(ddx(n[1]), speye(n[0]))
|
||||
D12 = sp.kron(speye(n[1]), ddx(n[0]))
|
||||
C = sp.hstack((-D21, D12), format="csr")
|
||||
self._edgeCurl = C*sdiag(1/S)
|
||||
self._edgeCurl = C*sdiag(old_div(1,S))
|
||||
|
||||
elif self.dim == 3:
|
||||
|
||||
@@ -476,7 +484,7 @@ class DiffOperators(object):
|
||||
sp.hstack((D31, O2, -D13)),
|
||||
sp.hstack((-D21, D12, O3))), format="csr")
|
||||
|
||||
self._edgeCurl = sdiag(1/S)*(C*sdiag(L))
|
||||
self._edgeCurl = sdiag(old_div(1,S))*(C*sdiag(L))
|
||||
|
||||
return self._edgeCurl
|
||||
return locals()
|
||||
@@ -655,7 +663,7 @@ class DiffOperators(object):
|
||||
elif(self.dim == 2):
|
||||
return (0.5)*sp.hstack((self.aveFx2CC, self.aveFy2CC), format="csr")
|
||||
elif(self.dim == 3):
|
||||
return (1./3.)*sp.hstack((self.aveFx2CC, self.aveFy2CC, self.aveFz2CC), format="csr")
|
||||
return (old_div(1.,3.))*sp.hstack((self.aveFx2CC, self.aveFy2CC, self.aveFz2CC), format="csr")
|
||||
|
||||
@property
|
||||
def aveF2CCV(self):
|
||||
@@ -727,7 +735,7 @@ class DiffOperators(object):
|
||||
elif(self.dim == 2):
|
||||
return 0.5*sp.hstack((self.aveEx2CC, self.aveEy2CC), format="csr")
|
||||
elif(self.dim == 3):
|
||||
return (1./3)*sp.hstack((self.aveEx2CC, self.aveEy2CC, self.aveEz2CC), format="csr")
|
||||
return (old_div(1.,3))*sp.hstack((self.aveEx2CC, self.aveEy2CC, self.aveEz2CC), format="csr")
|
||||
|
||||
@property
|
||||
def aveE2CCV(self):
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
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 builtins import range
|
||||
from builtins import object
|
||||
from scipy import sparse as sp
|
||||
from SimPEG.Utils import *
|
||||
import numpy as np
|
||||
@@ -186,7 +194,7 @@ class InnerProducts(object):
|
||||
if tensorType == 0:
|
||||
dMdm = spzeros(n, 1)
|
||||
for i, p in enumerate(P):
|
||||
dMdm = dMdm + sp.csr_matrix((p.T * (p * v), (range(n), np.zeros(n))), shape=(n,1))
|
||||
dMdm = dMdm + sp.csr_matrix((p.T * (p * v), (list(range(n)), np.zeros(n))), shape=(n,1))
|
||||
if d == 1:
|
||||
if tensorType == 1:
|
||||
dMdm = spzeros(n, self.nC)
|
||||
@@ -288,7 +296,7 @@ class InnerProducts(object):
|
||||
"""
|
||||
posFx = 0 if xFace == 'fXm' else 1
|
||||
IND = ii + posFx
|
||||
PX = sp.csr_matrix((np.ones(M.nC), (range(M.nC), IND)), shape=(M.nC, M.nF))
|
||||
PX = sp.csr_matrix((np.ones(M.nC), (list(range(M.nC)), IND)), shape=(M.nC, M.nF))
|
||||
return PX
|
||||
|
||||
return Px
|
||||
@@ -350,7 +358,7 @@ class InnerProducts(object):
|
||||
|
||||
IND = np.r_[ind1, ind2].flatten()
|
||||
|
||||
PXX = sp.csr_matrix((np.ones(2*M.nC), (range(2*M.nC), IND)), shape=(2*M.nC, M.nF))
|
||||
PXX = sp.csr_matrix((np.ones(2*M.nC), (list(range(2*M.nC)), IND)), shape=(2*M.nC, M.nF))
|
||||
|
||||
if M._meshType == 'Curv':
|
||||
I2x2 = inv2X2BlockDiagonal(getSubArray(fN1[0], [i + posFx, j]), getSubArray(fN1[1], [i + posFx, j]),
|
||||
@@ -407,7 +415,7 @@ class InnerProducts(object):
|
||||
|
||||
IND = np.r_[ind1, ind2, ind3].flatten()
|
||||
|
||||
PXXX = sp.coo_matrix((np.ones(3*M.nC), (range(3*M.nC), IND)), shape=(3*M.nC, M.nF)).tocsr()
|
||||
PXXX = sp.coo_matrix((np.ones(3*M.nC), (list(range(3*M.nC)), IND)), shape=(3*M.nC, M.nF)).tocsr()
|
||||
|
||||
if M._meshType == 'Curv':
|
||||
I3x3 = inv3X3BlockDiagonal(getSubArray(fN1[0], [i + posX, j, k]), getSubArray(fN1[1], [i + posX, j, k]), getSubArray(fN1[2], [i + posX, j, k]),
|
||||
@@ -449,7 +457,7 @@ class InnerProducts(object):
|
||||
|
||||
IND = np.r_[ind1, ind2].flatten()
|
||||
|
||||
PXX = sp.coo_matrix((np.ones(2*M.nC), (range(2*M.nC), IND)), shape=(2*M.nC, M.nE)).tocsr()
|
||||
PXX = sp.coo_matrix((np.ones(2*M.nC), (list(range(2*M.nC)), IND)), shape=(2*M.nC, M.nE)).tocsr()
|
||||
|
||||
if M._meshType == 'Curv':
|
||||
I2x2 = inv2X2BlockDiagonal(getSubArray(eT1[0], [i, j + posX]), getSubArray(eT1[1], [i, j + posX]),
|
||||
@@ -492,7 +500,7 @@ class InnerProducts(object):
|
||||
|
||||
IND = np.r_[ind1, ind2, ind3].flatten()
|
||||
|
||||
PXXX = sp.coo_matrix((np.ones(3*M.nC), (range(3*M.nC), IND)), shape=(3*M.nC, M.nE)).tocsr()
|
||||
PXXX = sp.coo_matrix((np.ones(3*M.nC), (list(range(3*M.nC)), IND)), shape=(3*M.nC, M.nE)).tocsr()
|
||||
|
||||
if M._meshType == 'Curv':
|
||||
I3x3 = inv3X3BlockDiagonal(getSubArray(eT1[0], [i, j + posX[0], k + posX[1]]), getSubArray(eT1[1], [i, j + posX[0], k + posX[1]]), getSubArray(eT1[2], [i, j + posX[0], k + posX[1]]),
|
||||
|
||||
+17
-5
@@ -1,3 +1,15 @@
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from __future__ import absolute_import
|
||||
from builtins import open
|
||||
from builtins import int
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
from builtins import str
|
||||
from builtins import zip
|
||||
from builtins import map
|
||||
from builtins import object
|
||||
import numpy as np, os
|
||||
from SimPEG import Utils
|
||||
|
||||
@@ -128,13 +140,13 @@ class TensorMeshIO(object):
|
||||
|
||||
# Assign the model('s) to the object
|
||||
if models is not None:
|
||||
for item in models.iteritems():
|
||||
for item in models.items():
|
||||
# Convert numpy array
|
||||
vtkDoubleArr = numpy_to_vtk(item[1],deep=1)
|
||||
vtkDoubleArr.SetName(item[0])
|
||||
vtkObj.GetCellData().AddArray(vtkDoubleArr)
|
||||
# Set the active scalar
|
||||
vtkObj.GetCellData().SetActiveScalars(models.keys()[0])
|
||||
vtkObj.GetCellData().SetActiveScalars(list(models.keys())[0])
|
||||
# vtkObj.Update()
|
||||
|
||||
# Check the extension of the fileName
|
||||
@@ -162,7 +174,7 @@ class TensorMeshIO(object):
|
||||
:return: model with TensorMesh ordered
|
||||
"""
|
||||
f = open(fileName, 'r')
|
||||
model = np.array(map(float, f.readlines()))
|
||||
model = np.array(list(map(float, f.readlines())))
|
||||
f.close()
|
||||
model = np.reshape(model, (mesh.nCz, mesh.nCx, mesh.nCy), order = 'F')
|
||||
model = model[::-1,:,:]
|
||||
@@ -265,7 +277,7 @@ class TreeMeshIO(object):
|
||||
# Assign the model('s) to the object
|
||||
if models is not None:
|
||||
# indUBCvector = np.argsort(cX0[np.argsort(np.concatenate((cX0[:,0:2],cX0[:,2:3].max() - cX0[:,2:3]),axis=1).view(','.join(3*['float'])),axis=0,order=('f2','f1','f0'))[:,0]].view(','.join(3*['float'])),axis=0,order=('f2','f1','f0'))[:,0]
|
||||
for item in models.iteritems():
|
||||
for item in models.items():
|
||||
# Save the data
|
||||
np.savetxt(item[0],item[1][ubcReorder],fmt='%3.5e')
|
||||
|
||||
@@ -384,7 +396,7 @@ class TreeMeshIO(object):
|
||||
vtuObj.GetCellData().AddArray(refineLevelArr)
|
||||
# Assign the model('s) to the object
|
||||
if models is not None:
|
||||
for item in models.iteritems():
|
||||
for item in models.items():
|
||||
# Convert numpy array
|
||||
vtkDoubleArr = numpy_to_vtk(item[1],deep=1)
|
||||
vtkDoubleArr.SetName(item[0])
|
||||
|
||||
+25
-18
@@ -1,13 +1,22 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import unicode_literals
|
||||
from builtins import int
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
from builtins import str
|
||||
from builtins import range
|
||||
from past.utils import old_div
|
||||
from SimPEG import Utils, np, sp
|
||||
from BaseMesh import BaseMesh, BaseRectangularMesh
|
||||
from View import TensorView
|
||||
from DiffOperators import DiffOperators
|
||||
from InnerProducts import InnerProducts
|
||||
from MeshIO import TensorMeshIO
|
||||
from .BaseMesh import BaseMesh, BaseRectangularMesh
|
||||
from .View import TensorView
|
||||
from .DiffOperators import DiffOperators
|
||||
from .InnerProducts import InnerProducts
|
||||
from .MeshIO import TensorMeshIO
|
||||
from future.utils import with_metaclass
|
||||
|
||||
class BaseTensorMesh(BaseMesh):
|
||||
|
||||
__metaclass__ = Utils.SimPEGMetaClass
|
||||
class BaseTensorMesh(with_metaclass(Utils.SimPEGMetaClass, BaseMesh)):
|
||||
|
||||
_meshType = 'BASETENSOR'
|
||||
|
||||
@@ -16,7 +25,7 @@ class BaseTensorMesh(BaseMesh):
|
||||
def __init__(self, h_in, x0_in=None):
|
||||
assert type(h_in) in [list, tuple], 'h_in must be a list'
|
||||
assert len(h_in) in [1,2,3], 'h_in must be of dimension 1, 2, or 3'
|
||||
h = range(len(h_in))
|
||||
h = list(range(len(h_in)))
|
||||
for i, h_i in enumerate(h_in):
|
||||
if Utils.isScalar(h_i) and type(h_i) is not np.ndarray:
|
||||
# This gives you something over the unit cube.
|
||||
@@ -298,7 +307,7 @@ class BaseTensorMesh(BaseMesh):
|
||||
prop = np.ones(self.nC)
|
||||
|
||||
if invProp:
|
||||
prop = 1./prop
|
||||
prop = old_div(1.,prop)
|
||||
|
||||
if Utils.isScalar(prop):
|
||||
prop = prop*np.ones(self.nC)
|
||||
@@ -339,11 +348,11 @@ class BaseTensorMesh(BaseMesh):
|
||||
if tensorType == 0:
|
||||
Av = getattr(self, 'ave'+projType+'2CC')
|
||||
V = Utils.sdiag(self.vol)
|
||||
ones = sp.csr_matrix((np.ones(self.nC), (range(self.nC), np.zeros(self.nC))), shape=(self.nC,1))
|
||||
ones = sp.csr_matrix((np.ones(self.nC), (list(range(self.nC)), np.zeros(self.nC))), shape=(self.nC,1))
|
||||
if not invMat and not invProp:
|
||||
dMdprop = self.dim * Av.T * V * ones
|
||||
elif invMat and invProp:
|
||||
dMdprop = self.dim * Utils.sdiag(MI.diagonal()**2) * Av.T * V * ones * Utils.sdiag(1./prop**2)
|
||||
dMdprop = self.dim * Utils.sdiag(MI.diagonal()**2) * Av.T * V * ones * Utils.sdiag(old_div(1.,prop**2))
|
||||
|
||||
if tensorType == 1:
|
||||
Av = getattr(self, 'ave'+projType+'2CC')
|
||||
@@ -351,7 +360,7 @@ class BaseTensorMesh(BaseMesh):
|
||||
if not invMat and not invProp:
|
||||
dMdprop = self.dim * Av.T * V
|
||||
elif invMat and invProp:
|
||||
dMdprop = self.dim * Utils.sdiag(MI.diagonal()**2) * Av.T * V * Utils.sdiag(1./prop**2)
|
||||
dMdprop = self.dim * Utils.sdiag(MI.diagonal()**2) * Av.T * V * Utils.sdiag(old_div(1.,prop**2))
|
||||
|
||||
if tensorType == 2: # anisotropic
|
||||
Av = getattr(self, 'ave'+projType+'2CCV')
|
||||
@@ -359,12 +368,12 @@ class BaseTensorMesh(BaseMesh):
|
||||
if not invMat and not invProp:
|
||||
dMdprop = Av.T * V
|
||||
elif invMat and invProp:
|
||||
dMdprop = Utils.sdiag(MI.diagonal()**2) * Av.T * V * Utils.sdiag(1./prop**2)
|
||||
dMdprop = Utils.sdiag(MI.diagonal()**2) * Av.T * V * Utils.sdiag(old_div(1.,prop**2))
|
||||
|
||||
if dMdprop is not None:
|
||||
def innerProductDeriv(v=None):
|
||||
if v is None:
|
||||
print 'Depreciation Warning: TensorMesh.innerProductDeriv. You should be supplying a vector. Use: sdiag(u)*dMdprop'
|
||||
print('Depreciation Warning: TensorMesh.innerProductDeriv. You should be supplying a vector. Use: sdiag(u)*dMdprop')
|
||||
return dMdprop
|
||||
return Utils.sdiag(v) * dMdprop
|
||||
return innerProductDeriv
|
||||
@@ -373,7 +382,7 @@ class BaseTensorMesh(BaseMesh):
|
||||
|
||||
|
||||
|
||||
class TensorMesh(BaseTensorMesh, BaseRectangularMesh, TensorView, DiffOperators, InnerProducts, TensorMeshIO):
|
||||
class TensorMesh(with_metaclass(Utils.SimPEGMetaClass, type('NewBase', (BaseTensorMesh, BaseRectangularMesh, TensorView, DiffOperators, InnerProducts, TensorMeshIO), {}))):
|
||||
"""
|
||||
TensorMesh is a mesh class that deals with tensor product meshes.
|
||||
|
||||
@@ -403,8 +412,6 @@ class TensorMesh(BaseTensorMesh, BaseRectangularMesh, TensorView, DiffOperators,
|
||||
|
||||
"""
|
||||
|
||||
__metaclass__ = Utils.SimPEGMetaClass
|
||||
|
||||
_meshType = 'TENSOR'
|
||||
|
||||
def __init__(self, h_in, x0=None):
|
||||
|
||||
+87
-74
@@ -1,3 +1,16 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import unicode_literals
|
||||
from builtins import int
|
||||
from builtins import dict
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
from builtins import str
|
||||
from builtins import zip
|
||||
from builtins import range
|
||||
from builtins import object
|
||||
from past.utils import old_div
|
||||
# ___ ___ ___ ___ ___
|
||||
# /\ \ ___ /\__\ /\ \ /\ \ /\ \
|
||||
# /::\ \ /\ \ /::| | /::\ \ /::\ \ /::\ \
|
||||
@@ -92,15 +105,15 @@
|
||||
from SimPEG import np, sp, Utils, Solver
|
||||
|
||||
try:
|
||||
import TreeUtils
|
||||
from . import TreeUtils
|
||||
_IMPORT_TREEUTILS = True
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
_IMPORT_TREEUTILS = False
|
||||
|
||||
|
||||
from InnerProducts import InnerProducts
|
||||
from TensorMesh import TensorMesh, BaseTensorMesh
|
||||
from MeshIO import TreeMeshIO
|
||||
from .InnerProducts import InnerProducts
|
||||
from .TensorMesh import TensorMesh, BaseTensorMesh
|
||||
from .MeshIO import TreeMeshIO
|
||||
import time
|
||||
|
||||
MAX_BITS = 20
|
||||
@@ -165,7 +178,7 @@ class TreeMesh(BaseTensorMesh, InnerProducts, TreeMeshIO):
|
||||
@property
|
||||
def fill(self):
|
||||
"""How filled is the mesh compared to a TensorMesh? As a fraction: [0,1]."""
|
||||
return float(self.nC)/((2**self.maxLevel)**self.dim)
|
||||
return old_div(float(self.nC),((2**self.maxLevel)**self.dim))
|
||||
|
||||
@property
|
||||
def maxLevel(self):
|
||||
@@ -408,7 +421,7 @@ class TreeMesh(BaseTensorMesh, InnerProducts, TreeMeshIO):
|
||||
return TreeUtils.index(self.dim, MAX_BITS, self._levelBits, pointer[:-1], pointer[-1])
|
||||
|
||||
def _pointer(self, index):
|
||||
assert type(index) in [int, long]
|
||||
assert type(index) in [int, int]
|
||||
return TreeUtils.point(self.dim, MAX_BITS, self._levelBits, index)
|
||||
|
||||
def __contains__(self, v):
|
||||
@@ -416,13 +429,13 @@ class TreeMesh(BaseTensorMesh, InnerProducts, TreeMeshIO):
|
||||
|
||||
def refine(self, function=None, recursive=True, cells=None, balance=True, verbose=False, _inRecursion=False):
|
||||
|
||||
if type(function) in [int, long]:
|
||||
if type(function) in [int, int]:
|
||||
level = function
|
||||
function = lambda cell: level
|
||||
|
||||
if not _inRecursion:
|
||||
self.__dirty__ = True
|
||||
if verbose: print 'Refining Mesh'
|
||||
if verbose: print('Refining Mesh')
|
||||
|
||||
cells = cells if cells is not None else sorted(self._cells)
|
||||
recurse = []
|
||||
@@ -433,14 +446,14 @@ class TreeMesh(BaseTensorMesh, InnerProducts, TreeMeshIO):
|
||||
result = function(Cell(self, cell, p))
|
||||
if type(result) is bool:
|
||||
do = result
|
||||
elif type(result) in [int,long]:
|
||||
elif type(result) in [int,int]:
|
||||
do = result > p[-1]
|
||||
else:
|
||||
raise Exception('You must tell the program what to refine. Use BOOL or INT (level)')
|
||||
if do:
|
||||
recurse += self._refineCell(cell, p)
|
||||
|
||||
if verbose: print ' ', time.time() - tic
|
||||
if verbose: print(' ', time.time() - tic)
|
||||
|
||||
if recursive and len(recurse) > 0:
|
||||
recurse += self.refine(function=function, recursive=True, cells=recurse, balance=balance, verbose=verbose, _inRecursion=True)
|
||||
@@ -451,13 +464,13 @@ class TreeMesh(BaseTensorMesh, InnerProducts, TreeMeshIO):
|
||||
|
||||
def corsen(self, function=None, recursive=True, cells=None, balance=True, verbose=False, _inRecursion=False):
|
||||
|
||||
if type(function) in [int, long]:
|
||||
if type(function) in [int, int]:
|
||||
level = function
|
||||
function = lambda cell: level
|
||||
|
||||
if not _inRecursion:
|
||||
self.__dirty__ = True
|
||||
if verbose: print 'Corsening Mesh'
|
||||
if verbose: print('Corsening Mesh')
|
||||
|
||||
cells = cells if cells is not None else sorted(self._cells)
|
||||
recurse = []
|
||||
@@ -469,14 +482,14 @@ class TreeMesh(BaseTensorMesh, InnerProducts, TreeMeshIO):
|
||||
result = function(Cell(self, cell, p))
|
||||
if type(result) is bool:
|
||||
do = result
|
||||
elif type(result) in [int,long]:
|
||||
elif type(result) in [int,int]:
|
||||
do = result < p[-1]
|
||||
else:
|
||||
raise Exception('You must tell the program what to corsen. Use BOOL or INT (level)')
|
||||
if do:
|
||||
recurse += self._corsenCell(cell, p)
|
||||
|
||||
if verbose: print ' ', time.time() - tic
|
||||
if verbose: print(' ', time.time() - tic)
|
||||
|
||||
if recursive and len(recurse) > 0:
|
||||
recurse += self.corsen(function=function, recursive=True, cells=recurse, balance=balance, verbose=verbose, _inRecursion=True)
|
||||
@@ -510,7 +523,7 @@ class TreeMesh(BaseTensorMesh, InnerProducts, TreeMeshIO):
|
||||
return [parentInd]
|
||||
|
||||
def _asPointer(self, ind):
|
||||
if type(ind) in [int, long]:
|
||||
if type(ind) in [int, int]:
|
||||
return self._pointer(ind)
|
||||
if type(ind) is list:
|
||||
assert len(ind) == (self.dim + 1), str(ind) +' is not valid pointer'
|
||||
@@ -521,7 +534,7 @@ class TreeMesh(BaseTensorMesh, InnerProducts, TreeMeshIO):
|
||||
raise Exception
|
||||
|
||||
def _asIndex(self, pointer):
|
||||
if type(pointer) in [int, long]:
|
||||
if type(pointer) in [int, int]:
|
||||
return pointer
|
||||
if type(pointer) is list:
|
||||
return self._index(pointer)
|
||||
@@ -577,7 +590,7 @@ class TreeMesh(BaseTensorMesh, InnerProducts, TreeMeshIO):
|
||||
|
||||
def _cellC(self, p):
|
||||
"""Cell center of a single cell (without origin correction), given a pointer."""
|
||||
return (np.array(self._cellH(p))/2.0 + self._cellN(p)).tolist()
|
||||
return (old_div(np.array(self._cellH(p)),2.0) + self._cellN(p)).tolist()
|
||||
|
||||
def _levelWidth(self, level):
|
||||
return 2**(self.levels - level)
|
||||
@@ -623,7 +636,7 @@ class TreeMesh(BaseTensorMesh, InnerProducts, TreeMeshIO):
|
||||
tic = time.time()
|
||||
if not _inRecursion:
|
||||
self.__dirty__ = True
|
||||
if verbose: print 'Balancing Mesh:'
|
||||
if verbose: print('Balancing Mesh:')
|
||||
|
||||
cells = cells if cells is not None else sorted(self._cells)
|
||||
|
||||
@@ -636,7 +649,7 @@ class TreeMesh(BaseTensorMesh, InnerProducts, TreeMeshIO):
|
||||
p = self._asPointer(cell)
|
||||
if p[-1] == self.levels: continue
|
||||
|
||||
cs = range(6)
|
||||
cs = list(range(6))
|
||||
cs[0] = self._getNextCell(cell, direction=0, positive=False)
|
||||
cs[1] = self._getNextCell(cell, direction=0, positive=True)
|
||||
cs[2] = self._getNextCell(cell, direction=1, positive=False)
|
||||
@@ -655,10 +668,10 @@ class TreeMesh(BaseTensorMesh, InnerProducts, TreeMeshIO):
|
||||
|
||||
if do and cell in self:
|
||||
newCells = self._refineCell(cell)
|
||||
recurse.update([_ for _ in cs if type(_) in [int, long]]) # only add the bigger ones!
|
||||
recurse.update([_ for _ in cs if type(_) in [int, int]]) # only add the bigger ones!
|
||||
recurse.update(newCells)
|
||||
|
||||
if verbose: print ' ', len(cells), time.time() - tic
|
||||
if verbose: print(' ', len(cells), time.time() - tic)
|
||||
if recursive and len(recurse) > 0:
|
||||
self.balance(cells=sorted(recurse), _inRecursion=True)
|
||||
|
||||
@@ -865,10 +878,10 @@ class TreeMesh(BaseTensorMesh, InnerProducts, TreeMeshIO):
|
||||
p = self._pointer(fx)
|
||||
n, h = self._cellN(p), self._cellH(p)
|
||||
if self.dim == 2:
|
||||
gridFx.append( [n[0], n[1] + h[1]/2.0] )
|
||||
gridFx.append( [n[0], n[1] + old_div(h[1],2.0)] )
|
||||
areaFx.append( h[1] )
|
||||
elif self.dim == 3:
|
||||
gridFx.append( [n[0], n[1] + h[1]/2.0, n[2] + h[2]/2.0] )
|
||||
gridFx.append( [n[0], n[1] + old_div(h[1],2.0), n[2] + old_div(h[2],2.0)] )
|
||||
areaFx.append( h[1]*h[2] )
|
||||
self._gridFx = np.array(gridFx)
|
||||
self._areaFxFull = np.array(areaFx)
|
||||
@@ -881,10 +894,10 @@ class TreeMesh(BaseTensorMesh, InnerProducts, TreeMeshIO):
|
||||
p = self._pointer(fy)
|
||||
n, h = self._cellN(p), self._cellH(p)
|
||||
if self.dim == 2:
|
||||
gridFy.append( [n[0] + h[0]/2.0, n[1]] )
|
||||
gridFy.append( [n[0] + old_div(h[0],2.0), n[1]] )
|
||||
areaFy.append( h[0] )
|
||||
elif self.dim == 3:
|
||||
gridFy.append( [n[0] + h[0]/2.0, n[1], n[2] + h[2]/2.0] )
|
||||
gridFy.append( [n[0] + old_div(h[0],2.0), n[1], n[2] + old_div(h[2],2.0)] )
|
||||
areaFy.append( h[0]*h[2] )
|
||||
self._gridFy = np.array(gridFy)
|
||||
self._areaFyFull = np.array(areaFy)
|
||||
@@ -900,7 +913,7 @@ class TreeMesh(BaseTensorMesh, InnerProducts, TreeMeshIO):
|
||||
self._fz2i[fz] = ii
|
||||
p = self._pointer(fz)
|
||||
n, h = self._cellN(p), self._cellH(p)
|
||||
gridFz.append( [n[0] + h[0]/2.0, n[1] + h[1]/2.0, n[2]] )
|
||||
gridFz.append( [n[0] + old_div(h[0],2.0), n[1] + old_div(h[1],2.0), n[2]] )
|
||||
areaFz.append(h[0]*h[1])
|
||||
self._gridFz = np.array(gridFz)
|
||||
self._areaFzFull = np.array(areaFz)
|
||||
@@ -921,7 +934,7 @@ class TreeMesh(BaseTensorMesh, InnerProducts, TreeMeshIO):
|
||||
self._ex2i[ex] = ii
|
||||
p = self._pointer(ex)
|
||||
n, h = self._cellN(p), self._cellH(p)
|
||||
gridEx.append( [n[0] + h[0]/2.0, n[1], n[2]] )
|
||||
gridEx.append( [n[0] + old_div(h[0],2.0), n[1], n[2]] )
|
||||
edgeEx.append( h[0] )
|
||||
self._gridEx = np.array(gridEx)
|
||||
self._edgeExFull = np.array(edgeEx)
|
||||
@@ -933,7 +946,7 @@ class TreeMesh(BaseTensorMesh, InnerProducts, TreeMeshIO):
|
||||
self._ey2i[ey] = ii
|
||||
p = self._pointer(ey)
|
||||
n, h = self._cellN(p), self._cellH(p)
|
||||
gridEy.append( [n[0], n[1] + h[1]/2.0, n[2]] )
|
||||
gridEy.append( [n[0], n[1] + old_div(h[1],2.0), n[2]] )
|
||||
edgeEy.append( h[1] )
|
||||
self._gridEy = np.array(gridEy)
|
||||
self._edgeEyFull = np.array(edgeEy)
|
||||
@@ -945,7 +958,7 @@ class TreeMesh(BaseTensorMesh, InnerProducts, TreeMeshIO):
|
||||
self._ez2i[ez] = ii
|
||||
p = self._pointer(ez)
|
||||
n, h = self._cellN(p), self._cellH(p)
|
||||
gridEz.append( [n[0], n[1], n[2] + h[2]/2.0] )
|
||||
gridEz.append( [n[0], n[1], n[2] + old_div(h[2],2.0)] )
|
||||
edgeEz.append( h[2] )
|
||||
self._gridEz = np.array(gridEz)
|
||||
self._edgeEzFull = np.array(edgeEz)
|
||||
@@ -985,12 +998,12 @@ class TreeMesh(BaseTensorMesh, InnerProducts, TreeMeshIO):
|
||||
chy1 = self._cellH([p[0] , p[1] + w, sl])[1]
|
||||
A = (chy0 + chy1)
|
||||
|
||||
self._hangingFx[self._fx2i[test ]] = ([self._fx2i[fx], chy0 / A], )
|
||||
self._hangingFx[self._fx2i[self._index([p[0] , p[1] + w, sl])]] = ([self._fx2i[fx], chy1 / A], )
|
||||
self._hangingFx[self._fx2i[test ]] = ([self._fx2i[fx], old_div(chy0, A)], )
|
||||
self._hangingFx[self._fx2i[self._index([p[0] , p[1] + w, sl])]] = ([self._fx2i[fx], old_div(chy1, A)], )
|
||||
|
||||
n0, n1 = fx, self._index([p[0], p[1] + 2*w, p[-1]])
|
||||
self._hangingN[self._n2i[test ]] = ([self._n2i[n0], 1.0], )
|
||||
self._hangingN[self._n2i[self._index([p[0] , p[1] + w, sl])]] = ([self._n2i[n0], 1.0 - chy0 / A], [self._n2i[n1], 1.0 - chy1 / A])
|
||||
self._hangingN[self._n2i[self._index([p[0] , p[1] + w, sl])]] = ([self._n2i[n0], 1.0 - old_div(chy0, A)], [self._n2i[n1], 1.0 - old_div(chy1, A)])
|
||||
self._hangingN[self._n2i[self._index([p[0] , p[1] + 2*w, sl])]] = ([self._n2i[n1], 1.0], )
|
||||
|
||||
elif self.dim == 3:
|
||||
@@ -1081,8 +1094,8 @@ class TreeMesh(BaseTensorMesh, InnerProducts, TreeMeshIO):
|
||||
chx0 = self._cellH([p[0] , p[1] , sl])[0]
|
||||
chx1 = self._cellH([p[0] + w, p[1] , sl])[0]
|
||||
|
||||
self._hangingFy[self._fy2i[test ]] = ([self._fy2i[fy], chx0 / (chx0 + chx1)], )
|
||||
self._hangingFy[self._fy2i[self._index([p[0] + w, p[1] , sl])]] = ([self._fy2i[fy], chx1 / (chx0 + chx1)], )
|
||||
self._hangingFy[self._fy2i[test ]] = ([self._fy2i[fy], old_div(chx0, (chx0 + chx1))], )
|
||||
self._hangingFy[self._fy2i[self._index([p[0] + w, p[1] , sl])]] = ([self._fy2i[fy], old_div(chx1, (chx0 + chx1))], )
|
||||
|
||||
n0, n1 = fy, self._index([p[0] + 2*w, p[1], p[-1]])
|
||||
self._hangingN[self._n2i[test ]] = ([self._n2i[n0], 1.0], )
|
||||
@@ -1287,7 +1300,7 @@ class TreeMesh(BaseTensorMesh, InnerProducts, TreeMeshIO):
|
||||
V += [1.0]
|
||||
ii += 1
|
||||
if withHanging:
|
||||
for hfkey in theHang.keys():
|
||||
for hfkey in list(theHang.keys()):
|
||||
hf = theHang[hfkey]
|
||||
I += [hfkey]*len(hf)
|
||||
J += [reducedInd[_[0]] for _ in hf]
|
||||
@@ -1343,7 +1356,7 @@ class TreeMesh(BaseTensorMesh, InnerProducts, TreeMeshIO):
|
||||
S = np.r_[self._areaFxFull, self._areaFyFull]
|
||||
elif self.dim == 3:
|
||||
S = np.r_[self._areaFxFull, self._areaFyFull, self._areaFzFull]
|
||||
self._faceDiv = Utils.sdiag(1.0/VOL)*D*Utils.sdiag(S)*R
|
||||
self._faceDiv = Utils.sdiag(old_div(1.0,VOL))*D*Utils.sdiag(S)*R
|
||||
return self._faceDiv
|
||||
|
||||
@property
|
||||
@@ -1418,12 +1431,12 @@ class TreeMesh(BaseTensorMesh, InnerProducts, TreeMeshIO):
|
||||
Rf = self._deflationMatrix('F', withHanging=True, asOnes=False)
|
||||
Re = self._deflationMatrix('E')
|
||||
|
||||
Rf_ave = Utils.sdiag(1./Rf.sum(axis=0)) * Rf.T
|
||||
Rf_ave = Utils.sdiag(old_div(1.,Rf.sum(axis=0))) * Rf.T
|
||||
|
||||
C = sp.csr_matrix((V,(I,J)), shape=(self.ntF, self.ntE))
|
||||
S = np.r_[self._areaFxFull, self._areaFyFull, self._areaFzFull]
|
||||
L = np.r_[self._edgeExFull, self._edgeEyFull, self._edgeEzFull]
|
||||
self._edgeCurl = Rf_ave*Utils.sdiag(1.0/S)*C*Utils.sdiag(L)*Re
|
||||
self._edgeCurl = Rf_ave*Utils.sdiag(old_div(1.0,S))*C*Utils.sdiag(L)*Re
|
||||
return self._edgeCurl
|
||||
|
||||
@property
|
||||
@@ -1482,9 +1495,9 @@ class TreeMesh(BaseTensorMesh, InnerProducts, TreeMeshIO):
|
||||
Rn = self._deflationMatrix('N')
|
||||
Re = self._deflationMatrix('E', withHanging=True, asOnes=False)
|
||||
|
||||
Re_ave = Utils.sdiag(1./Re.sum(axis=0)) * Re.T
|
||||
Re_ave = Utils.sdiag(old_div(1.,Re.sum(axis=0))) * Re.T
|
||||
|
||||
self._nodalGrad = Re_ave*Utils.sdiag(1/L)*G*Rn
|
||||
self._nodalGrad = Re_ave*Utils.sdiag(old_div(1,L))*G*Rn
|
||||
return self._nodalGrad
|
||||
|
||||
@property
|
||||
@@ -1496,7 +1509,7 @@ class TreeMesh(BaseTensorMesh, InnerProducts, TreeMeshIO):
|
||||
raise Exception('aveEx2CC not implemented in 2D')
|
||||
|
||||
if self.dim == 3:
|
||||
PM = [1./4.]*4
|
||||
PM = [old_div(1.,4.)]*4
|
||||
|
||||
for ii, ind in enumerate(self._sortedCells):
|
||||
p = self._pointer(ind)
|
||||
@@ -1530,7 +1543,7 @@ class TreeMesh(BaseTensorMesh, InnerProducts, TreeMeshIO):
|
||||
raise NotImplementedError('aveEy2CC not implemented in 2D')
|
||||
|
||||
if self.dim == 3:
|
||||
PM = [1./4.]*4 # plus / plus
|
||||
PM = [old_div(1.,4.)]*4 # plus / plus
|
||||
|
||||
for ii, ind in enumerate(self._sortedCells):
|
||||
p = self._pointer(ind)
|
||||
@@ -1565,7 +1578,7 @@ class TreeMesh(BaseTensorMesh, InnerProducts, TreeMeshIO):
|
||||
raise Exception('There are no z edges in 2D')
|
||||
|
||||
if self.dim == 3:
|
||||
PM = [1./4.]*4 # plus / plus
|
||||
PM = [old_div(1.,4.)]*4 # plus / plus
|
||||
|
||||
for ii, ind in enumerate(self._sortedCells):
|
||||
p = self._pointer(ind)
|
||||
@@ -1616,7 +1629,7 @@ class TreeMesh(BaseTensorMesh, InnerProducts, TreeMeshIO):
|
||||
def aveFx2CC(self):
|
||||
if getattr(self, '_aveFx2CC', None) is None:
|
||||
I, J, V = [], [], []
|
||||
PM = [1./2.]*self.dim # 0.5, 0.5
|
||||
PM = [old_div(1.,2.)]*self.dim # 0.5, 0.5
|
||||
|
||||
for ii, ind in enumerate(self._sortedCells):
|
||||
p = self._pointer(ind)
|
||||
@@ -1649,7 +1662,7 @@ class TreeMesh(BaseTensorMesh, InnerProducts, TreeMeshIO):
|
||||
def aveFy2CC(self):
|
||||
if getattr(self, '_aveFy2CC', None) is None:
|
||||
I, J, V = [], [], []
|
||||
PM = [1./2.]*2 # 0.5, 0.5
|
||||
PM = [old_div(1.,2.)]*2 # 0.5, 0.5
|
||||
|
||||
for ii, ind in enumerate(self._sortedCells):
|
||||
p = self._pointer(ind)
|
||||
@@ -1681,7 +1694,7 @@ class TreeMesh(BaseTensorMesh, InnerProducts, TreeMeshIO):
|
||||
def aveFz2CC(self):
|
||||
if getattr(self, '_aveFz2CC', None) is None:
|
||||
I, J, V = [], [], []
|
||||
PM = [1./2.]*2 # 0.5, 0.5
|
||||
PM = [old_div(1.,2.)]*2 # 0.5, 0.5
|
||||
|
||||
for ii, ind in enumerate(self._sortedCells):
|
||||
p = self._pointer(ind)
|
||||
@@ -1729,7 +1742,7 @@ class TreeMesh(BaseTensorMesh, InnerProducts, TreeMeshIO):
|
||||
def aveN2CC(self):
|
||||
if getattr(self, '_aveN2CC', None) is None:
|
||||
I, J, V = [], [], []
|
||||
PM = [1./2.**self.dim] * 2**self.dim
|
||||
PM = [old_div(1.,2.**self.dim)] * 2**self.dim
|
||||
|
||||
for ii, ind in enumerate(self._sortedCells):
|
||||
p = self._pointer(ind)
|
||||
@@ -1788,7 +1801,7 @@ class TreeMesh(BaseTensorMesh, InnerProducts, TreeMeshIO):
|
||||
if self.dim == 3:
|
||||
IND = np.r_[ind1, ind2, ind3]
|
||||
|
||||
PXXX = sp.coo_matrix((np.ones(self.dim*self.nC), (range(self.dim*self.nC), IND)), shape=(self.dim*self.nC, self.ntF)).tocsr()
|
||||
PXXX = sp.coo_matrix((np.ones(self.dim*self.nC), (list(range(self.dim*self.nC)), IND)), shape=(self.dim*self.nC, self.ntF)).tocsr()
|
||||
|
||||
Rf = self._deflationMatrix('F', withHanging=True, asOnes=True)
|
||||
|
||||
@@ -1824,7 +1837,7 @@ class TreeMesh(BaseTensorMesh, InnerProducts, TreeMeshIO):
|
||||
|
||||
IND = np.r_[ind1, ind2, ind3]
|
||||
|
||||
PXXX = sp.coo_matrix((np.ones(self.dim*self.nC), (range(self.dim*self.nC), IND)), shape=(self.dim*self.nC, self.ntE)).tocsr()
|
||||
PXXX = sp.coo_matrix((np.ones(self.dim*self.nC), (list(range(self.dim*self.nC)), IND)), shape=(self.dim*self.nC, self.ntE)).tocsr()
|
||||
|
||||
Re = self._deflationMatrix('E')
|
||||
|
||||
@@ -1847,7 +1860,7 @@ class TreeMesh(BaseTensorMesh, InnerProducts, TreeMeshIO):
|
||||
Ny = self.vectorNy
|
||||
Nz = self.vectorNz
|
||||
|
||||
pointers = range(self.dim)
|
||||
pointers = list(range(self.dim))
|
||||
Nx = np.r_[Nx[0] - TOL, Nx[1:-1], Nx[-1] + TOL]
|
||||
pointers[0] = np.searchsorted(Nx, locs[:,0])
|
||||
Ny = np.r_[Ny[0] - TOL, Ny[1:-1], Ny[-1] + TOL]
|
||||
@@ -2022,13 +2035,13 @@ class TreeMesh(BaseTensorMesh, InnerProducts, TreeMeshIO):
|
||||
ax.plot(self.gridCC[[0,-1],0], self.gridCC[[0,-1],1], 'ro')
|
||||
if nodes:
|
||||
ax.plot(self._gridN[:,0], self._gridN[:,1], 'ms')
|
||||
ax.plot(self._gridN[self._hangingN.keys(),0], self._gridN[self._hangingN.keys(),1], 'ms', ms=10, mfc='none', mec='m')
|
||||
ax.plot(self._gridN[list(self._hangingN.keys()),0], self._gridN[list(self._hangingN.keys()),1], 'ms', ms=10, mfc='none', mec='m')
|
||||
if facesX:
|
||||
ax.plot(self._gridFx[:,0], self._gridFx[:,1], 'g>')
|
||||
ax.plot(self._gridFx[self._hangingFx.keys(),0], self._gridFx[self._hangingFx.keys(),1], 'gs', ms=10, mfc='none', mec='g')
|
||||
ax.plot(self._gridFx[list(self._hangingFx.keys()),0], self._gridFx[list(self._hangingFx.keys()),1], 'gs', ms=10, mfc='none', mec='g')
|
||||
if facesY:
|
||||
ax.plot(self._gridFy[:,0], self._gridFy[:,1], 'g^')
|
||||
ax.plot(self._gridFy[self._hangingFy.keys(),0], self._gridFy[self._hangingFy.keys(),1], 'gs', ms=10, mfc='none', mec='g')
|
||||
ax.plot(self._gridFy[list(self._hangingFy.keys()),0], self._gridFy[list(self._hangingFy.keys()),1], 'gs', ms=10, mfc='none', mec='g')
|
||||
ax.set_xlabel('x1')
|
||||
ax.set_ylabel('x2')
|
||||
elif self.dim == 3:
|
||||
@@ -2040,56 +2053,56 @@ class TreeMesh(BaseTensorMesh, InnerProducts, TreeMeshIO):
|
||||
|
||||
if nodes:
|
||||
ax.plot(self._gridN[:,0], self._gridN[:,1], 'ms', zs=self._gridN[:,2])
|
||||
ax.plot(self._gridN[self._hangingN.keys(),0], self._gridN[self._hangingN.keys(),1], 'ms', ms=10, mfc='none', mec='m', zs=self._gridN[self._hangingN.keys(),2])
|
||||
for key in self._hangingN.keys():
|
||||
ax.plot(self._gridN[list(self._hangingN.keys()),0], self._gridN[list(self._hangingN.keys()),1], 'ms', ms=10, mfc='none', mec='m', zs=self._gridN[list(self._hangingN.keys()),2])
|
||||
for key in list(self._hangingN.keys()):
|
||||
for hf in self._hangingN[key]:
|
||||
ind = [key, hf[0]]
|
||||
ax.plot(self._gridN[ind,0], self._gridN[ind,1], 'm:', zs=self._gridN[ind,2])
|
||||
|
||||
if facesX:
|
||||
ax.plot(self._gridFx[:,0], self._gridFx[:,1], 'g>', zs=self._gridFx[:,2])
|
||||
ax.plot(self._gridFx[self._hangingFx.keys(),0], self._gridFx[self._hangingFx.keys(),1], 'gs', ms=10, mfc='none', mec='g', zs=self._gridFx[self._hangingFx.keys(),2])
|
||||
for key in self._hangingFx.keys():
|
||||
ax.plot(self._gridFx[list(self._hangingFx.keys()),0], self._gridFx[list(self._hangingFx.keys()),1], 'gs', ms=10, mfc='none', mec='g', zs=self._gridFx[list(self._hangingFx.keys()),2])
|
||||
for key in list(self._hangingFx.keys()):
|
||||
for hf in self._hangingFx[key]:
|
||||
ind = [key, hf[0]]
|
||||
ax.plot(self._gridFx[ind,0], self._gridFx[ind,1], 'g:', zs=self._gridFx[ind,2])
|
||||
|
||||
if facesY:
|
||||
ax.plot(self._gridFy[:,0], self._gridFy[:,1], 'g^', zs=self._gridFy[:,2])
|
||||
ax.plot(self._gridFy[self._hangingFy.keys(),0], self._gridFy[self._hangingFy.keys(),1], 'gs', ms=10, mfc='none', mec='g', zs=self._gridFy[self._hangingFy.keys(),2])
|
||||
for key in self._hangingFy.keys():
|
||||
ax.plot(self._gridFy[list(self._hangingFy.keys()),0], self._gridFy[list(self._hangingFy.keys()),1], 'gs', ms=10, mfc='none', mec='g', zs=self._gridFy[list(self._hangingFy.keys()),2])
|
||||
for key in list(self._hangingFy.keys()):
|
||||
for hf in self._hangingFy[key]:
|
||||
ind = [key, hf[0]]
|
||||
ax.plot(self._gridFy[ind,0], self._gridFy[ind,1], 'g:', zs=self._gridFy[ind,2])
|
||||
|
||||
if facesZ:
|
||||
ax.plot(self._gridFz[:,0], self._gridFz[:,1], 'g^', zs=self._gridFz[:,2])
|
||||
ax.plot(self._gridFz[self._hangingFz.keys(),0], self._gridFz[self._hangingFz.keys(),1], 'gs', ms=10, mfc='none', mec='g', zs=self._gridFz[self._hangingFz.keys(),2])
|
||||
for key in self._hangingFz.keys():
|
||||
ax.plot(self._gridFz[list(self._hangingFz.keys()),0], self._gridFz[list(self._hangingFz.keys()),1], 'gs', ms=10, mfc='none', mec='g', zs=self._gridFz[list(self._hangingFz.keys()),2])
|
||||
for key in list(self._hangingFz.keys()):
|
||||
for hf in self._hangingFz[key]:
|
||||
ind = [key, hf[0]]
|
||||
ax.plot(self._gridFz[ind,0], self._gridFz[ind,1], 'g:', zs=self._gridFz[ind,2])
|
||||
|
||||
if edgesX:
|
||||
ax.plot(self._gridEx[:,0], self._gridEx[:,1], 'k>', zs=self._gridEx[:,2])
|
||||
ax.plot(self._gridEx[self._hangingEx.keys(),0], self._gridEx[self._hangingEx.keys(),1], 'ks', ms=10, mfc='none', mec='k', zs=self._gridEx[self._hangingEx.keys(),2])
|
||||
for key in self._hangingEx.keys():
|
||||
ax.plot(self._gridEx[list(self._hangingEx.keys()),0], self._gridEx[list(self._hangingEx.keys()),1], 'ks', ms=10, mfc='none', mec='k', zs=self._gridEx[list(self._hangingEx.keys()),2])
|
||||
for key in list(self._hangingEx.keys()):
|
||||
for hf in self._hangingEx[key]:
|
||||
ind = [key, hf[0]]
|
||||
ax.plot(self._gridEx[ind,0], self._gridEx[ind,1], 'k:', zs=self._gridEx[ind,2])
|
||||
|
||||
if edgesY:
|
||||
ax.plot(self._gridEy[:,0], self._gridEy[:,1], 'k<', zs=self._gridEy[:,2])
|
||||
ax.plot(self._gridEy[self._hangingEy.keys(),0], self._gridEy[self._hangingEy.keys(),1], 'ks', ms=10, mfc='none', mec='k', zs=self._gridEy[self._hangingEy.keys(),2])
|
||||
for key in self._hangingEy.keys():
|
||||
ax.plot(self._gridEy[list(self._hangingEy.keys()),0], self._gridEy[list(self._hangingEy.keys()),1], 'ks', ms=10, mfc='none', mec='k', zs=self._gridEy[list(self._hangingEy.keys()),2])
|
||||
for key in list(self._hangingEy.keys()):
|
||||
for hf in self._hangingEy[key]:
|
||||
ind = [key, hf[0]]
|
||||
ax.plot(self._gridEy[ind,0], self._gridEy[ind,1], 'k:', zs=self._gridEy[ind,2])
|
||||
|
||||
if edgesZ:
|
||||
ax.plot(self._gridEz[:,0], self._gridEz[:,1], 'k^', zs=self._gridEz[:,2])
|
||||
ax.plot(self._gridEz[self._hangingEz.keys(),0], self._gridEz[self._hangingEz.keys(),1], 'ks', ms=10, mfc='none', mec='k', zs=self._gridEz[self._hangingEz.keys(),2])
|
||||
for key in self._hangingEz.keys():
|
||||
ax.plot(self._gridEz[list(self._hangingEz.keys()),0], self._gridEz[list(self._hangingEz.keys()),1], 'ks', ms=10, mfc='none', mec='k', zs=self._gridEz[list(self._hangingEz.keys()),2])
|
||||
for key in list(self._hangingEz.keys()):
|
||||
for hf in self._hangingEz[key]:
|
||||
ind = [key, hf[0]]
|
||||
ax.plot(self._gridEz[ind,0], self._gridEz[ind,1], 'k:', zs=self._gridEz[ind,2])
|
||||
@@ -2152,8 +2165,8 @@ class TreeMesh(BaseTensorMesh, InnerProducts, TreeMeshIO):
|
||||
import matplotlib.cm as cmx
|
||||
|
||||
szSliceDim = len(getattr(self, 'h'+normal.lower())) #: Size of the sliced dimension
|
||||
if ind is None: ind = int(szSliceDim/2)
|
||||
assert type(ind) in [int, long], 'ind must be an integer'
|
||||
if ind is None: ind = int(old_div(szSliceDim,2))
|
||||
assert type(ind) in [int, int], 'ind must be an integer'
|
||||
indLoc = getattr(self,'vectorCC'+normal.lower())[ind]
|
||||
normalInd = {'X':0,'Y':1,'Z':2}[normal]
|
||||
antiNormalInd = {'X':[1,2],'Y':[0,2],'Z':[0,1]}[normal]
|
||||
@@ -2235,19 +2248,19 @@ class TreeMesh(BaseTensorMesh, InnerProducts, TreeMeshIO):
|
||||
def __getitem__(self, key):
|
||||
if isinstance( key, slice ) :
|
||||
#Get the start, stop, and step from the slice
|
||||
return [self[ii] for ii in xrange(*key.indices(len(self)))]
|
||||
return [self[ii] for ii in range(*key.indices(len(self)))]
|
||||
elif isinstance( key, int ) :
|
||||
if key < 0 : #Handle negative indices
|
||||
key += len( self )
|
||||
if key >= len( self ) :
|
||||
raise IndexError, "The index (%d) is out of range."%key
|
||||
raise IndexError("The index (%d) is out of range."%key)
|
||||
|
||||
self._numberCells() # no-op if numbered
|
||||
index = self._i2cc[key]
|
||||
pointer = self._asPointer(index)
|
||||
return Cell(self, index, pointer)
|
||||
else:
|
||||
raise TypeError, "Invalid argument type."
|
||||
raise TypeError("Invalid argument type.")
|
||||
|
||||
|
||||
class Cell(object):
|
||||
@@ -2333,7 +2346,7 @@ def SortGrid(grid, offset=0):
|
||||
def __ne__(self, other):
|
||||
return mycmp(self.obj, other.obj) != 0
|
||||
|
||||
return sorted(range(offset,grid.shape[0]+offset), key=K)
|
||||
return sorted(list(range(offset,grid.shape[0]+offset)), key=K)
|
||||
|
||||
|
||||
class TreeException(Exception):
|
||||
|
||||
+18
-7
@@ -1,11 +1,22 @@
|
||||
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 zip
|
||||
from builtins import range
|
||||
from builtins import object
|
||||
from past.utils import old_div
|
||||
import numpy as np
|
||||
from SimPEG.Utils import mkvc
|
||||
try:
|
||||
import matplotlib.pyplot as plt
|
||||
import matplotlib
|
||||
from mpl_toolkits.mplot3d import Axes3D
|
||||
except ImportError, e:
|
||||
print 'Trouble importing matplotlib.'
|
||||
except ImportError as e:
|
||||
print('Trouble importing matplotlib.')
|
||||
|
||||
|
||||
class TensorView(object):
|
||||
@@ -128,7 +139,7 @@ class TensorView(object):
|
||||
|
||||
# determine number oE slices in x and y dimension
|
||||
nX = np.ceil(np.sqrt(self.nCz))
|
||||
nY = np.ceil(self.nCz/nX)
|
||||
nY = np.ceil(old_div(self.nCz,nX))
|
||||
|
||||
# allocate space for montage
|
||||
nCx = self.nCx
|
||||
@@ -228,8 +239,8 @@ class TensorView(object):
|
||||
assert type(grid) is bool, 'grid must be a boolean'
|
||||
|
||||
szSliceDim = getattr(self, 'nC'+normal.lower()) #: Size of the sliced dimension
|
||||
if ind is None: ind = int(szSliceDim/2)
|
||||
assert type(ind) in [int, long], 'ind must be an integer'
|
||||
if ind is None: ind = int(old_div(szSliceDim,2))
|
||||
assert type(ind) in [int, int], 'ind must be an integer'
|
||||
|
||||
assert not (v.dtype == complex and view == 'vec'), 'Can not plot a complex vector.'
|
||||
# The slicing and plotting code!!
|
||||
@@ -362,8 +373,8 @@ class TensorView(object):
|
||||
# spaced vectors at the moment. So we will
|
||||
# Interpolate down to a regular mesh at the
|
||||
# smallest mesh size in this 2D slice.
|
||||
nxi = int(self.hx.sum()/self.hx.min())
|
||||
nyi = int(self.hy.sum()/self.hy.min())
|
||||
nxi = int(old_div(self.hx.sum(),self.hx.min()))
|
||||
nyi = int(old_div(self.hy.sum(),self.hy.min()))
|
||||
tMi = self.__class__([np.ones(nxi)*self.hx.sum()/nxi,
|
||||
np.ones(nyi)*self.hy.sum()/nyi], self.x0)
|
||||
P = self.getInterpolationMat(tMi.gridCC,'CC',zerosOutside=True)
|
||||
|
||||
+11
-5
@@ -1,5 +1,11 @@
|
||||
from TensorMesh import TensorMesh
|
||||
from CylMesh import CylMesh
|
||||
from CurvilinearMesh import CurvilinearMesh
|
||||
from TreeMesh import TreeMesh
|
||||
from BaseMesh import BaseMesh
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function
|
||||
from __future__ import division
|
||||
from future import standard_library
|
||||
standard_library.install_aliases()
|
||||
from .TensorMesh import TensorMesh
|
||||
from .CylMesh import CylMesh
|
||||
from .CurvilinearMesh import CurvilinearMesh
|
||||
from .TreeMesh import TreeMesh
|
||||
from .BaseMesh import BaseMesh
|
||||
|
||||
Reference in New Issue
Block a user