mirror of
https://github.com/wassname/simpeg.git
synced 2026-06-27 19:48:52 +08:00
write test for invProp and invMat (failing)
This commit is contained in:
@@ -109,10 +109,12 @@ class InnerProducts(object):
|
||||
return [V*proj(*locs[node][d-1]) for node in nodes]
|
||||
|
||||
|
||||
def getFaceInnerProductDeriv(self, prop, doFast=True):
|
||||
def getFaceInnerProductDeriv(self, prop, doFast=True, invProp=False, invMat=False):
|
||||
"""
|
||||
:param numpy.array prop: material property (tensor properties are possible) at each cell center (nC, (1, 3, or 6))
|
||||
:param bool doFast: do a faster implementation if available.
|
||||
:param bool invProp: inverts the material property
|
||||
:param bool invMat: inverts the matrix
|
||||
:rtype: function
|
||||
:return: dMdmu(u), the derivative of the inner product matrix (u)
|
||||
|
||||
@@ -122,23 +124,27 @@ class InnerProducts(object):
|
||||
:rtype: scipy.csr_matrix
|
||||
:return: dMdmu, the derivative of the inner product matrix for a certain u
|
||||
"""
|
||||
return self._getInnerProductDeriv(prop, 'F', doFast=doFast)
|
||||
return self._getInnerProductDeriv(prop, 'F', doFast=doFast, invProp=invProp, invMat=invMat)
|
||||
|
||||
|
||||
def getEdgeInnerProductDeriv(self, prop, doFast=True):
|
||||
def getEdgeInnerProductDeriv(self, prop, doFast=True, invProp=False, invMat=False):
|
||||
"""
|
||||
:param numpy.array prop: material property (tensor properties are possible) at each cell center (nC, (1, 3, or 6))
|
||||
:param bool doFast: do a faster implementation if available.
|
||||
:param bool invProp: inverts the material property
|
||||
:param bool invMat: inverts the matrix
|
||||
:rtype: scipy.csr_matrix
|
||||
:return: dMdm, the derivative of the inner product matrix (nE, nC*nA)
|
||||
"""
|
||||
return self._getInnerProductDeriv(prop, 'E', doFast=doFast)
|
||||
return self._getInnerProductDeriv(prop, 'E', doFast=doFast, invProp=invProp, invMat=invMat)
|
||||
|
||||
def _getInnerProductDeriv(self, prop, projType, doFast=True):
|
||||
def _getInnerProductDeriv(self, prop, projType, doFast=True, invProp=False, invMat=False):
|
||||
"""
|
||||
:param numpy.array prop: material property (tensor properties are possible) at each cell center (nC, (1, 3, or 6))
|
||||
:param str projType: 'F' for faces 'E' for edges
|
||||
:param bool doFast: do a faster implementation if available.
|
||||
:param bool invProp: inverts the material property
|
||||
:param bool invMat: inverts the matrix
|
||||
:rtype: scipy.csr_matrix
|
||||
:return: dMdm, the derivative of the inner product matrix (nE, nC*nA)
|
||||
"""
|
||||
@@ -146,7 +152,10 @@ class InnerProducts(object):
|
||||
fast = None
|
||||
|
||||
if hasattr(self, '_fastInnerProductDeriv') and doFast:
|
||||
fast = self._fastInnerProductDeriv(projType, tensorType)
|
||||
fast = self._fastInnerProductDeriv(projType, tensorType, invProp=invProp, invMat=invMat)
|
||||
|
||||
if invProp or invMat:
|
||||
raise NotImplementedError('inverting the property or the matrix is not yet implemented for this mesh/tensorType. You should write it!')
|
||||
|
||||
if fast is not None:
|
||||
return fast
|
||||
|
||||
@@ -6,7 +6,7 @@ from TestUtils import checkDerivative
|
||||
|
||||
class TestInnerProductsDerivs(unittest.TestCase):
|
||||
|
||||
def doTestFace(self, h, rep, fast, meshType):
|
||||
def doTestFace(self, h, rep, fast, meshType, invProp=False, invMat=False):
|
||||
if meshType == 'LRM':
|
||||
hRect = Utils.exampleLrmGrid(h,'rotate')
|
||||
mesh = Mesh.LogicallyRectMesh(hRect)
|
||||
@@ -16,14 +16,14 @@ class TestInnerProductsDerivs(unittest.TestCase):
|
||||
mesh = Mesh.TensorMesh(h)
|
||||
v = np.random.rand(mesh.nF)
|
||||
sig = np.random.rand(1) if rep is 0 else np.random.rand(mesh.nC*rep)
|
||||
Md = mesh.getFaceInnerProductDeriv(sig, doFast=fast)
|
||||
def fun(sig):
|
||||
M = mesh.getFaceInnerProduct(sig)
|
||||
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
|
||||
return checkDerivative(fun, sig, num=5, plotIt=False)
|
||||
|
||||
def doTestEdge(self, h, rep, fast, meshType):
|
||||
def doTestEdge(self, h, rep, fast, meshType, invProp=False, invMat=False):
|
||||
if meshType == 'LRM':
|
||||
hRect = Utils.exampleLrmGrid(h,'rotate')
|
||||
mesh = Mesh.LogicallyRectMesh(hRect)
|
||||
@@ -33,9 +33,9 @@ class TestInnerProductsDerivs(unittest.TestCase):
|
||||
mesh = Mesh.TensorMesh(h)
|
||||
v = np.random.rand(mesh.nE)
|
||||
sig = np.random.rand(1) if rep is 0 else np.random.rand(mesh.nC*rep)
|
||||
Md = mesh.getEdgeInnerProductDeriv(sig, doFast=fast)
|
||||
def fun(sig):
|
||||
M = mesh.getEdgeInnerProduct(sig)
|
||||
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
|
||||
return checkDerivative(fun, sig, num=5, plotIt=False)
|
||||
@@ -118,6 +118,25 @@ class TestInnerProductsDerivs(unittest.TestCase):
|
||||
|
||||
|
||||
|
||||
# def test_FaceIP_1D_float_fast_harmonic(self):
|
||||
# self.assertTrue(self.doTestFace([10],0, True, 'Tensor', invProp=True, invMat=True))
|
||||
# def test_FaceIP_2D_float_fast_harmonic(self):
|
||||
# self.assertTrue(self.doTestFace([10, 4],0, True, 'Tensor', invProp=True, invMat=True))
|
||||
# def test_FaceIP_3D_float_fast_harmonic(self):
|
||||
# self.assertTrue(self.doTestFace([10, 4, 5],0, True, 'Tensor', invProp=True, invMat=True))
|
||||
def test_FaceIP_1D_isotropic_fast_harmonic(self):
|
||||
self.assertTrue(self.doTestFace([10],1, True, 'Tensor', invProp=True, invMat=True))
|
||||
def test_FaceIP_2D_isotropic_fast_harmonic(self):
|
||||
self.assertTrue(self.doTestFace([10, 4],1, True, 'Tensor', invProp=True, invMat=True))
|
||||
def test_FaceIP_3D_isotropic_fast_harmonic(self):
|
||||
self.assertTrue(self.doTestFace([10, 4, 5],1, True, 'Tensor', invProp=True, invMat=True))
|
||||
# def test_FaceIP_2D_anisotropic_fast_harmonic(self):
|
||||
# self.assertTrue(self.doTestFace([10, 4],2, True, 'Tensor', invProp=True, invMat=True))
|
||||
# def test_FaceIP_3D_anisotropic_fast_harmonic(self):
|
||||
# self.assertTrue(self.doTestFace([10, 4, 5],3, True, 'Tensor', invProp=True, invMat=True))
|
||||
|
||||
|
||||
|
||||
def test_FaceIP_2D_float_LRM(self):
|
||||
self.assertTrue(self.doTestFace([10, 4],0, False, 'LRM'))
|
||||
def test_FaceIP_3D_float_LRM(self):
|
||||
|
||||
Reference in New Issue
Block a user