mirror of
https://github.com/wassname/simpeg.git
synced 2026-08-20 12:50:34 +08:00
Merge branch 'develop' of https://github.com/simpeg/simpeg into cylClean
Conflicts: SimPEG/Mesh/TensorMesh.py also lower top on one test.
This commit is contained in:
@@ -2,6 +2,9 @@ import numpy as np
|
||||
import unittest
|
||||
from TestUtils import OrderTest
|
||||
from SimPEG.Utils import mkvc
|
||||
from SimPEG import Mesh
|
||||
import unittest
|
||||
|
||||
|
||||
MESHTYPES = ['uniformTensorMesh', 'randomTensorMesh']
|
||||
TOLERANCES = [0.9, 0.5]
|
||||
@@ -50,6 +53,19 @@ class TestInterpolation1D(OrderTest):
|
||||
self.name = 'Interpolation 1D: N'
|
||||
self.orderTest()
|
||||
|
||||
class TestOutliersInterp1D(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def test_outliers(self):
|
||||
M = Mesh.TensorMesh([4])
|
||||
Q = M.getInterpolationMat(np.array([[0],[0.126],[0.127]]),'CC',zerosOutside=True)
|
||||
x = np.arange(4)+1
|
||||
self.assertTrue(np.all(Q*x == [1,1.004,1.008]))
|
||||
Q = M.getInterpolationMat(np.array([[-1],[0.126],[0.127]]),'CC',zerosOutside=True)
|
||||
self.assertTrue(np.all(Q*x == [0,1.004,1.008]))
|
||||
|
||||
class TestInterpolation2d(OrderTest):
|
||||
name = "Interpolation 2D"
|
||||
LOCS = np.random.rand(50,2)*0.6+0.2
|
||||
|
||||
@@ -11,7 +11,8 @@ class ModelTests(unittest.TestCase):
|
||||
|
||||
a = np.array([1, 1, 1])
|
||||
b = np.array([1, 2])
|
||||
self.mesh2 = Mesh.TensorMesh([a, b], np.array([3, 5]))
|
||||
self.mesh2 = Mesh.TensorMesh([a, b], x0=np.array([3, 5]))
|
||||
self.mesh22 = Mesh.TensorMesh([b, a], x0=np.array([3, 5]))
|
||||
|
||||
def test_modelTransforms(self):
|
||||
for M in dir(Model):
|
||||
@@ -22,6 +23,10 @@ class ModelTests(unittest.TestCase):
|
||||
continue
|
||||
self.assertTrue(model.test())
|
||||
|
||||
def test_Mesh2MeshModel(self):
|
||||
model = Model.Mesh2Mesh([self.mesh22, self.mesh2])
|
||||
self.assertTrue(model.test())
|
||||
|
||||
def test_comboModels(self):
|
||||
combos = [(Model.LogModel, Model.Vertical1DModel)]
|
||||
for combo in combos:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import numpy as np
|
||||
import unittest
|
||||
from SimPEG.Utils import mkvc, ndgrid, indexCube, sdiag, inv3X3BlockDiagonal, inv2X2BlockDiagonal
|
||||
from SimPEG.Utils import mkvc, ndgrid, indexCube, sdiag, inv3X3BlockDiagonal, inv2X2BlockDiagonal,sub2ind,ind2sub
|
||||
from SimPEG.Tests import checkDerivative
|
||||
|
||||
|
||||
@@ -64,6 +64,19 @@ class TestSequenceFunctions(unittest.TestCase):
|
||||
self.assertTrue(np.all(XYZ[:, 1] == X2_test))
|
||||
self.assertTrue(np.all(XYZ[:, 2] == X3_test))
|
||||
|
||||
def test_sub2ind(self):
|
||||
x = np.ones((5,2))
|
||||
self.assertTrue(np.all(sub2ind(x.shape, [0,0]) == [0]))
|
||||
self.assertTrue(np.all(sub2ind(x.shape, [4,0]) == [4]))
|
||||
self.assertTrue(np.all(sub2ind(x.shape, [0,1]) == [5]))
|
||||
self.assertTrue(np.all(sub2ind(x.shape, [4,1]) == [9]))
|
||||
self.assertTrue(np.all(sub2ind(x.shape, [[0,0],[4,0],[0,1],[4,1]]) == [0,4,5,9]))
|
||||
|
||||
def test_ind2sub(self):
|
||||
x = np.ones((5,2))
|
||||
self.assertTrue(np.all(ind2sub(x.shape, [0,4,5,9])[0] == [0,4,0,4]))
|
||||
self.assertTrue(np.all(ind2sub(x.shape, [0,4,5,9])[1] == [0,0,1,1]))
|
||||
|
||||
def test_indexCube_2D(self):
|
||||
nN = np.array([3, 3])
|
||||
self.assertTrue(np.all(indexCube('A', nN) == np.array([0, 1, 3, 4])))
|
||||
@@ -93,7 +106,7 @@ class TestSequenceFunctions(unittest.TestCase):
|
||||
sp.hstack((sdiag(a[2]), sdiag(a[3])))))
|
||||
|
||||
Z2 = B*A - sp.eye(10, 10)
|
||||
self.assertTrue(np.linalg.norm(Z2.todense().ravel(), 2) < 1e-12)
|
||||
self.assertTrue(np.linalg.norm(Z2.todense().ravel(), 2) < 1e-10)
|
||||
|
||||
a = [np.random.rand(5, 1) for i in range(9)]
|
||||
B = inv3X3BlockDiagonal(*a)
|
||||
@@ -104,7 +117,7 @@ class TestSequenceFunctions(unittest.TestCase):
|
||||
|
||||
Z3 = B*A - sp.eye(15, 15)
|
||||
|
||||
self.assertTrue(np.linalg.norm(Z3.todense().ravel(), 2) < 1e-12)
|
||||
self.assertTrue(np.linalg.norm(Z3.todense().ravel(), 2) < 1e-10)
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user