def test_invPropertyTensor2D(self): M = Mesh.TensorMesh([6, 6]) a1 = np.random.rand(M.nC) a2 = np.random.rand(M.nC) a3 = np.random.rand(M.nC) prop1 = a1 prop2 = np.c_[a1, a2] prop3 = np.c_[a1, a2, a3] for prop in [4, prop1, prop2, prop3]: b = invPropertyTensor(M, prop) A = makePropertyTensor(M, prop) B1 = makePropertyTensor(M, b) B2 = invPropertyTensor(M, prop, returnMatrix=True) Z = B1 * A - sp.identity(M.nC * 2) self.assertTrue(np.linalg.norm(Z.todense().ravel(), 2) < TOL) Z = B2 * A - sp.identity(M.nC * 2) self.assertTrue(np.linalg.norm(Z.todense().ravel(), 2) < TOL)
def test_invPropertyTensor2D(self): M = Mesh.TensorMesh([6, 6]) a1 = np.random.rand(M.nC) a2 = np.random.rand(M.nC) a3 = np.random.rand(M.nC) prop1 = a1 prop2 = np.c_[a1, a2] prop3 = np.c_[a1, a2, a3] for prop in [4, prop1, prop2, prop3]: b = invPropertyTensor(M, prop) A = makePropertyTensor(M, prop) B1 = makePropertyTensor(M, b) B2 = invPropertyTensor(M, prop, returnMatrix=True) Z = B1*A - sp.identity(M.nC*2) self.assertTrue(np.linalg.norm(Z.todense().ravel(), 2) < TOL) Z = B2*A - sp.identity(M.nC*2) self.assertTrue(np.linalg.norm(Z.todense().ravel(), 2) < TOL)
def _getInnerProduct(self, projType, prop=None, invProp=False, invMat=False, doFast=True): """ :param str projType: 'F' for faces 'E' for edges :param numpy.array prop: material property (tensor properties are possible) at each cell center (nC, (1, 3, or 6)) :param bool invProp: inverts the material property :param bool invMat: inverts the matrix :param bool doFast: do a faster implementation if available. :rtype: scipy.sparse.csr_matrix :return: M, the inner product matrix (nE, nE) """ assert projType in [ 'F', 'E' ], "projType must be 'F' for faces or 'E' for edges" fast = None if hasattr(self, '_fastInnerProduct') and doFast: fast = self._fastInnerProduct(projType, prop=prop, invProp=invProp, invMat=invMat) if fast is not None: return fast if invProp: prop = invPropertyTensor(self, prop) tensorType = TensorType(self, prop) Mu = makePropertyTensor(self, prop) Ps = self._getInnerProductProjectionMatrices(projType, tensorType) A = np.sum([P.T * Mu * P for P in Ps]) if invMat and tensorType < 3: A = sdInv(A) elif invMat and tensorType == 3: raise Exception('Solver needed to invert A.') return A